Exclude trains with false coordinates
This commit is contained in:
@ -25,7 +25,6 @@ exports.getLiveTrainData = functions.https.onRequest((request, response) => {
|
|||||||
snapshot.forEach(doc => {
|
snapshot.forEach(doc => {
|
||||||
jsonData.push(doc.data());
|
jsonData.push(doc.data());
|
||||||
});
|
});
|
||||||
// response.send(jsonData);
|
|
||||||
response.json({data: jsonData});
|
response.json({data: jsonData});
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@ -56,21 +55,25 @@ exports.postLiveTrainData = functions.https.onRequest((request, response) => {
|
|||||||
batchDelete.commit().then(function() {
|
batchDelete.commit().then(function() {
|
||||||
// batch write all train JSON objects to the "liveTrainData" collection
|
// batch write all train JSON objects to the "liveTrainData" collection
|
||||||
var batchWrite = db.batch();
|
var batchWrite = db.batch();
|
||||||
|
|
||||||
jsonData.forEach((doc) => {
|
jsonData.forEach((doc) => {
|
||||||
// set the train's code as the document ID
|
// ignore trains with longitudes or latitudes equal zero
|
||||||
var docID = db.collection('liveTrainData').doc(doc["TrainCode"][0]);
|
if (!(doc["TrainLongitude"] == 0 || doc["TrainLatitude"] == 0)) {
|
||||||
batchWrite.set(docID, doc);
|
// set the train's code as the document ID
|
||||||
|
var docID = db.collection('liveTrainData').doc(doc["TrainCode"][0]);
|
||||||
|
batchWrite.set(docID, doc);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
batchWrite.commit().then(function () {
|
batchWrite.commit().then(function () {
|
||||||
response.send("Successfully fetched and uploaded data from Irish Rail");
|
response.send({data: "Successfully fetched and uploaded data from Irish Rail"});
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.catch((error) => {;
|
.catch((error) => {;
|
||||||
response.send("Error fetching data from the IrishRail API");
|
response.send({data: "Error fetching data from the IrishRail API"});
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
})
|
})
|
Reference in New Issue
Block a user