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 functions from "firebase-functions";
import * as admin from "firebase-admin"; // import * as admin from "firebase-admin";
admin.initializeApp(); // admin.initializeApp();
const db = admin.firestore(); // const db = admin.firestore();
import axios from "axios"; // import axios from "axios";
exports.scheduledUpdate = functions.pubsub // const stationJSONList: any[] = require("./stations.json");
.schedule("0 * * * *")
.onRun(async (context) => {
let stationData: {
stationName: string;
dispatcherName: string;
isOnline: boolean;
region: string;
}[];
try { // let stationAPIData: {
stationData = await ( // stationName: string;
await axios.get( // dispatcherName: string;
"https://api.td2.info.pl:9640/?method=getStationsOnline" // isOnline: boolean;
) // region: string;
).data.message; // }[];
} catch (error) {
return;
}
const historyRef = db.collection("history"); // let previousOnlineStations: {
// stationName: string;
// dispatcherName: string;
// occupiedFrom: number;
// }[] = [];
stationData.forEach(async (station) => { // // const test = functions.pubsub.schedule("0 * * * *").onRun(async (context) => {
const docRef = historyRef.doc(station.stationName); // // try {
const docSnapshot = await docRef.get(); // // stationAPIData = await (
// // await axios.get("https://api.td2.info.pl:9640/?method=getStationsOnline")
// // ).data.message;
// // } catch (error) {
// // return;
// // }
if (!docSnapshot.exists) { // // if (previousOnlineStations.length == 0) {
docRef.set({ // // const historyRef = db.collection("dispatcherHistory");
occupiedFrom: Date.now(),
currentDispatcherName: station.dispatcherName,
});
return;
}
});
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) => { // // if (!isOfficial) return;
const docData = doc.data();
const docRef = historyRef.doc(doc.id);
const APIStationData = stationData // // const docRef = historyRef.doc(station.stationName);
.filter((station) => station.isOnline && station.region === "eu") // // const docSnap = await docRef.get();
.find((station) => station.stationName == doc.id);
if (docData.currentDispatcherName != "") { // // const occupiedFrom = Date.now();
if (
!APIStationData ||
APIStationData.dispatcherName != docData.currentDispatcherName
) {
docRef.update({
currentDispatcherName: !APIStationData
? ""
: APIStationData.dispatcherName,
occupiedFrom: !APIStationData ? 0 : Date.now(),
});
docRef.collection("dispatcherHistory").add({ // // if (!docSnap.exists) {
currentDispatcherName: docData.currentDispatcherName, // // docRef.set({
occupiedFrom: docData.occupiedFrom, // // occupiedFrom,
occupiedTo: Date.now(), // // currentDispatcherName: station.dispatcherName,
}); // // });
} // // } else {
} else if (APIStationData) { // // docRef.update({
docRef.update({ // // occupiedFrom,
currentDispatcherName: APIStationData.dispatcherName, // // currentDispatcherName: station.dispatcherName,
occupiedFrom: Date.now(), // // });
}); // // }
}
}); // // 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>
<div class="card-history"> <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"> <ul class="history-list">
<div <!-- <div
class="history-info" class="history-info"
>Wersja eksperymentalna! Dziennik aktualizuje się automatycznie co godzinę.</div> >Wersja eksperymentalna! Dziennik aktualizuje się automatycznie co godzinę.</div>-->
<li class="history-log" v-for="(log, i) in computedHistory" :key="i"> <!-- <li class="history-log" v-for="(log, i) in computedHistory" :key="i">
<div class="log-time"> <div class="log-time">
<div class="from"> <div class="from">
<span> <span>
@@ -47,7 +51,7 @@
</div> </div>
<div class="log-dispatcher">{{log.dispatcher}}</div> <div class="log-dispatcher">{{log.dispatcher}}</div>
</li> </li>-->
</ul> </ul>
</div> </div>
@@ -57,7 +61,7 @@
<span <span
class="main-level flex" class="main-level flex"
v-if="stationInfo.reqLevel > -1" 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"> <span class="main-general">
<div class="main-name"> <div class="main-name">
<a <a
@@ -202,54 +206,54 @@ export default class StationCard extends styleMixin {
: `${this.stationInfo.dispatcherExp}`; : `${this.stationInfo.dispatcherExp}`;
} }
toLocaleDate(timestamp: number) { // toLocaleDate(timestamp: number) {
return new Date(timestamp).toLocaleDateString("pl-PL", { // return new Date(timestamp).toLocaleDateString("pl-PL", {
hour: "2-digit", // hour: "2-digit",
minute: "2-digit", // minute: "2-digit",
}); // });
} // }
get computedHistory() { // get computedHistory() {
return this.history.sort((a, b) => { // return this.history.sort((a, b) => {
if (a.occupiedFrom < b.occupiedFrom) return 1; // if (a.occupiedFrom < b.occupiedFrom) return 1;
else return -1; // else return -1;
}); // });
} // }
async loadHistory() { // async loadHistory() {
const historyRef = await db // const historyRef = await db
.collection("history") // .collection("history")
.doc(this.stationInfo.stationName) // .doc(this.stationInfo.stationName)
.collection("dispatcherHistory") // .collection("dispatcherHistory")
.get(); // .get();
this.history = historyRef.docs // this.history = historyRef.docs
.filter((doc) => doc.data().occupiedTo != 0) // .filter((doc) => doc.data().occupiedTo != 0)
.map((doc) => { // .map((doc) => {
const occupiedFrom = doc.data().occupiedFrom; // const occupiedFrom = doc.data().occupiedFrom;
const occupiedTo = doc.data().occupiedTo; // const occupiedTo = doc.data().occupiedTo;
const sameDay = // const sameDay =
new Date(occupiedFrom).getDate() == new Date(occupiedTo).getDate(); // new Date(occupiedFrom).getDate() == new Date(occupiedTo).getDate();
return { // return {
occupiedFrom, // occupiedFrom,
occupiedTo, // occupiedTo,
dispatcher: // dispatcher:
doc.data().currentDispatcherName || doc.data().dispatcherName, // doc.data().currentDispatcherName || doc.data().dispatcherName,
sameDay, // sameDay,
}; // };
}); // });
} // }
@Watch("stationInfo") // @Watch("stationInfo")
async onStationChange(val: any, oldVal: any) { // async onStationChange(val: any, oldVal: any) {
this.loadHistory(); // this.loadHistory();
} // }
created() { // created() {
this.loadHistory(); // this.loadHistory();
} // }
} }
</script> </script>
@@ -325,23 +329,25 @@ export default class StationCard extends styleMixin {
transition: min-height 150ms ease-in, min-width 150ms ease-in, transition: min-height 150ms ease-in, min-width 150ms ease-in,
font-size 150ms ease-in; font-size 150ms ease-in;
&:hover { // &:hover {
min-height: 90%; // min-height: 90%;
& > .history-list { // & > .history-list {
opacity: 1; // opacity: 1;
max-height: 350px; // max-height: 350px;
} // }
& > .history-title { // & > .history-title {
font-size: 2em; // font-size: 2em;
} // }
} // }
} }
.history { .history {
&-title { &-title {
transition: font-size 150ms ease-in; transition: font-size 150ms ease-in;
color: #999;
} }
&-info { &-info {
+1741 -1741
View File
File diff suppressed because it is too large Load Diff