Talk:Averages/Mean time of day: Difference between revisions
Content added Content deleted
m (promote to task) |
|||
Line 3: | Line 3: | ||
:You have to factor in minutes and hours here, so the task may not be completely redundant. [[User:Markhobley|Markhobley]] 19:32, 11 February 2013 (UTC) |
:You have to factor in minutes and hours here, so the task may not be completely redundant. [[User:Markhobley|Markhobley]] 19:32, 11 February 2013 (UTC) |
||
I think this is ready to promote to task. [[User:Markhobley|Markhobley]] 19:32, 11 February 2013 (UTC) |
I think this is ready to promote to task. [[User:Markhobley|Markhobley]] 19:32, 11 February 2013 (UTC) |
||
==TCL and rounding== |
|||
TCL has a different output than others, of 23:47:44 instead of 23:47:43. It seems to be somewhere in the calculation of the mean time rather than in the split into HH:MM:SS as I tried the TCL way in my python - inserting the two lines before the return statement below and got 43 seconds and not 44 again. |
|||
<lang python>def mean_time(times): |
|||
t = (time.split(':') for time in times) |
|||
seconds = ((float(s) + int(m) * 60 + int(h) * 3600) |
|||
for h, m, s in t) |
|||
day = 24 * 60 * 60 |
|||
to_angles = [s * 360. / day for s in seconds] |
|||
mean_as_angle = mean_angle(to_angles) |
|||
mean_seconds = mean_as_angle * day / 360. |
|||
if mean_seconds < 0: |
|||
mean_seconds += day |
|||
h, m = divmod(mean_seconds, 3600) |
|||
m, s = divmod(m, 60) |
|||
a = mean_seconds |
|||
print("%02d:%02d:%02d" % (a / 60 / 60 % 24, a / 60 % 60, a % 60)) |
|||
return '%02i:%02i:%02i' % (h, m, s)</lang> |
|||
--[[User:Paddy3118|Paddy3118]] ([[User talk:Paddy3118|talk]]) 05:57, 2 July 2013 (UTC) |
Revision as of 05:57, 2 July 2013
It seems redundant to have a task that is exactly the same as Averages/Mean angle except that 360 degrees is replaced with 24 hours. --Spoon! 08:57, 12 July 2012 (UTC)
- A bit. I agree, except I suspect most of the code for this task will involve going to and from the printable time format. I added it to the "Date and time" category. —Sonia 17:39, 21 September 2012 (UTC)
- You have to factor in minutes and hours here, so the task may not be completely redundant. Markhobley 19:32, 11 February 2013 (UTC)
I think this is ready to promote to task. Markhobley 19:32, 11 February 2013 (UTC)
TCL and rounding
TCL has a different output than others, of 23:47:44 instead of 23:47:43. It seems to be somewhere in the calculation of the mean time rather than in the split into HH:MM:SS as I tried the TCL way in my python - inserting the two lines before the return statement below and got 43 seconds and not 44 again. <lang python>def mean_time(times):
t = (time.split(':') for time in times) seconds = ((float(s) + int(m) * 60 + int(h) * 3600) for h, m, s in t) day = 24 * 60 * 60 to_angles = [s * 360. / day for s in seconds] mean_as_angle = mean_angle(to_angles) mean_seconds = mean_as_angle * day / 360. if mean_seconds < 0: mean_seconds += day h, m = divmod(mean_seconds, 3600) m, s = divmod(m, 60) a = mean_seconds print("%02d:%02d:%02d" % (a / 60 / 60 % 24, a / 60 % 60, a % 60)) return '%02i:%02i:%02i' % (h, m, s)</lang>