54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
import data
|
|
import polars as pl
|
|
from data import etl_property_capacities as etl_pc
|
|
from fastapi import FastAPI, Response
|
|
|
|
d = data.load()
|
|
|
|
app = FastAPI()
|
|
|
|
@app.get("/")
|
|
def read_root():
|
|
return {"Hi there!"}
|
|
|
|
@app.get("/items/{item_id}")
|
|
def read_item(item_id: int):
|
|
ext = d.extractions_for(item_id).pl()
|
|
out = ext.with_columns(pl.col("calendar").str.extract_all(r"([0-9]{4}-[0-9]{2}-[0-9]{2})|[0-2]").alias("calendar_data"))
|
|
out = out.drop(['calendar', 'property_id'])
|
|
return Response(content=out.write_json(), media_type="application/json")
|
|
|
|
@app.get("/region/properties")
|
|
def properties_region():
|
|
return d.properties_per_region().pl().to_dicts()
|
|
|
|
@app.get("/properties/growth")
|
|
def properties_growth():
|
|
options = {"dates" : d.properties_growth().pl()['date'].to_list(), "total_all" : d.properties_growth().pl()['total_all'].to_list(), "total_heidiland" : d.properties_growth().pl()['total_heidiland'].to_list(), "total_engadin" : d.properties_growth().pl()['total_engadin'].to_list(), "total_davos" : d.properties_growth().pl()['total_davos'].to_list(), "total_stmoritz" : d.properties_growth().pl()['total_stmoritz'].to_list()}
|
|
return options
|
|
|
|
@app.get("/properties/geo")
|
|
def properties_geo():
|
|
return d.properties_geo().pl().to_dicts()
|
|
|
|
@app.get("/property/{id}/extractions")
|
|
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()
|
|
|
|
@app.get("/region/{id}/capacities")
|
|
def region_capacities_data(id: int):
|
|
capacities = etl_pc.region_capacities(id)
|
|
return capacities
|
|
|
|
|
|
|