Task[edit]
A particular activity of bats occurs at these times of the day:

23:00:17, 23:40:20, 00:12:45, 00:17:19
Using the idea that there are twenty-four hours in a day,
which is analogous to there being 360 degrees in a circle,
map times of day to and from angles;
and using the ideas of Averages/Mean angle
compute and show the average time of the nocturnal activity
to an accuracy of one second of time.

See also
Tasks for calculating statistical measures



in one go
moving (sliding window)
moving (cumulative)

Mean
Arithmetic

Statistics/Basic
Averages/Arithmetic mean
Averages/Pythagorean means


Averages/Simple moving average




Geometric

Averages/Pythagorean means




Harmonic

Averages/Pythagorean means




Quadratic

Averages/Root mean square




Circular

Averages/Mean angle
Averages/Mean time of day




Median

Averages/Median




Mode

Averages/Mode




Standard deviation

Statistics/Basic



Cumulative standard deviation




INCLUDE "H6:REALMATH.ACT"
 
DEFINE PTR="CARD"
TYPE Time=[BYTE s,m,h]
REAL r60
 
PROC PrintB2(BYTE b)
  IF b<10 THEN Put('0) FI
  PrintB(b)
RETURN
 
PROC PrintTime(Time POINTER t)
  PrintB2(t.h) Put(':)
  PrintB2(t.m) Put(':)
  PrintB2(t.s)
RETURN
 
PROC Decode(CHAR ARRAY st Time POINTER t)
  CHAR ARRAY tmp
 
  IF st(0)#8 THEN Break() FI
  SCopyS(tmp,st,1,2) t.h=ValB(tmp)
  SCopyS(tmp,st,4,5) t.m=ValB(tmp)
  SCopyS(tmp,st,7,8) t.s=ValB(tmp)
RETURN
 
PROC TimeToSeconds(Time POINTER t REAL POINTER seconds)
  REAL r
 
  IntToReal(t.h,seconds)
  RealMult(seconds,r60,seconds)
  IntToReal(t.m,r)
  RealAdd(seconds,r,seconds)
  RealMult(seconds,r60,seconds)
  IntToReal(t.s,r)
  RealAdd(seconds,r,seconds)
RETURN
 
PROC SecondsToTime(REAL POINTER seconds Time POINTER t)
  REAL tmp1,tmp2
 
  RealAssign(seconds,tmp1)
  RealMod(tmp1,r60,tmp2)
  t.s=RealToInt(tmp2)
  RealDivInt(tmp1,r60,tmp2)
  RealMod(tmp2,r60,tmp1)
  t.m=RealToInt(tmp1)
  RealDivInt(tmp2,r60,tmp1)
  t.h=RealToInt(tmp1)
RETURN
 
PROC AverageTime(PTR ARRAY times BYTE count Time POINTER res)
  BYTE i
  Time t
  REAL avg,rcount,seconds,halfDay,day
 
  IntToReal(0,avg)
  IntToReal(count,rcount)
  ValR("43200",halfDay) ;seconds in the half of day
  ValR("86400",day)     ;seconds in the whole day
  FOR i=0 TO count-1
  DO
    Decode(times(i),t)
    TimeToSeconds(t,seconds)
    IF RealLess(seconds,halfDay) THEN
      RealAdd(seconds,day,seconds) ;correction of time
    FI
    RealAdd(avg,seconds,avg)
  OD
  RealDivInt(avg,rcount,avg)
  WHILE RealGreaterOrEqual(avg,day)
  DO
    RealSub(avg,day,avg) ;correction of time
  OD
  SecondsToTime(avg,res)
RETURN
 
PROC Main()
  DEFINE COUNT="4"
  PTR ARRAY times(COUNT)
  Time t
 
  Put(125) PutE() ;clear the screen
  IntToReal(60,r60)
  times(0)="23:00:17" times(1)="23:40:20"
  times(2)="00:12:45" times(3)="00:17:19"
 
  AverageTime(times,COUNT,t)
  Print("Mean time is ") PrintTime(t)
RETURN