From b10b135b3949ab3d25509d75e25bf9a752b012f4 Mon Sep 17 00:00:00 2001 From: "Maurice L." Date: Wed, 7 May 2025 16:14:06 +0200 Subject: [PATCH] Finished entire frontend --- api-backend/src/index.ts | 18 +++++ src/components/Footer.vue | 18 ----- src/components/app/AppSidebar.vue | 118 ------------------------------ src/components/app/Entry.vue | 35 --------- src/components/app/ListItem.vue | 26 ------- src/views/Home.vue | 93 ++++++++++++++--------- src/views/Stats.vue | 50 ++++++++----- src/views/app/App.vue | 13 ---- src/views/app/Documentation.vue | 9 --- src/views/app/Help.vue | 9 --- 10 files changed, 110 insertions(+), 279 deletions(-) delete mode 100644 src/components/app/Entry.vue delete mode 100644 src/components/app/ListItem.vue diff --git a/api-backend/src/index.ts b/api-backend/src/index.ts index ab052a5..5243c9c 100644 --- a/api-backend/src/index.ts +++ b/api-backend/src/index.ts @@ -2,6 +2,8 @@ import express from 'express'; import cors from 'cors'; import pathRoutes from './routes/parkRoutes.js'; import coasterRoutes from './routes/coasterRoutes.js'; +import fs from 'fs'; +import path from 'path'; const app = express(); const port = 3000; @@ -15,6 +17,22 @@ app.use(cors()); app.use('/api/parks', pathRoutes); app.use('/api/coasters', coasterRoutes); +app.get('/api/filesize', (req, res) => { + const dbPath = path.join('./database.db'); + + fs.stat(dbPath, (err, stats) => { + if (err) { + console.error('Fehler beim Abrufen der Dateigröße:', err); + return res.status(500).json({ error: 'Dateigröße konnte nicht ermittelt werden' }); + } + + res.json({ + sizeBytes: stats.size, + sizeMB: (stats.size / (1024 * 1024)).toFixed(2) + }); + }); +}); + // Start des Servers app.listen(port, () => { console.log(`Server läuft auf http://localhost:${port}`); diff --git a/src/components/Footer.vue b/src/components/Footer.vue index abe4888..23b15ac 100644 --- a/src/components/Footer.vue +++ b/src/components/Footer.vue @@ -45,26 +45,8 @@ export default {
  • GitHub
  • - -
    diff --git a/src/components/app/AppSidebar.vue b/src/components/app/AppSidebar.vue index f9f02e3..88d556c 100644 --- a/src/components/app/AppSidebar.vue +++ b/src/components/app/AppSidebar.vue @@ -238,79 +238,8 @@ export default { >Technische Infos - - - \ No newline at end of file diff --git a/src/components/app/Entry.vue b/src/components/app/Entry.vue deleted file mode 100644 index 71b29db..0000000 --- a/src/components/app/Entry.vue +++ /dev/null @@ -1,35 +0,0 @@ - - - \ No newline at end of file diff --git a/src/components/app/ListItem.vue b/src/components/app/ListItem.vue deleted file mode 100644 index a82b8dd..0000000 --- a/src/components/app/ListItem.vue +++ /dev/null @@ -1,26 +0,0 @@ - - - \ No newline at end of file diff --git a/src/views/Home.vue b/src/views/Home.vue index a78ac66..118ba14 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -1,5 +1,4 @@ @@ -14,38 +37,40 @@ export default { \ No newline at end of file + diff --git a/src/views/Stats.vue b/src/views/Stats.vue index b6ef623..2bd77c8 100644 --- a/src/views/Stats.vue +++ b/src/views/Stats.vue @@ -12,30 +12,42 @@ export default { stats: { totalParks: 0, totalCoasters: 0, - totalVisitorsPerMonth: 500000, // bleibt statisch, da nicht aus API - averageTicketPrice: 45.99, // bleibt statisch, da nicht aus API - totalInversions: 0 + totalVisitorsPerMonth: 0, + averageTicketPrice: 0, + totalInversions: 0, + databaseSize: 0 } }; }, async mounted() { - try { - // Parks abrufen - const parksRes = await fetch('http://localhost:3000/api/parks'); - const parks = await parksRes.json(); - this.stats.totalParks = parks.length; + try { + const parksRes = await fetch('http://localhost:3000/api/parks'); + const parks = await parksRes.json(); + this.stats.totalParks = parks.length; - // Coaster abrufen - const coastersRes = await fetch('http://localhost:3000/api/coasters'); - const coasters = await coastersRes.json(); - this.stats.totalCoasters = coasters.length; + const totalVisitors = parks.reduce((sum: number, park: any) => sum + Number(park.average_visitor_count), 0); + this.stats.totalVisitorsPerMonth = Math.round(totalVisitors / parks.length); - // Summe der Inversionen berechnen - this.stats.totalInversions = coasters.reduce((sum: number, coaster: any) => sum + coaster.inversions, 0); - } catch (err) { - console.error('Fehler beim Laden der Statistiken:', err); - } + const totalPrice = parks.reduce((sum: number, park: any) => { + const price = parseFloat(park.ticket_price.replace('€', '').replace(',', '.')); + return sum + price; + }, 0); + this.stats.averageTicketPrice = parseFloat((totalPrice / parks.length).toFixed(2)); + + const coastersRes = await fetch('http://localhost:3000/api/coasters'); + const coasters = await coastersRes.json(); + this.stats.totalCoasters = coasters.length; + this.stats.totalInversions = coasters.reduce((sum: number, coaster: any) => sum + coaster.inversions, 0); + + const sizeRes = await fetch('http://localhost:3000/api/filesize'); + const size = await sizeRes.json(); + this.stats.databaseSize = size.sizeMB; + + } catch (err) { + console.error('Fehler beim Laden der Statistiken:', err); } +} + }; @@ -76,6 +88,10 @@ export default {

    Anzahl der Inversionen:

    {{ stats.totalInversions }}

    +
    +

    Größe der Datenbank:

    +

    {{ stats.databaseSize }} MB

    +
    diff --git a/src/views/app/App.vue b/src/views/app/App.vue index 9e91793..2ea88de 100644 --- a/src/views/app/App.vue +++ b/src/views/app/App.vue @@ -1,18 +1,7 @@