From 47a5035787adf8944b1623af04ea64ecdb7c495b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gi=C3=B2=20Diani?= Date: Thu, 19 Dec 2024 19:22:09 +0100 Subject: [PATCH] dashboard einzelansicht trend auslastung. --- README.md | 3 +- dashboard/app/Api.php | 5 + dashboard/resources/views/property.blade.php | 99 ++++++++++++++++++-- dashboard/routes/web.php | 4 +- etl/pixi.lock | 2 +- etl/src/api/main.py | 6 ++ etl/src/data/etl_property_capacities.py | 40 ++++++++ 7 files changed, 148 insertions(+), 11 deletions(-) create mode 100644 etl/src/data/etl_property_capacities.py diff --git a/README.md b/README.md index 19b2cef..26a3b92 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,5 @@ ## Projektstruktur - etl: Enthält den Programmcode, welcher die Daten aufbereitet und via REST-API zur Verfügung stellt. -- dashboard: Webapplikation zur Exploration und Visualisierung der Daten. \ No newline at end of file +- dashboard: Webapplikation zur Exploration und Visualisierung der Daten. + diff --git a/dashboard/app/Api.php b/dashboard/app/Api.php index 0647af0..3b41e45 100644 --- a/dashboard/app/Api.php +++ b/dashboard/app/Api.php @@ -45,6 +45,11 @@ class Api return self::get("/property/{$id}/extractions"); } + public static function propertyCapacities(int $id) + { + return self::get("/property/{$id}/capacities"); + } + public static function propertyBase(int $id): mixed { return self::get("/property/{$id}/base"); diff --git a/dashboard/resources/views/property.blade.php b/dashboard/resources/views/property.blade.php index 2822bcb..46109a2 100644 --- a/dashboard/resources/views/property.blade.php +++ b/dashboard/resources/views/property.blade.php @@ -21,7 +21,7 @@ @endforeach -
+

Belegung am {{ json_decode($extractiondates)[0] }} @@ -29,7 +29,52 @@

+
+
+

+ Entwicklung der Verfügbarkeit +

+
+
+
@endsection diff --git a/dashboard/routes/web.php b/dashboard/routes/web.php index b390891..86c25c7 100644 --- a/dashboard/routes/web.php +++ b/dashboard/routes/web.php @@ -17,7 +17,6 @@ Route::get('/', function () { } $propertiesGeo = Api::propertiesGeo(); - //dump($propertiesGeo); return view('overview', ["geo" => $propertiesGeo, "growth" => $propertiesGrowth, "propsPerRegion" => [json_encode($propsPerRegionName), json_encode($propsPerRegionCounts)]]); }); @@ -26,6 +25,7 @@ Route::get('/prop/{id}', function (int $id) { $propertyBase = Api::propertyBase($id); $extractions = Api::propertyExtractions($id); + $propertyCapacities = Api::propertyCapacities($id); $data = []; $dates = []; @@ -46,5 +46,5 @@ Route::get('/prop/{id}', function (int $id) { } - return view('property', ['base' => $propertyBase[0], "extractiondates" => json_encode($dates), "calendar" => $data]); + return view('property', ['base' => $propertyBase[0], "extractiondates" => json_encode($dates), "calendar" => $data, 'capacities' => $propertyCapacities]); }); diff --git a/etl/pixi.lock b/etl/pixi.lock index f78ba19..88af371 100644 --- a/etl/pixi.lock +++ b/etl/pixi.lock @@ -2200,7 +2200,7 @@ packages: name: consultancy-2 version: 0.1.0 path: . - sha256: 878bb6af1502cc9ac71feab6f184f593077f134626d6f8c552e9bcafb178f6b4 + sha256: c09f63486f0dd4151008de68ef73d00f72663dc3cc47894ff750d517f898a23b requires_python: '>=3.11' editable: true - kind: conda diff --git a/etl/src/api/main.py b/etl/src/api/main.py index ccdc484..cc68ed8 100644 --- a/etl/src/api/main.py +++ b/etl/src/api/main.py @@ -1,5 +1,6 @@ import data import polars as pl +from data import etl_property_capacities as etl_pc from fastapi import FastAPI, Response d = data.load() @@ -34,6 +35,11 @@ def properties_geo(): def property_extractions(id: int): return d.extractions_for(property_id = id).pl().to_dicts() +@app.get("/property/{id}/capacities") +def property_capacities_data(id: int): + capacities = etl_pc.property_capacities(id) + return capacities + @app.get("/property/{id}/base") def property_base_data(id: int): return d.property_base_data(id).pl().to_dicts() diff --git a/etl/src/data/etl_property_capacities.py b/etl/src/data/etl_property_capacities.py new file mode 100644 index 0000000..f3bab08 --- /dev/null +++ b/etl/src/data/etl_property_capacities.py @@ -0,0 +1,40 @@ +from io import StringIO + +import polars as pl + +import data + +d = data.load() + +def property_capacities(id: int): + + extractions = d.extractions_for(id).pl() + df_dates = pl.DataFrame() + + for row in extractions.rows(named=True): + df_calendar = pl.read_json(StringIO(row['calendar'])) + #df_calendar.insert_column(0, pl.Series("created_at", [row['created_at']])) + df_dates = pl.concat([df_calendar, df_dates], how="diagonal") + + # order = sorted(df_dates.columns) + # df_dates = df_dates.select(order) + sum_hor = df_dates.sum_horizontal() + #print(sum_hor) + # Get the available dates per extraction + count_days = [] + for dates in df_dates.rows(): + # Remove all None values + liste = [x for x in dates if x is not None] + count_days.append(len(liste)) + + print(sum_hor) + counts = pl.DataFrame({"count_days" : count_days, "sum" : sum_hor}) + result = {"capacities": [], "dates": extractions['created_at'].cast(pl.Datetime).to_list() } + + for row in counts.rows(named=True): + max_capacity = row['count_days'] * 2 + max_capacity_perc = 100 / max_capacity + result['capacities'].append(round(max_capacity_perc * row['sum'], 2)) + result['capacities'].reverse() + return result +