我有按天分组的日期数组,我想按时间开始和结束对日期进行分组,然后减去最后一个值 - 第一个值。
时间开始和结束也在一个数组中。
数据数组:
const data = [
{ x: "2021-10-17T24:00:00.000Z", y: 52 },
{ x: "2021-10-17T22:14:00.000Z", y: 44 },
{ x: "2021-10-17T22:10:00.000Z", y: 36 },
{ x: "2021-10-17T22:00:00.000Z", y: 29 },
{ x: "2021-10-17T20:14:45.540Z", y: 24 },
{ x: "2021-10-17T20:13:45.540Z", y: 20 },
{ x: "2021-10-17T20:00:45.540Z", y: 18 },
{ x: "2021-10-17T14:38:45.540Z", y: 17 },
{ x: "2021-10-17T13:38:45.540Z", y: 15 },
{ x: "2021-09-16T14:36:46.540Z", y: 13 },
{ x: "2021-01-04T14:35:46.540Z", y: 12 },
{ x: "2021-01-01T14:30:46.540Z", y: 10 },
{ x: "2020-02-01T06:28:47.520Z", y: 7 },
{ x: "2020-02-01T07:28:47.520Z", y: 6 },
{ x: "2019-04-13T10:19:20.034Z", y: 5 },
{ x: "2018-01-01T09:09:19.134Z", y: 4 },
{ x: "2017-01-01T12:09:19.034Z", y: 3 },
{ x: "2016-01-02T12:10:20.034Z", y: 2 },
{ x: "2016-01-02T11:10:20.034Z", y: 1 }
];
时间开始和结束数组:
const configurations = [
{
label: "C1",
startTime: { hr: "06", min: "00" },
endTime: { hr: "22", min: "00" }
},
{
label: "C2",
startTime: { hr: "22", min: "00" },
endTime: { hr: "24", min: "00" }
}
];
按天分组的数据:
[
{
"value": 37, // 52 -15 (last value - first value)
"label": "2021/10/17",
// (I want to group this data by time start and end)
"data": [
{
"x": "2021-10-17T13:38:45.540Z",
"y": 15
},
{
"x": "2021-10-17T14:38:45.540Z",
"y": 17
},
{
"x": "2021-10-17T20:00:45.540Z",
"y": 18
},
{
"x": "2021-10-17T20:13:45.540Z",
"y": 20
},
{
"x": "2021-10-17T20:14:45.540Z",
"y": 24
},
{
"x": "2021-10-17T22:00:00.000Z",
"y": 29
},
{
"x": "2021-10-17T22:10:00.000Z",
"y": 36
},
{
"x": "2021-10-17T22:14:00.000Z",
"y": 44
},
{
"x": "2021-10-17T24:00:00.000Z",
"y": 52
}
]
},
//...
]
预期输出:
[
{
"value": 37, // 52 -15 (last value - first value)
"label": "2021/10/17",
"data": [
{
value: 14, // 29-15 =14
label: "C1"
},
{
value: 23, // 52-29 = 23
label: "C2"
}
]
},
// ...
]