Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

 how to find average of time in cobol Goto page 1, 2  Next
Author Message
neelima.sinha

New User

Joined: 14 Sep 2007
Posts: 30
Location: Bangalore

 Posted: Tue Mar 18, 2008 10:16 pm    Post subject: how to find average of time in cobol 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,

Craq Giegerich

Senior Member

Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

 Posted: Tue Mar 18, 2008 11:17 pm    Post subject: Convert the time from hour and minutes to minutes, find the average and convert back to hour and minutes.
neelima.sinha

New User

Joined: 14 Sep 2007
Posts: 30
Location: Bangalore

 Posted: Wed Mar 19, 2008 12:13 am    Post subject: 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
enrico-sorichetti

Global Moderator

Joined: 14 Mar 2007
Posts: 10457
Location: italy

 Posted: Wed Mar 19, 2008 12:30 am    Post subject: Reply to: how to find average of time in cobol 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
Craq Giegerich

Senior Member

Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

 Posted: Wed Mar 19, 2008 12:30 am    Post subject: 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.
neelima.sinha

New User

Joined: 14 Sep 2007
Posts: 30
Location: Bangalore

 Posted: Wed Mar 19, 2008 12:36 am    Post subject: Hi enrico, Thanks for your reply. could you please explain with my example and show the calculation. Regards
dick scherrer

Site Director

Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

Posted: Wed Mar 19, 2008 1:05 am    Post subject:

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.
enrico-sorichetti

Global Moderator

Joined: 14 Mar 2007
Posts: 10457
Location: italy

Posted: Wed Mar 19, 2008 1:09 am    Post subject: Reply to: how to find average of time in cobol

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
dick scherrer

Site Director

Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

Posted: Wed Mar 19, 2008 1:42 am    Post subject:

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.
enrico-sorichetti

Global Moderator

Joined: 14 Mar 2007
Posts: 10457
Location: italy

Posted: Wed Mar 19, 2008 4:08 am    Post subject: Reply to: how to find average of time in cobol

 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
neelima.sinha

New User

Joined: 14 Sep 2007
Posts: 30
Location: Bangalore

 Posted: Wed Mar 19, 2008 4:10 am    Post subject: 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
Craq Giegerich

Senior Member

Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

 Posted: Wed Mar 19, 2008 4:18 am    Post subject: I repeat, Convert the time from hour and minutes to minutes, find the average and convert back to hour and minutes.
enrico-sorichetti

Global Moderator

Joined: 14 Mar 2007
Posts: 10457
Location: italy

Posted: Wed Mar 19, 2008 4:24 am    Post subject: Reply to: how to find average of time in cobol

 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

dick scherrer

Site Director

Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

Posted: Wed Mar 19, 2008 4:28 am    Post subject:

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.
enrico-sorichetti

Global Moderator

Joined: 14 Mar 2007
Posts: 10457
Location: italy

 Posted: Wed Mar 19, 2008 4:34 am    Post subject: Reply to: how to find average of time in cobol 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
dick scherrer

Site Director

Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

Posted: Wed Mar 19, 2008 4:44 am    Post subject:

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).
enrico-sorichetti

Global Moderator

Joined: 14 Mar 2007
Posts: 10457
Location: italy

 Posted: Wed Mar 19, 2008 4:46 am    Post subject: Reply to: how to find average of time in cobol based on what mathematical rule what if I had asked for the average quoting the two times the other way around
enrico-sorichetti

Global Moderator

Joined: 14 Mar 2007
Posts: 10457
Location: italy

 Posted: Wed Mar 19, 2008 4:59 am    Post subject: Reply to: how to find average of time in cobol 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
dick scherrer

Site Director

Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

Posted: Wed Mar 19, 2008 5:44 am    Post subject: Reply to: how to find average of time in cobol

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
rpuhlman

New User

Joined: 11 Jun 2007
Posts: 80
Location: Columbus, Ohio

 Posted: Wed Mar 19, 2008 3:26 pm    Post subject: Craq, Dick, Enrico ... great discussion ... one of the best I've seen ... Neelima, thanks for the op!
 All times are GMT + 6 HoursGoto page 1, 2  Next
 Page 1 of 2

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics How to display offset thru cobol prog... tvinodkumar7 CICS 1 Sun Apr 22, 2018 8:42 pm Linkage editor is part of COBOL, z/OS... ankit.jain COBOL Programming 4 Fri Apr 20, 2018 4:17 pm Difference between EQUAL and EQUAL TO... jithinraghavan COBOL Programming 3 Thu Apr 19, 2018 2:22 am Call COBOL or PLI with a click from w... vaibhav gs All Other Mainframe Topics 1 Mon Apr 16, 2018 7:29 pm COBOL MVS options BiswajitDG COBOL Programming 8 Fri Apr 06, 2018 12:35 am

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us