# How to merger every three minutes values?

I have some date values like

date=Uncompress[FromCharacterCode[
Flatten[ImageData[Import["http://i.stack.imgur.com/QLINL.png"],"Byte"]]]]


<|08:00:10->5,08:00:14->1,08:00:17->5,08:00:23->1,08:00:24->1,08:00:25->5,08:00:31->1,08:00:32->6,08:00:36->2,...|>

Of course,the hour not always is 08 in my real case.I have a good method to merger the value for every one minute

GroupBy[Normal[date], StringDrop[Keys[#], -3] &, Total[<|#|>] &]


<|08:00->48,08:01->54,08:02->58,08:03->73,08:04->69,08:05->76,08:06->66,08:07->70,08:08->72,08:09->70,08:10->82,08:11->77,08:12->88,08:13->78,08:14->19|>

But if I want to merger the value for every three minutes,is there any concise method to do this?

• You could use TimeSeries but you have to define what does it mean to merge every three minutes. – Kuba Jun 18 '17 at 9:08
• @Kuba Such as 03:00 and 03:02 should regard one time.In my case,I get some 08:00,08:03,08:06,08:09,08:12,08:14.. – yode Jun 18 '17 at 9:10
• Where should the 3minutes window start if the first value date is e.g: 08:04:10. – Kuba Jun 18 '17 at 9:18
• @Kuba Like the function BinLists,we should give a sort behavoir firstly.. – yode Jun 18 '17 at 9:23

Try this and let me know:

TimeSeriesAggregate[
EventSeries @ date, {Quantity[3, "Minutes"], Left}, Total
]

% // Normal


As you can see it starts with the first date in opposition to rounded example you gave. Don't know how to specify the window start automatically except of adding artificial date at the beginning.

You may also be interested in HistogramList for DateHistogram?

This is probably not the most efficient, but it's convenient and kinda concise:

In[72]:= times = Normal@KeyMap[TimeObject, date];
Map[First@First@# -> Total@Map[Last, #] &,
Block[{time = First@First@times},
SplitBy[times,
If[First[#] - time > Quantity[3, "Minutes"],
time = First[#];
True,
False
] &
]
]
]

Out[73]= {TimeObject[{8, 0, 10.}, TimeZone -> -4.] -> 178,
TimeObject[{8, 3, 12.}, TimeZone -> -4.] -> 211,
TimeObject[{8, 6, 14.}, TimeZone -> -4.] -> 217,
TimeObject[{8, 9, 17.}, TimeZone -> -4.] -> 237,
TimeObject[{8, 12, 18.}, TimeZone -> -4.] -> 157}

• Since every three minutes,it should give some result of 08:00,08:03,08:06,08:09,08:12,08:14. :) – yode Jun 18 '17 at 9:13