Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

how to find average of time in cobol
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
neelima.sinha

New User


Joined: 14 Sep 2007
Posts: 30
Location: Bangalore

PostPosted: Tue Mar 18, 2008 10:16 pm    Post subject: how to find average of time in cobol
Reply with quote

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
View user's profile Send private message

Craq Giegerich

Senior Member


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

PostPosted: Tue Mar 18, 2008 11:17 pm    Post subject:
Reply with quote

Convert the time from hour and minutes to minutes, find the average and convert back to hour and minutes.
Back to top
View user's profile Send private message
neelima.sinha

New User


Joined: 14 Sep 2007
Posts: 30
Location: Bangalore

PostPosted: Wed Mar 19, 2008 12:13 am    Post subject:
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Wed Mar 19, 2008 12:30 am    Post subject: Reply to: how to find average of time in cobol
Reply with quote

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
View user's profile Send private message
Craq Giegerich

Senior Member


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

PostPosted: Wed Mar 19, 2008 12:30 am    Post subject:
Reply with quote

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
View user's profile Send private message
neelima.sinha

New User


Joined: 14 Sep 2007
Posts: 30
Location: Bangalore

PostPosted: Wed Mar 19, 2008 12:36 am    Post subject:
Reply with quote

Hi enrico,

Thanks for your reply. could you please explain with my example and show the calculation.

Regards
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Wed Mar 19, 2008 1:05 am    Post subject:
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

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

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
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Wed Mar 19, 2008 1:42 am    Post subject:
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

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

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 icon_biggrin.gif

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
View user's profile Send private message
neelima.sinha

New User


Joined: 14 Sep 2007
Posts: 30
Location: Bangalore

PostPosted: Wed Mar 19, 2008 4:10 am    Post subject:
Reply with quote

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
View user's profile Send private message
Craq Giegerich

Senior Member


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

PostPosted: Wed Mar 19, 2008 4:18 am    Post subject:
Reply with quote

I repeat,
Convert the time from hour and minutes to minutes, find the average and convert back to hour and minutes.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

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

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
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Wed Mar 19, 2008 4:28 am    Post subject:
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Wed Mar 19, 2008 4:34 am    Post subject: Reply to: how to find average of time in cobol
Reply with quote

an average is an average and
mathematics is mathematics icon_cool.gif

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
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Wed Mar 19, 2008 4:44 am    Post subject:
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Wed Mar 19, 2008 4:46 am    Post subject: Reply to: how to find average of time in cobol
Reply with quote

icon_biggrin.gif based on what mathematical rule icon_biggrin.gif icon_question.gif

what if I had asked for the average quoting the two times the other way around icon_biggrin.gif
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Wed Mar 19, 2008 4:59 am    Post subject: Reply to: how to find average of time in cobol
Reply with quote

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
View user's profile Send private message
dick scherrer

Site Director


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

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

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 icon_confused.gif

Have a good one.

d
Back to top
View user's profile Send private message
rpuhlman

New User


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

PostPosted: Wed Mar 19, 2008 3:26 pm    Post subject:
Reply with quote

Craq, Dick, Enrico ... great discussion ... one of the best I've seen ... Neelima, thanks for the op!
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts How to find the first monday of the w... abdulrafi COBOL Programming 10 Fri Nov 25, 2016 3:24 pm
This topic is locked: you cannot edit posts or make replies. Get a job submitted itself every time... arunsoods JCL & VSAM 3 Tue Nov 22, 2016 4:05 pm
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Check System time(Minute) Using TIME1... balaji81_k DFSORT/ICETOOL 5 Fri Nov 11, 2016 10:53 am
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us