Building Time Based Bins
Michael Spencer
mahs at telcopartners.com
Wed Mar 23 01:13:36 EST 2005
MCD wrote:
> I've mostly been racking my brain with this bit of code:
>
> newtm = ((klock + 4) // 5 * 5 ) % 2400
>
You might want to take another look at the first reply I sent you: it contains a
function that does this:
def groupkey(data):
"""Groups times by 5 min resolution. Note this version doesn't work
exactly like the example - so fix if necessary"""
time = data[0]
return time / 100 * 100 + (time % 100) / 5 * 5
# test it:
>>> for i in range(900,959): print groupkey([i]),
...
900 900 900 900 900 905 905 905 905 905 910 910 910 910 910 915 915 915 915
915 920 920 920 920 920 925 925 925 925 925 930 930 930 930 930 935 935 935 935
935 940 940 940 940 940 945 945 945 945 945 950 950 950 950 950 955 955 955 955
>>>
It rounds down, for the reason you have come across
Michael
More information about the Python-list
mailing list