Wiederinstandsetzung Heatmap @stoffelmauro musste dazu etwas in der API anpassen.
This commit is contained in:
1 parent
67382003ca
commit
2013d2b440
4 files changed
+28
-28
No files matched your search
@@ -1,8 +1,8 @@
|
||||
import data
|
||||
import polars as pl
|
||||
from io import StringIO
|
||||
import numpy as np
|
||||
|
||||
import polars as pl
|
||||
|
||||
import data
|
||||
|
||||
d = data.load()
|
||||
|
||||
@@ -26,10 +26,9 @@ def region_properties_capacities(id: int):
|
||||
# Merge Dataframe to generate indices
|
||||
df = df.join(datesDF, on='ScrapeDate')
|
||||
df = df.join(propIdDF, on='property_id')
|
||||
# Drop now useless columns ScrapeDate and property_id
|
||||
df = df[['ScrapeDate', 'calendarBody', 'date_index', 'prop_index']]
|
||||
|
||||
# Calculate grid values
|
||||
gridData = []
|
||||
gridData = pl.DataFrame(schema=[("scrape_date", pl.String), ("property_id", pl.String), ("sum_hor", pl.Int64)])
|
||||
for row in df.rows(named=True):
|
||||
# Return 0 for sum if calendar is null
|
||||
if row['calendarBody']:
|
||||
@@ -37,25 +36,22 @@ def region_properties_capacities(id: int):
|
||||
sum_hor = calDF.sum_horizontal()[0]
|
||||
else:
|
||||
sum_hor = 0
|
||||
# With Index
|
||||
# gridData.append([row['prop_index'], row['date_index'], sum_hor])
|
||||
# With ScrapeDate
|
||||
gridData.append([row['ScrapeDate'], row['date_index'], sum_hor])
|
||||
|
||||
gridData = np.array(gridData)
|
||||
# get all values to calculate Max
|
||||
allValues = gridData[:, 2].astype(int)
|
||||
maxValue = np.max(allValues)
|
||||
gridData[:, 2] = (allValues*100)/maxValue
|
||||
gridData = gridData.vstack(pl.DataFrame({"scrape_date" : row['ScrapeDate'], "property_id": str(row['property_id']), "sum_hor": sum_hor}))
|
||||
|
||||
# Return back to list
|
||||
gridData = gridData.tolist()
|
||||
# get the overall maximum sum
|
||||
maxValue = gridData['sum_hor'].max()
|
||||
values = []
|
||||
|
||||
for row in gridData.rows(named=True):
|
||||
capacity = (row['sum_hor']*100)/maxValue
|
||||
values.append((row['scrape_date'], row['property_id'], capacity))
|
||||
|
||||
# Cast listOfDates to datetime
|
||||
listOfDates = listOfDates.cast(pl.Date).to_list()
|
||||
listOfPropertyIDs = listOfPropertyIDs.to_list()
|
||||
listOfPropertyIDs = listOfPropertyIDs.cast(pl.String).to_list()
|
||||
|
||||
# Create JSON
|
||||
outDict = {'scrapeDates': listOfDates, 'property_ids': listOfPropertyIDs, 'values': gridData}
|
||||
outDict = {'scrapeDates': listOfDates, 'property_ids': listOfPropertyIDs, 'values': values}
|
||||
|
||||
return outDict
|
||||
Reference in new issue
Block a user