Skip to content

Commit

Permalink
drt: only show active data
Browse files Browse the repository at this point in the history
  • Loading branch information
dulvui committed Aug 24, 2023
1 parent e4956f0 commit e794ec6
Showing 1 changed file with 60 additions and 54 deletions.
114 changes: 60 additions & 54 deletions drt/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down

0 comments on commit e794ec6

Please sign in to comment.