split time then group by 15 min mongodb
-
I have a Schema in mongodb like:-
{
_id: ObjectId("5e05c1089b3e4e333cee8c39"),
name:"Alex",
activity:[{
{
_id: ObjectId("5e05c1089b3e4e333cee8c39"),
type: 'run',
start_timestamp: ISODate("2020-01-11T11:34:59.804Z"),
end_timestamp: ISODate("2020-01-11T11:40:00.804Z")
},
{
_id: ObjectId("5e05c1089b3e4e333cee8c40"),
type: 'stop',
start_timestamp: ISODate("2020-01-11T11:40:00.804Z"),
end_timestamp: ISODate("2020-01-11T11:42:00.804Z")
},
{
_id: ObjectId("5e05c1089b3e4e333cee8c41"),
type: 'wait',
start_timestamp: ISODate("2020-01-11T11:42:00.804Z"),
end_timestamp: ISODate("2020-01-11T11:52:00.804Z")
},
}]
}This is a schema for a man activity, i need to find brake-up of every 15 minute (brake-up duration in minute) like
{
_id: "2020-01-11T11:34 to 2020-01-11T11:49" ,
duration: 15,
brake-up:{
run:6,
stop:2,
wait:7
}
}here type: wait should be split into 2 duration "2020-01-11T11:34 to 2020-01-11T11:49" 7 min and "2020-01-11T11:49 to 2020-01-11T12:04" 3 min .
{
_id: "2020-01-11T11:34 to 2020-01-11T12:04" ,
duration: 15,
brake-up:{
wait:3
}
},Thanks