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




' FB 1.05.0 Win64
 
Const pi As Double = 3.1415926535897932
 
Function meanAngle(angles() As Double) As Double
  Dim As Integer length = Ubound(angles) - Lbound(angles) + 1
  Dim As Double sinSum = 0.0
  Dim As Double cosSum = 0.0
  For i As Integer = LBound(angles) To UBound(angles)
    sinSum += Sin(angles(i) * pi / 180.0)
    cosSum += Cos(angles(i) * pi / 180.0)    
  Next
  Return Atan2(sinSum / length, cosSum / length) * 180.0 / pi
End Function
 
' time string assumed to be in format "hh:mm:ss"
Function timeToSecs(t As String) As Integer
  Dim As Integer hours = Val(Left(t, 2))
  Dim As Integer mins =  Val(Mid(t, 4, 2))
  Dim As Integer secs =  Val(Right(t, 2))
  Return 3600 * hours + 60 * mins + secs  
End Function
 
' 1 second of time = 360/(24 * 3600) = 1/240th degree
Function timeToDegrees(t As String) As Double
  Dim secs As Integer = timeToSecs(t)
  Return secs/240.0
End Function
 
Function degreesToTime(d As Double) As String
  If d < 0 Then d += 360.0 
  Dim secs As Integer  = d * 240.0
  Dim hours As Integer = secs \ 3600
  Dim mins As Integer  = secs Mod 3600
  secs = mins Mod 60
  mins = mins \ 60
  Dim hBuffer As String = Right("0" + Str(hours), 2)
  Dim mBuffer As String = Right("0" + Str(mins), 2)
  Dim sBuffer As String = Right("0" + Str(secs), 2)
  Return hBuffer + ":" + mBuffer + ":" + sBuffer
End Function
 
Dim tm(1 To 4) As String = {"23:00:17", "23:40:20", "00:12:45", "00:17:19"}
Dim angles(1 To 4) As Double
 
For i As Integer = 1 To 4
  angles(i) = timeToDegrees(tm(i))
Next
 
Dim mean As Double = meanAngle(angles())
Print "Average time is : "; degreesToTime(mean)
Print
Print "Press any key to quit"
Sleep