Czasowo wstrzymano dziennik stacji

This commit is contained in:
2020-08-23 02:01:22 +02:00
parent 8ab8461276
commit 5a9795f0a5
4 changed files with 3703 additions and 1866 deletions
+155 -67
View File
@@ -1,79 +1,167 @@
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
// import * as functions from "firebase-functions";
// import * as admin from "firebase-admin";
admin.initializeApp();
const db = admin.firestore();
// admin.initializeApp();
// const db = admin.firestore();
import axios from "axios";
// import axios from "axios";
exports.scheduledUpdate = functions.pubsub
.schedule("0 * * * *")
.onRun(async (context) => {
let stationData: {
stationName: string;
dispatcherName: string;
isOnline: boolean;
region: string;
}[];
// const stationJSONList: any[] = require("./stations.json");
try {
stationData = await (
await axios.get(
"https://api.td2.info.pl:9640/?method=getStationsOnline"
)
).data.message;
} catch (error) {
return;
}
// let stationAPIData: {
// stationName: string;
// dispatcherName: string;
// isOnline: boolean;
// region: string;
// }[];
const historyRef = db.collection("history");
// let previousOnlineStations: {
// stationName: string;
// dispatcherName: string;
// occupiedFrom: number;
// }[] = [];
stationData.forEach(async (station) => {
const docRef = historyRef.doc(station.stationName);
const docSnapshot = await docRef.get();
// // const test = functions.pubsub.schedule("0 * * * *").onRun(async (context) => {
// // try {
// // stationAPIData = await (
// // await axios.get("https://api.td2.info.pl:9640/?method=getStationsOnline")
// // ).data.message;
// // } catch (error) {
// // return;
// // }
if (!docSnapshot.exists) {
docRef.set({
occupiedFrom: Date.now(),
currentDispatcherName: station.dispatcherName,
});
return;
}
});
// // if (previousOnlineStations.length == 0) {
// // const historyRef = db.collection("dispatcherHistory");
const snapshot = await historyRef.get();
// // stationAPIData
// // .filter((station) => station.isOnline && station.region === "eu")
// // .forEach(async (station) => {
// // const isOfficial: boolean = stationJSONList.some(
// // (stationData) => stationData.stationName === station.stationName
// // );
snapshot.forEach(async (doc) => {
const docData = doc.data();
const docRef = historyRef.doc(doc.id);
// // if (!isOfficial) return;
const APIStationData = stationData
.filter((station) => station.isOnline && station.region === "eu")
.find((station) => station.stationName == doc.id);
// // const docRef = historyRef.doc(station.stationName);
// // const docSnap = await docRef.get();
if (docData.currentDispatcherName != "") {
if (
!APIStationData ||
APIStationData.dispatcherName != docData.currentDispatcherName
) {
docRef.update({
currentDispatcherName: !APIStationData
? ""
: APIStationData.dispatcherName,
occupiedFrom: !APIStationData ? 0 : Date.now(),
});
// // const occupiedFrom = Date.now();
docRef.collection("dispatcherHistory").add({
currentDispatcherName: docData.currentDispatcherName,
occupiedFrom: docData.occupiedFrom,
occupiedTo: Date.now(),
});
}
} else if (APIStationData) {
docRef.update({
currentDispatcherName: APIStationData.dispatcherName,
occupiedFrom: Date.now(),
});
}
});
});
// // if (!docSnap.exists) {
// // docRef.set({
// // occupiedFrom,
// // currentDispatcherName: station.dispatcherName,
// // });
// // } else {
// // docRef.update({
// // occupiedFrom,
// // currentDispatcherName: station.dispatcherName,
// // });
// // }
// // previousOnlineStations.push({
// // dispatcherName: station.dispatcherName,
// // occupiedFrom,
// // stationName: station.stationName,
// // });
// // });
// // } else {
// // previousOnlineStations.forEach((prevStation) => {
// // const currStationData = stationAPIData.find(
// // (currStation) => currStation.stationName === prevStation.stationName
// // );
// // // Dispatcher left
// // if (!currStationData) {
// // }
// // // The same dispatcher is still online - do nothing
// // else if (prevStation.dispatcherName === currStationData.dispatcherName) {
// // }
// // // Dispatchers switched
// // else if (prevStation.dispatcherName !== currStationData.dispatcherName) {
// // }
// // });
// // stationAPIData.forEach((stationData) => {
// // const isPrevious = previousOnlineStations.find(
// // (prevStation) => prevStation.stationName === stationData.stationName
// // );
// // // New station turned online
// // if (!isPrevious) {
// // }
// // });
// // }
// // });
// // const scheduledUpdate = functions.pubsub
// // .schedule("0 * * * *")
// // .onRun(async (context) => {
// // let stationData: {
// // stationName: string;
// // dispatcherName: string;
// // isOnline: boolean;
// // region: string;
// // }[];
// // try {
// // stationData = await (
// // await axios.get(
// // "https://api.td2.info.pl:9640/?method=getStationsOnline"
// // )
// // ).data.message;
// // } catch (error) {
// // return;
// // }
// // const historyRef = db.collection("history");
// // stationData.forEach(async (station) => {
// // const docRef = historyRef.doc(station.stationName);
// // const docSnapshot = await docRef.get();
// // if (!docSnapshot.exists) {
// // docRef.set({
// // occupiedFrom: Date.now(),
// // currentDispatcherName: station.dispatcherName,
// // });
// // return;
// // }
// // });
// // const snapshot = await historyRef.get();
// // snapshot.forEach(async (doc) => {
// // const docData = doc.data();
// // const docRef = historyRef.doc(doc.id);
// // const APIStationData = stationData
// // .filter((station) => station.isOnline && station.region === "eu")
// // .find((station) => station.stationName == doc.id);
// // if (docData.currentDispatcherName != "") {
// // if (
// // !APIStationData ||
// // APIStationData.dispatcherName != docData.currentDispatcherName
// // ) {
// // docRef.update({
// // currentDispatcherName: !APIStationData
// // ? ""
// // : APIStationData.dispatcherName,
// // occupiedFrom: !APIStationData ? 0 : Date.now(),
// // });
// // docRef.collection("dispatcherHistory").add({
// // currentDispatcherName: docData.currentDispatcherName,
// // occupiedFrom: docData.occupiedFrom,
// // occupiedTo: Date.now(),
// // });
// // }
// // } else if (APIStationData) {
// // docRef.update({
// // currentDispatcherName: APIStationData.dispatcherName,
// // occupiedFrom: Date.now(),
// // });
// // }
// // });
// // });
File diff suppressed because it is too large Load Diff
+63 -57
View File
@@ -5,13 +5,17 @@
</div>
<div class="card-history">
<div class="history-title title">DZIENNIK STACJI</div>
<div class="history-title">
<span class="title">DZIENNIK STACJI</span>
|
<span>Usługa czasowo wstrzymana </span>
</div>
<ul class="history-list">
<div
<!-- <div
class="history-info"
>Wersja eksperymentalna! Dziennik aktualizuje się automatycznie co godzinę.</div>
<li class="history-log" v-for="(log, i) in computedHistory" :key="i">
>Wersja eksperymentalna! Dziennik aktualizuje się automatycznie co godzinę.</div>-->
<!-- <li class="history-log" v-for="(log, i) in computedHistory" :key="i">
<div class="log-time">
<div class="from">
<span>
@@ -47,7 +51,7 @@
</div>
<div class="log-dispatcher">{{log.dispatcher}}</div>
</li>
</li>-->
</ul>
</div>
@@ -57,7 +61,7 @@
<span
class="main-level flex"
v-if="stationInfo.reqLevel > -1"
>{{parseInt(stationInfo.reqLevel) < 2 ? "L" : stationInfo.reqLevel}}</span>
>{{ 2 > parseInt(stationInfo.reqLevel) ? "L" : stationInfo.reqLevel}}</span>
<span class="main-general">
<div class="main-name">
<a
@@ -202,54 +206,54 @@ export default class StationCard extends styleMixin {
: `${this.stationInfo.dispatcherExp}`;
}
toLocaleDate(timestamp: number) {
return new Date(timestamp).toLocaleDateString("pl-PL", {
hour: "2-digit",
minute: "2-digit",
});
}
// toLocaleDate(timestamp: number) {
// return new Date(timestamp).toLocaleDateString("pl-PL", {
// hour: "2-digit",
// minute: "2-digit",
// });
// }
get computedHistory() {
return this.history.sort((a, b) => {
if (a.occupiedFrom < b.occupiedFrom) return 1;
else return -1;
});
}
// get computedHistory() {
// return this.history.sort((a, b) => {
// if (a.occupiedFrom < b.occupiedFrom) return 1;
// else return -1;
// });
// }
async loadHistory() {
const historyRef = await db
.collection("history")
.doc(this.stationInfo.stationName)
.collection("dispatcherHistory")
.get();
// async loadHistory() {
// const historyRef = await db
// .collection("history")
// .doc(this.stationInfo.stationName)
// .collection("dispatcherHistory")
// .get();
this.history = historyRef.docs
.filter((doc) => doc.data().occupiedTo != 0)
.map((doc) => {
const occupiedFrom = doc.data().occupiedFrom;
const occupiedTo = doc.data().occupiedTo;
// this.history = historyRef.docs
// .filter((doc) => doc.data().occupiedTo != 0)
// .map((doc) => {
// const occupiedFrom = doc.data().occupiedFrom;
// const occupiedTo = doc.data().occupiedTo;
const sameDay =
new Date(occupiedFrom).getDate() == new Date(occupiedTo).getDate();
// const sameDay =
// new Date(occupiedFrom).getDate() == new Date(occupiedTo).getDate();
return {
occupiedFrom,
occupiedTo,
dispatcher:
doc.data().currentDispatcherName || doc.data().dispatcherName,
sameDay,
};
});
}
// return {
// occupiedFrom,
// occupiedTo,
// dispatcher:
// doc.data().currentDispatcherName || doc.data().dispatcherName,
// sameDay,
// };
// });
// }
@Watch("stationInfo")
async onStationChange(val: any, oldVal: any) {
this.loadHistory();
}
// @Watch("stationInfo")
// async onStationChange(val: any, oldVal: any) {
// this.loadHistory();
// }
created() {
this.loadHistory();
}
// created() {
// this.loadHistory();
// }
}
</script>
@@ -325,23 +329,25 @@ export default class StationCard extends styleMixin {
transition: min-height 150ms ease-in, min-width 150ms ease-in,
font-size 150ms ease-in;
&:hover {
min-height: 90%;
// &:hover {
// min-height: 90%;
& > .history-list {
opacity: 1;
max-height: 350px;
}
// & > .history-list {
// opacity: 1;
// max-height: 350px;
// }
& > .history-title {
font-size: 2em;
}
}
// & > .history-title {
// font-size: 2em;
// }
// }
}
.history {
&-title {
transition: font-size 150ms ease-in;
color: #999;
}
&-info {
+1741 -1741
View File
File diff suppressed because it is too large Load Diff