Seeking assistance in calculating the maximum and minimum date differences (in hours or float days) for each location. When there is only one date interval for a location, consider the difference from the date above it. The data is already sorted by date (descending) and the rack is consistent across all entries, thus can be ignored. Thank you.
var data = [
{rack: 1208, location: 42, date: "2020-05-11T13:53:51.000Z"},
{rack: 1208, location: 42, date: "2020-05-08T12:36:51.000Z"},
{rack: 1208, location: 40, date: "2020-05-08T12:36:27.000Z"},
{rack: 1208, location: 41, date: "2020-05-08T10:44:40.000Z"},
{rack: 1208, location: 41, date: "2020-05-08T10:43:33.000Z"},
{rack: 1208, location: 42, date: "2020-05-08T10:42:55.000Z"},
{rack: 1208, location: 41, date: "2020-05-08T10:41:55.000Z"},
{rack: 1208, location: 40, date: "2020-05-08T10:41:18.000Z"},
{rack: 1208, location: 40, date: "2020-05-08T09:47:42.000Z"},
{rack: 1208, location: 40, date: "2020-05-07T10:24:56.000Z"}
]
var response = {
42: {
minHours : {
value: 0.01,
startTime: '2020-05-08T10:42:55.000Z',
endTime: '2020-05-08T10:43:33.000Z'
},
maxHours : {
value: 73.28,
startTime: '2020-05-08T12:36:51.000Z',
endTime: 'NOW() Current Datetime'
}
},
41: {
//do the same
},
40: {
//do the same
}
};
This concept is akin to a timeline where tracking the "rack" movement is necessary.
1) Starting from the bottom up: the rack arrived at site 40 on 2020-05-07T10:24:56.000Z before moving to site 41 on 2020-05-08T10:41:55.000Z. Therefore, the rack spent 24.28 at location 40.
2) Subsequently, the rack reached site 41 on 2020-05-08T10:41:55.000Z followed by its move to site 42 at 2020-05-08T10:42:55.000Z. Hence, the duration of stay at site 41 was 1 minute or 0.016 hours.
The process continues with each comparison updating the maxHours and minHours for that location based on whether the difference exceeds the current maxHours or falls below minHours.