35 lines
957 B
Python
35 lines
957 B
Python
![]() |
import data
|
||
|
import polars as pl
|
||
|
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(), "values" : d.properties_growth().pl()['properties_count'].to_list()}
|
||
|
return options
|
||
|
|
||
|
@app.get("/properties/extractions/{id}")
|
||
|
def property_extractions(id: int):
|
||
|
return d.extractions_for(property_id = id).pl().to_dicts()
|
||
|
|
||
|
|
||
|
|