Add Stats

This commit is contained in:
Fred Boniface 2023-06-28 14:08:37 +01:00
parent 166ca1fe5f
commit 1d138b629d

View File

@ -1,47 +1,88 @@
<script> <script>
import Header from '$lib/navigation/header.svelte' import Island from '$lib/islands/island.svelte';
import Header from '$lib/navigation/header.svelte'
import Loading from '$lib/navigation/loading.svelte'; import Loading from '$lib/navigation/loading.svelte';
import Nav from '$lib/navigation/nav.svelte' import Nav from '$lib/navigation/nav.svelte'
import { onMount } from 'svelte';
const title = "Statistics" const title = "Statistics"
let isLoading = true; let isLoading = true;
let update_timetable = "", update_corpus="", let data, error;
update_pis = "", count_ldbws_api="",
count_ldbsvws_api = "", count_corpus_api = "", onMount(async () => {
count_timetable_db = "", count_pis_db = "", const url = "https://owlboard.info/misc/server/stats"
count_corpus_db = "", count_stations_db = "", const res = await fetch(url);
length_users = "", length_registrations = "", if (res.status == 200) {
length_stations = "", length_corpus = "", data = await res.json();
length_pis = "", length_timetable = "" } else {
error = true;
}
isLoading = false;
})
function U2L(input) {
try {
const datetime = new Date(input*1000)
return datetime.toLocaleString()
} catch (err) {
console.log(err);
return false;
}
}
</script> </script>
<Header {title} /> <Header {title} />
{#if isLoading} {#if error}
<Loading /> <Island>
{:else} <p>Unable to connect to server</p>
<h2>Last Update</h2> </Island>
<p>Timetable Data: <span>{update_timetable}</span></p>
<p>Location Reference Data: <span>{update_corpus}</span></p>
<p>PIS Codes Data: <span>{update_pis}</span></p>
<h2>Request Counts</h2>
<p>LDBWS API: <span>{count_ldbws_api}</span></p>
<p>LDBSVWS API: <span>{count_ldbsvws_api}</span></p>
<p>Location Reference API: <span>{count_corpus_api}</span></p>
<p>Timetable: <span>{count_timetable_db}</span></p>
<p>PIS: <span>{count_pis_db}</span></p>
<p>Location Reference: <span>{count_corpus_db}</span></p>
<p>Stations: <span>{count_stations_db}</span></p>
<h2>Database Lengths</h2>
<p>Users: <span>{length_users}</span></p>
<p>Pending Registrations: <span>{length_registrations}</span></p>
<p>CORPUS: <span>{length_corpus}</span></p>
<p>Stations: <span>{length_stations}</span></p>
<p>PIS: <span>{length_pis}</span></p>
<p>Timetable: <span>{length_timetable}</span></p>
{/if} {/if}
<Nav /> {#if isLoading}
<Loading />
{:else if !isLoading && !error}
<p>API Server:<br><span>{data?.hostname}</span></p>
<p>Runtime Mode: <span>{data?.runtimeMode}</span></p>
<p>Stats Reset: <span>{U2L(data?.reset) || 'Unknown'}</span></p>
<h2>Last Update</h2>
<p>Timetable: <span>{U2L(data?.updateTimes?.timetable)}</span></p>
<p>Location Ref: <span>{U2L(data?.updateTimes?.corpus)}</span></p>
<p>PIS Codes: <span>{U2L(data?.updateTimes?.pis)}</span></p>
<p>Reason Codes: <span>{U2L(data?.updateTimes?.reasonCodes)}</span></p>
<h2>Request Counts</h2>
<p>LDBWS API: <span>{data?.requestCounts?.ldbws_api}</span></p>
<p>LDBSVWS API: <span>{data?.requestCounts?.lsbsvws_api}</span></p>
<p>Location Reference API: <span>{data?.requestCounts?.corpus_api}</span></p>
<p>Timetable: <span>{data?.requestCounts?.timetable_db}</span></p>
<p>PIS: <span>{data?.requestCounts?.pis_db}</span></p>
<p>Location Reference: <span>{data?.requestCounts?.corpus_db}</span></p>
<p>Stations: <span>{data?.requestCounts?.stations_db}</span></p>
<h2>Database Lengths</h2>
<p>Users: <span>{data?.dbLengths?.users}</span></p>
<p>Pending Registrations: <span>{data?.dbLengths?.registrations}</span></p>
<p>CORPUS: <span>{data?.dbLengths?.corpus}</span></p>
<p>Stations: <span>{data?.dbLengths?.stations}</span></p>
<p>PIS: <span>{data?.dbLengths?.pis}</span></p>
<p>Timetable: <span>{data?.dbLengths?.timetable}</span></p>
<p>Reason Codes: <span>{data?.dbLengths?.reasonCodes}</span></p>
{/if}
<Nav />
<style>
span {
color: white;
}
p {
margin: 0;
color: lightgray;
}
h2 {
margin-bottom: 2px;
margin-top: 8px;
}
</style>