diff --git a/drt/utils/index.js b/drt/utils/index.js index a7f87b2a..9832037d 100644 --- a/drt/utils/index.js +++ b/drt/utils/index.js @@ -10,45 +10,48 @@ function generateEntitiesVehicle(data) { const entities = []; for (const item of data) { - let capacityMax = 0; - let capacityUsed = 0; - for (const [key, value] of Object.entries(item.smetadata.capacityMax)) { - capacityMax += value - } - for (const [key, value] of Object.entries(item.smetadata.capacityUsed)) { - capacityUsed += value - } - let occupancyStatus = 5; //FULL - if (capacityMax > 0) { - const percentage = 100 * capacityUsed / capacityMax; - if (percentage === 0) { - occupancyStatus = 0; //EMPTY - } else if (percentage <= 50) { - occupancyStatus = 1; //MANY_SEAT_AVAILABLE - } else if (percentage < 100) { - occupancyStatus = 2; //FEW_SEAT_AVAILABLE - } - } + if (item.sactive === true) { - entities.push( - { - position: { - latitude: item.scoordinate.y, - longitude: item.scoordinate.x - }, - lat: item.scoordinate.y, - lon: item.scoordinate.x, - timestamp: new Date(item.mvalidtime || 0).getTime() / 1000, - vehicle: { - id: item.sname, - name: item.smetadata.type.name, - label: item.smetadata.type.name - }, - capacity: capacityMax, - free: capacityMax - capacityUsed, - occupancyStatus + let capacityMax = 0; + let capacityUsed = 0; + for (const [key, value] of Object.entries(item.smetadata.capacityMax)) { + capacityMax += value + } + for (const [key, value] of Object.entries(item.smetadata.capacityUsed)) { + capacityUsed += value + } + let occupancyStatus = 5; //FULL + if (capacityMax > 0) { + const percentage = 100 * capacityUsed / capacityMax; + if (percentage === 0) { + occupancyStatus = 0; //EMPTY + } else if (percentage <= 50) { + occupancyStatus = 1; //MANY_SEAT_AVAILABLE + } else if (percentage < 100) { + occupancyStatus = 2; //FEW_SEAT_AVAILABLE + } } - ); + + entities.push( + { + position: { + latitude: item.scoordinate.y, + longitude: item.scoordinate.x + }, + lat: item.scoordinate.y, + lon: item.scoordinate.x, + timestamp: new Date(item.mvalidtime || 0).getTime() / 1000, + vehicle: { + id: item.sname, + name: item.smetadata.type.name, + label: item.smetadata.type.name + }, + capacity: capacityMax, + free: capacityMax - capacityUsed, + occupancyStatus + } + ); + } } return entities; } @@ -59,23 +62,26 @@ function generateEntitiesStop(data) { let count = -1; for (const item of data) { - entities.push( - { - position: { - latitude: item.scoordinate.y, - longitude: item.scoordinate.x - }, - lat: item.scoordinate.y, - lon: item.scoordinate.x, - timestamp: new Date(item.mvalidtime || 0).getTime() / 1000, - stop: { - id: item.scode, - name: item.sname - }, - area: item.smetadata.groups.length === 0 ? 0 : item.smetadata.groups[0].id, - } - ); - count -= 1; + if (item.sactive === true) { + + entities.push( + { + position: { + latitude: item.scoordinate.y, + longitude: item.scoordinate.x + }, + lat: item.scoordinate.y, + lon: item.scoordinate.x, + timestamp: new Date(item.mvalidtime || 0).getTime() / 1000, + stop: { + id: item.scode, + name: item.sname + }, + area: item.smetadata.groups.length === 0 ? 0 : item.smetadata.groups[0].id, + } + ); + count -= 1; + } } return entities;