dashboard einzelansicht trend auslastung.
This commit is contained in:
1 parent
4b7067fb63
commit
47a5035787
7 files changed
+148
-11
No files matched your search
Generated
+1
-1
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user