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
20080225, 23:46
20080304, 00:01
20080310, 23:15
20080225, 23:46
20080317, 23:08
20080310, 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
20080225, 23:46
20080304, 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 


enricosorichetti
Senior Member
Joined: 14 Mar 2007 Posts: 10696 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
Site Director
Joined: 23 Nov 2006 Posts: 19254 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 starttime "rules" to consider. 

Back to top 


enricosorichetti
Senior Member
Joined: 14 Mar 2007 Posts: 10696 Location: italy




it does not make any sense
but for Your sample the average start date_time is 20080306, 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
Site Director
Joined: 23 Nov 2006 Posts: 19254 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 recalculate.
I'm away from a mainframe connection just now and cannot run it here. 

Back to top 


enricosorichetti
Senior Member
Joined: 14 Mar 2007 Posts: 10696 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 20080306
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 


enricosorichetti
Senior Member
Joined: 14 Mar 2007 Posts: 10696 Location: italy




from Your data
Quote: 
20080225, 23:46
20080304, 00:01
20080310, 23:15
20080225, 23:46
20080317, 23:08
20080310, 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
Site Director
Joined: 23 Nov 2006 Posts: 19254 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 


enricosorichetti
Senior Member
Joined: 14 Mar 2007 Posts: 10696 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
Site Director
Joined: 23 Nov 2006 Posts: 19254 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 


enricosorichetti
Senior Member
Joined: 14 Mar 2007 Posts: 10696 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 


enricosorichetti
Senior Member
Joined: 14 Mar 2007 Posts: 10696 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
Site Director
Joined: 23 Nov 2006 Posts: 19254 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 starttimes 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 


