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




Module Module1
 
    Function TimeToDegrees(time As TimeSpan) As Double
        Return 360 * time.Hours / 24.0 + 360 * time.Minutes / (24 * 60.0) + 360 * time.Seconds / (24 * 3600.0)
    End Function
 
    Function DegreesToTime(angle As Double) As TimeSpan
        Return New TimeSpan((24 * 60 * 60 * angle \ 360) \ 3600, ((24 * 60 * 60 * angle \ 360) Mod 3600 - (24 * 60 * 60 * angle \ 360) Mod 60) \ 60, (24 * 60 * 60 * angle \ 360) Mod 60)
    End Function
 
    Function MeanAngle(angles As List(Of Double)) As Double
        Dim y_part = 0.0
        Dim x_part = 0.0
        Dim numItems = angles.Count
 
        For Each angle In angles
            x_part += Math.Cos(angle * Math.PI / 180)
            y_part += Math.Sin(angle * Math.PI / 180)
        Next
 
        Return Math.Atan2(y_part / numItems, x_part / numItems) * 180 / Math.PI
    End Function
 
    Sub Main()
        Dim digitimes As New List(Of Double)
        Dim digitime As TimeSpan
        Dim input As String
 
        Console.WriteLine("Enter times, end with no input: ")
        Do
            input = Console.ReadLine
            If Not String.IsNullOrWhiteSpace(input) Then
                If TimeSpan.TryParse(input, digitime) Then
                    digitimes.Add(TimeToDegrees(digitime))
                Else
                    Console.WriteLine("Seems this is wrong input: ingnoring time")
                End If
            End If
        Loop Until String.IsNullOrWhiteSpace(input)
 
        If digitimes.Count > 0 Then
            Console.WriteLine("The mean time is : {0}", DegreesToTime(360 + MeanAngle(digitimes)))
        End If
    End Sub
 
End Module