Skip to content

Commit

Permalink
Merge branch 'develop' into camera-status-min
Browse files Browse the repository at this point in the history
  • Loading branch information
khavinshankar authored Jul 28, 2023
2 parents 324fb31 + 9f9926d commit f65f4db
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/controller/ObservationController.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,13 @@ const updateObservationsToCare = async () => {
const filterStatusData = () => {
const MIN_IN_MS = 60000;
statusData = statusData.filter(
(status) => new Date() - status.time <= 30 * MIN_IN_MS
(status) => new Date() - new Date(status.time) <= 30 * MIN_IN_MS
);
};

const parseDataAsStatus = (data) => {
return {
time: new Date(),
time: new Date(new Date().setSeconds(0, 0)).toISOString(),

status: data.reduce((acc, device_observations) => {
device_observations.forEach((observation) => {
Expand All @@ -396,7 +396,24 @@ const parseDataAsStatus = (data) => {
const addStatusData = (data) => {
filterStatusData();

statusData.push(parseDataAsStatus(data));
const newStatus = parseDataAsStatus(data);

const index = statusData.findIndex(
(status) => status.time === newStatus.time
);

if (index === -1) {
statusData.push(newStatus);
return;
}

statusData[index] = {
time: newStatus.time,
status: {
...statusData[index].status,
...newStatus.status,
},
};
};

export class ObservationController {
Expand Down

0 comments on commit f65f4db

Please sign in to comment.