Merge pull request #48 from 0hAodha/earlyOnTimeFiltering

add primitive early & on time filtering
This commit is contained in:
Conor McNamara
2023-03-12 20:44:18 +00:00
committed by GitHub

View File

@ -1,5 +1,15 @@
<template> <template>
<Navbar /> <Navbar />
<nav class="navbar navbar-light bg-light">
<div class="container-fluid" @change="decideShowTrains();">
<input type="checkbox" id="showLate" v-model="showLate"/>
<label for="showLate">Show Late Trains</label>
<input type="checkbox" id="showOnTime" v-model="showOnTime"/>
<label for="showOnTime">Show On-Time Trains</label>
</div>
</nav>
<transition id="sidebar" name="slideLeft"> <transition id="sidebar" name="slideLeft">
<div v-if="store.displaySelectedTrain && store.selectedTrain"> <div v-if="store.displaySelectedTrain && store.selectedTrain">
<TrainSidebar /> <TrainSidebar />
@ -17,7 +27,7 @@
<!-- train overlay --> <!-- train overlay -->
<template v-for="coordinate, i in trainCoordinates" :position="inline-block"> <template v-for="coordinate, i in trainCoordinates" :position="inline-block">
<ol-overlay :position="coordinate" :positioning="center-center" :offset="[-14,-16]"> <ol-overlay v-if="showTrains[i]" :position="coordinate" :positioning="center-center" :offset="[-14,-16]">
<div class="overlay-content" @click="getSelectedTrain(i)"> <div class="overlay-content" @click="getSelectedTrain(i)">
<div v-if="getTrainType(i) === 'Dart'"> <div v-if="getTrainType(i) === 'Dart'">
<img v-if="isTrainRunning(i) && isTrainLate(i)" src="../assets/red-train-tram-solid.png" class="trainMapIcon" alt="Late DART Icon"> <img v-if="isTrainRunning(i) && isTrainLate(i)" src="../assets/red-train-tram-solid.png" class="trainMapIcon" alt="Late DART Icon">
@ -52,13 +62,13 @@
</template> </template>
<script> <script>
import { store } from '../store/store' import { store } from '../store/store';
import { ref } from 'vue'; import { ref } from 'vue';
import { fromLonLat, toLonLat } from 'ol/proj.js'; import { fromLonLat, toLonLat } from 'ol/proj.js';
import { getFunctions, httpsCallable, connectFunctionsEmulator } from "firebase/functions"; import { getFunctions, httpsCallable, connectFunctionsEmulator } from "firebase/functions";
import app from '../api/firebase'; import app from '../api/firebase';
import Navbar from '../components/Navbar.vue' import Navbar from '../components/Navbar.vue';
import MarqueeText from 'vue-marquee-text-component' import MarqueeText from 'vue-marquee-text-component';
import TrainSidebar from '../components/TrainSidebar.vue'; import TrainSidebar from '../components/TrainSidebar.vue';
import StationSidebar from '../components/StationSidebar.vue'; import StationSidebar from '../components/StationSidebar.vue';
@ -66,14 +76,20 @@ export default {
name: "MapPage", name: "MapPage",
data() { data() {
const center = ref(fromLonLat([-7.5029786, 53.4494762])) const center = ref(fromLonLat([-7.5029786, 53.4494762]));
const projection = ref('EPSG:3857') const projection = ref('EPSG:3857');
const zoom = ref(7) const zoom = ref(7);
const rotation = ref(0) const rotation = ref(0);
const radius = ref(10) const radius = ref(10);
const strokeWidth = ref(1) const strokeWidth = ref(1);
const strokeColor = ref('black') const strokeColor = ref('black');
const fillColor = ref('red') const fillColor = ref('red');
let showTrains = [];
let showLate = true;
let showOnTime = true;
let showEarly = true;
return { return {
center, center,
@ -85,6 +101,7 @@ export default {
strokeColor, strokeColor,
fillColor, fillColor,
showTrains: [],
trainCoordinates: [], trainCoordinates: [],
stationCoordinates: [], stationCoordinates: [],
allTrains: {}, allTrains: {},
@ -92,6 +109,10 @@ export default {
publicMessages: [], publicMessages: [],
isPaused: false, isPaused: false,
store, store,
showLate,
showOnTime,
showEarly
} }
}, },
@ -110,23 +131,31 @@ export default {
else { else {
this.getTrainAndStationData(); this.getTrainAndStationData();
} }
// request new data every 60 seconds // request new data every 60 seconds
// window.setInterval(this.getLiveTrainData, 60000); // window.setInterval(this.getLiveTrainData, 60000);
}, },
methods: { methods: {
// method to determine whether or not to show each train
decideShowTrains() {
for (let i = 0; i < this.showTrains.length; i++) {
this.showTrains[i] = (this.showLate && this.isTrainLate(i)) || (this.showOnTime && !this.isTrainLate(i));
}
},
// method to display a selected train // method to display a selected train
getSelectedTrain(i) { getSelectedTrain(i) {
store.setSelectedTrain(this.allTrains[i]); store.setSelectedTrain(this.allTrains[i]);
if (store.displaySelectedStation) store.setDisplaySelectedStation(false) if (store.displaySelectedStation) store.setDisplaySelectedStation(false);
store.setDisplaySelectedTrain(true) store.setDisplaySelectedTrain(true);
}, },
// method to display a selected station // method to display a selected station
getSelectedStation(i) { getSelectedStation(i) {
store.setSelectedStation(this.allStations[i]); store.setSelectedStation(this.allStations[i]);
if (store.displaySelectedTrain) store.setDisplaySelectedTrain(false) if (store.displaySelectedTrain) store.setDisplaySelectedTrain(false);
store.setDisplaySelectedStation(true) store.setDisplaySelectedStation(true);
}, },
// method to determine whether or not a selected train is late // method to determine whether or not a selected train is late
@ -144,6 +173,66 @@ export default {
return false; return false;
}, },
// // method to determine whether or not a selected train is early
// isTrainEarly(i) {
// // check if the train is running
// if (this.allTrains[i]["TrainStatus"][0] == "R") {
// let publicMessage = this.allTrains[i]["PublicMessage"][0];
// let startTimeStr = publicMessage.indexOf("(");
//
// // check if the train is early
// if (publicMessage[startTimeStr+1] == "-" && publicMessage[startTimeStr+1] != "0") {
// return true;
// }
// }
// return false;
// },
//
// // method to determine whether or not a selected train is on time
// isTrainOnTime(i) {
// // check if the train is running
// if (this.allTrains[i]["TrainStatus"][0] == "R") {
// let publicMessage = this.allTrains[i]["PublicMessage"][0];
// let startTimeStr = publicMessage.indexOf("(");
//
// // check if the train is on time
// if (publicMessage[startTimeStr+1] != "-" && publicMessage[startTimeStr+1] == "0") {
// return true;
// }
// }
// return false;
// },
//
// // method to determine whether or not a selected train is late
// isTrainLate(i) {
// // check if the train is running
// if (this.allTrains[i]["TrainStatus"][0] == "R") {
// let publicMessage = this.allTrains[i]["PublicMessage"][0];
// let startTimeStr = publicMessage.indexOf("(");
//
// // check if the train is late
// if (publicMessage[startTimeStr+1] != "-" && publicMessage[startTimeStr+1] != "0") {
// return true;
// }
// }
// return false;
// },
//
// // method to determine whether or not a selected train is late
// isTrainLate(i) {
// // check if the train is running
// if (this.allTrains[i]["TrainStatus"][0] == "R") {
// let publicMessage = this.allTrains[i]["PublicMessage"][0];
// let startTimeStr = publicMessage.indexOf("(");
//
// // check if the train is late
// if (publicMessage[startTimeStr+1] != "-" && publicMessage[startTimeStr+1] != "0") {
// return true;
// }
// }
// return false;
// },
// method to determine whether or not a selected train is running // method to determine whether or not a selected train is running
isTrainRunning(i) { isTrainRunning(i) {
if (this.allTrains[i]["TrainStatus"][0] == "R") { if (this.allTrains[i]["TrainStatus"][0] == "R") {
@ -197,6 +286,10 @@ export default {
for (var i=0; i<response.data.length; i++) { for (var i=0; i<response.data.length; i++) {
let train = response.data[i]; let train = response.data[i];
this.allTrains[i] = train; this.allTrains[i] = train;
// filling showTrains witht the default value true
this.showTrains[i] = true;
this.trainCoordinates[i] = ref(fromLonLat([train["TrainLongitude"][0], train["TrainLatitude"][0]])) this.trainCoordinates[i] = ref(fromLonLat([train["TrainLongitude"][0], train["TrainLatitude"][0]]))
insights["totalNumTrains"] += 1 insights["totalNumTrains"] += 1