I assume that your information is sorted time-wise.
Save it as a symbol:
data = {{{2010, 1, 1, 6, 15, 0.}, 0.04375}, {{2010, 1, 1, 6, 30, 0.}, 0.04375}, {{2010, 1, 1, 6, 45, 0.}, 0.04375}, {{2010, 1, 1, 7, 0, 0.}, 5}, {{2010, 1, 1, 7, 15, 0.}, 0.5}, {{2010, 1, 1, 7, 30, 0.}, 5}};
Find the time spent on each step:
data2 = Prepend[
#1,
DateDifference[First[#1], First[#2], "Minute"] // First
] & @@@ Partition[data, 2, 1]
(* {{15, {2010, 1, 1, 6, 15, 0.}, 0.04375}, {15, {2010, 1, 1, 6, 30, 0.},0.04375}, {15, {2010, 1, 1, 6, 45, 0.}, 0.04375}, {15, {2010, 1, 1, 7, 0, 0.}, 5}, {15, {2010, 1, 1, 7, 15, 0.}, 0.5}} *)
Split according to your criteria (level
), then collect your desired result, in the format {start time, end time, time spent on level}
level = 1;
data3 = Module[{start, duration},
Cases[Split[data2, Last[#1] < level && Last[#2] < level &],
x_ /; Last[Last[x]] < level :>
{
start = x[[1, 2]],
DatePlus[start, {duration = Total[First /@ x], "Minute"}],
duration
}
]
]
(* {{{2010, 1, 1, 6, 15, 0.}, {2010, 1, 1, 7, 0, 0}, 45}, {{2010, 1, 1, 7, 15, 0.}, {2010, 1, 1, 7, 30, 0}, 15}} *)
Then, to plot it:
date = DateString[#, {"Hour", ":", "Minute"}] &;
BarChart[Last /@ data3,
ChartLabels -> ("From " <> date[#1] <> " to " <> date[#2] & @@@ Most /@ data3)]