View previous topic :: View next topic
|
Author |
Message |
neelima.sinha
New User
Joined: 14 Sep 2007 Posts: 30 Location: Bangalore
|
|
|
|
Hi,
I have a jo that starts at different time on different days. I want to calculate the average start time.
example:
Date Time
2008-02-25, 23:46
2008-03-04, 00:01
2008-03-10, 23:15
2008-02-25, 23:46
2008-03-17, 23:08
2008-03-10, 23:10
can anybody help me with this.
Regards, |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Convert the time from hour and minutes to minutes, find the average and convert back to hour and minutes. |
|
Back to top |
|
|
neelima.sinha
New User
Joined: 14 Sep 2007 Posts: 30 Location: Bangalore
|
|
|
|
Hi,
If i take
2008-02-25, 23:46
2008-03-04, 00:01
23*60 + 46 = 1426
00*60 + 01 = 01
1426 + 01 = 1427
1427 / 2 = 713.5
713.5/60 = 11.89 ... which is wrong as avg. start time should be 23.54 approx.
Regards,
Neelima |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
You asked for the start time and that' s what You got...
Otherwise You should have asked about the average date_time relative to a
baseline date_time
in this case....
determine the baseline , could be min(dates)
compute the time offset
by adding the seconds_per_day * date_offset + time_in_seconds
compute the average start offset
reverse the computations to get offset in days + hours + minutes + seconds |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
According to my calculations it should be 11:53 as the average start time. I don't know how you came up with 23.54. If you just average the hour for the two start times it would be 11.5. |
|
Back to top |
|
|
neelima.sinha
New User
Joined: 14 Sep 2007 Posts: 30 Location: Bangalore
|
|
|
|
Hi enrico,
Thanks for your reply. could you please explain with my example and show the calculation.
Regards |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
it should be 11:53 as the average start time. I don't know how you came up with 23.54. |
Well, 23:54 is almost the same as 11:53(pm).
Additonal computation is needed to accommodate the "roll" over midnight. Depending on how the start times might be distributed, i'd suggest addng another 24 hours if the start time was less than 06:00 (6am). This could be modified if there are other start-time "rules" to consider. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
it does not make any sense
but for Your sample the average start date_time is 2008-03-06, 07:31
here is a rexx I used for the computations
Code: |
/* Rexx */
dates.0 = 6
dates.1 = "20080225 23:46"
dates.2 = "20080304 00:01"
dates.3 = "20080310 23:15"
dates.4 = "20080225 23:46"
dates.5 = "20080317 23:08"
dates.6 = "20080310 23:10"
/* compute the baseline date ... min(dates) */
dbase = 999999
do i = 1 to dates.0
dcurr = date("B",substr(dates.i,1,8),"s")
if dcurr < dbase then ,
dbase = dcurr
end
/* compute the time offset from the baseline */
wtime = 0
do i = 1 to dates.0
dcurr = date("B",substr(dates.i,1,8),"s") - dbase
tcurr = substr(dates.i,10,2)*60 + substr(dates.i,13,2)
toffs = dcurr * 24 * 60 + tcurr
wtime = wtime + toffs
end
/* the meaningless average */
wavrg = wtime % dates.0
/* tranform back to days and hours */
wdays = wavrg % ( 24 * 60 )
wtime = wavrg // ( 24 * 60 )
/* the date */
adate = date("s",wdays + dbase,"b")
say "adate " adate
/* the time */
atime = wtime % 60 || ":" || wtime // 60
say "atime " atime
exit
|
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
it does not make any sense |
Yup, please change the "dates.2 = "20080304 00:01"" to "dates.2 = "20080304 24:01"" and re-calculate.
I'm away from a mainframe connection just now and cannot run it here. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
Quote: |
it does not make any sense |
My remark was about calculating an average across a date_time timestamp
and the average start time resulting 2008-03-06
but an average is an average unless as I pointed out before some constarints are being defined...
maybe I was a bit sarcastic in my approach, but my mathematical approach was consistent..
the other two ways of getting an average are ( disregarding the date )
1) absolute average
2) baselined average ( take the deltas from a baseline )
the times are modulus 24 so the function modulus is unidirectional
given a value its modulus is unique, not the other way around
still i feel that a baselined average mught be considered cheating
the baseline will be chosen to yield good looking results
number 1 is a subset of number 2 whit a baseline of 00:00 |
|
Back to top |
|
|
neelima.sinha
New User
Joined: 14 Sep 2007 Posts: 30 Location: Bangalore
|
|
|
|
i only want to calculate average of time .... i dont have to do anything with date at all and i am reading this input from file |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
I repeat,
Convert the time from hour and minutes to minutes, find the average and convert back to hour and minutes. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
from Your data
Quote: |
2008-02-25, 23:46
2008-03-04, 00:01
2008-03-10, 23:15
2008-02-25, 23:46
2008-03-17, 23:08
2008-03-10, 23:10 |
((23*60+46) + (00*60+01) + (23*60+15) + (23*60+46) + (23*60+08) + (23*60+10) ) mod 6 ... (integer division ) = 1161 minutes = 19:31
that exactly what You asked |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hi Craig,
Quote: |
Convert the time from hour and minutes to minutes, find the average and convert back to hour and minutes. |
I do not believe this will give the "correct" result. Look again at the initial 2 time values used - one just before midnight and the other just after. The avereage comes out to be just before noon which is not correct (unless i misunderstand).
Hi Enrico,
Quote: |
the other two ways of getting an average are ( disregarding the date )
1) absolute average
2) baselined average ( take the deltas from a baseline ) |
should work once the before/after midnight situation is handled. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
an average is an average and
mathematics is mathematics
if a job start at 23:59 and the other one at 00:01 the average start time is 12:00
unless somebody wants to run statistics based on the shift/period
were the values are offsets from something different than 00:00 |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hi Enrico,
Quote: |
if a job start at 23:59 and the other one at 00:01 the average start time is 12:00 |
'Fraid i must "disagree". The average start time is 00:00 (midnight) rather than 12:00 (noon). |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
based on what mathematical rule
what if I had asked for the average quoting the two times the other way around |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
The point I am trying to make is that if somebody asks questions
without further clarifying, the thread will never reach an end
in such cases ( seen it done it ) all the statistics on job start times
were carried on by taking into account the delay from a projected start time
with the objective of delay and resource contention analysis |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hi Enrico,
Quote: |
based on what mathematical rule |
That would be the "rule" that when we know "too much" about the situation, we "add" things to the calculation. . .
Quote: |
what if I had asked for the average quoting the two times the other way around |
Yup, that would surely give a different average - assuming that there could be multiple start-times in a day.
Also not considered is how "skipped" days might be handled as far as averaging.
Quote: |
The point I am trying to make is that if somebody asks questions
without further clarifying, the thread will never reach an end |
For sure
Have a good one.
d |
|
Back to top |
|
|
rpuhlman
New User
Joined: 11 Jun 2007 Posts: 80 Location: Columbus, Ohio
|
|
|
|
Craq, Dick, Enrico ... great discussion ... one of the best I've seen ... Neelima, thanks for the op! |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
It seems to me that you have to know if the submission is "late" or "early".
If 2 jobs are submitted: one at 23:00, the other at 01:00. If the 1 AM job is late, there's a 2 hr difference in their times and the avg start is 24:00.
If the 1 AM job is early, there's a 22 hr difference in their times and the avg start is 12:00. |
|
Back to top |
|
|
neelima.sinha
New User
Joined: 14 Sep 2007 Posts: 30 Location: Bangalore
|
|
|
|
Hi,
after all this discussion, I still did not get an answer or may be I am not understanding what is being explained.
I would try to explain again -- I am reading a file which has job name and start date and start time, passing the record via jcl to cobol program(linkage section) --- as example I have given, sometimes job may start midnight , some times after midnight, in such case I want to know what was average start time.
as for example
if a job start at 23:59 and the other day at 00:01 the average start time is midnight 00:00hrs, this is the answer I am looking for.
can anybody explain now in a more simpler way or via some sample code
Regards, |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Convert the hours and minutes to minutes, take the average and convert the average back to hours & minutes. Details are up to you. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
Quote: |
if a job start at 23:59 and the other day at 00:01 the average start time is midnight 00:00hrs, this is the answer I am looking for. |
funny mathematics...
in mathematics You must express rules
the average for 23.59 and 00.01 is 12.00
express Your outlook in terms of a mathematical rule/constraint
not based on the fact that You know that usually Your jobs run around midnight
unless as already said in my previous posts You choose a different time window
for a default time window starting at 00:0 for 24 hours the average is 12:00 |
|
Back to top |
|
|
Douglas Wilder
Active User
Joined: 28 Nov 2006 Posts: 305 Location: Deerfield IL
|
|
|
|
If your time window is 12:00 - 12:00 ie noon to noon, try the following
If the hours are less than 12 add 24 to the hours
Convert the hours and minutes to minutes
add up all the minute values
divide by the number of values
convert the average back to hours & minutes
If the hours are greater than 24 subtract 24. |
|
Back to top |
|
|
|