Further dashboard development.
This commit is contained in:
1 parent
1574edea88
commit
a8543d619f
10 files changed
+209
-312
No files matched your search
+9
-2
@@ -23,12 +23,19 @@ def properties_region():
|
||||
|
||||
@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()}
|
||||
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/extractions/{id}")
|
||||
@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}/base")
|
||||
def property_base_data(id: int):
|
||||
return d.property_base_data(id).pl().to_dicts()
|
||||
|
||||
|
||||
+114
-7
@@ -46,13 +46,93 @@ class Database:
|
||||
|
||||
def properties_growth(self):
|
||||
return self.connection.sql("""
|
||||
WITH PropertiesALL AS (
|
||||
SELECT
|
||||
strftime(created_at, '%Y-%m-%d') AS date,
|
||||
COUNT(*) as properties_count,
|
||||
SUM(properties_count) OVER (ORDER BY date) AS total
|
||||
FROM
|
||||
consultancy_d.properties p
|
||||
GROUP BY
|
||||
date
|
||||
ORDER BY
|
||||
date
|
||||
),
|
||||
PropertiesR1 AS (
|
||||
SELECT
|
||||
strftime(created_at, '%Y-%m-%d') AS date,
|
||||
COUNT(*) as properties_count,
|
||||
SUM(properties_count) OVER (ORDER BY date) AS total
|
||||
FROM
|
||||
consultancy_d.properties p
|
||||
WHERE
|
||||
p.seed_id = 1
|
||||
GROUP BY
|
||||
date
|
||||
ORDER BY
|
||||
date
|
||||
),
|
||||
PropertiesR2 AS (
|
||||
SELECT
|
||||
strftime(created_at, '%Y-%m-%d') AS date,
|
||||
COUNT(*) as properties_count,
|
||||
SUM(properties_count) OVER (ORDER BY date) AS total
|
||||
FROM
|
||||
consultancy_d.properties p
|
||||
WHERE
|
||||
p.seed_id = 2
|
||||
GROUP BY
|
||||
date
|
||||
ORDER BY
|
||||
date
|
||||
),
|
||||
PropertiesR3 AS (
|
||||
SELECT
|
||||
strftime(created_at, '%Y-%m-%d') AS date,
|
||||
COUNT(*) as properties_count,
|
||||
SUM(properties_count) OVER (ORDER BY date) AS total
|
||||
FROM
|
||||
consultancy_d.properties p
|
||||
WHERE
|
||||
p.seed_id = 3
|
||||
GROUP BY
|
||||
date
|
||||
ORDER BY
|
||||
date
|
||||
),
|
||||
PropertiesR4 AS (
|
||||
SELECT
|
||||
strftime(created_at, '%Y-%m-%d') AS date,
|
||||
COUNT(*) as properties_count,
|
||||
SUM(properties_count) OVER (ORDER BY date) AS total
|
||||
FROM
|
||||
consultancy_d.properties p
|
||||
WHERE
|
||||
p.seed_id = 4
|
||||
GROUP BY
|
||||
date
|
||||
ORDER BY
|
||||
date
|
||||
)
|
||||
SELECT
|
||||
strftime(created_at, '%Y-%m-%d') AS date,
|
||||
COUNT(*) as properties_count
|
||||
p.date,
|
||||
p.total AS total_all,
|
||||
pR1.total as total_heidiland,
|
||||
pR2.total AS total_davos,
|
||||
pR3.total AS total_engadin,
|
||||
pR4.total AS total_stmoritz
|
||||
FROM
|
||||
consultancy_d.properties
|
||||
GROUP BY
|
||||
date;
|
||||
PropertiesAll p
|
||||
LEFT JOIN
|
||||
PropertiesR1 pR1 ON p.date = pR1.date
|
||||
LEFT JOIN
|
||||
PropertiesR2 pR2 ON p.date = pR2.date
|
||||
LEFT JOIN
|
||||
PropertiesR3 pR3 ON p.date = pR3.date
|
||||
LEFT JOIN
|
||||
PropertiesR4 pR4 ON p.date = pR4.date
|
||||
ORDER BY
|
||||
p.date
|
||||
""")
|
||||
|
||||
def properties_per_region(self):
|
||||
@@ -233,9 +313,10 @@ class Database:
|
||||
consultancy_d.extractions
|
||||
WHERE
|
||||
type == 'calendar' AND
|
||||
property_id = {property_id}
|
||||
property_id = {property_id} AND
|
||||
calendar NOT NULL
|
||||
ORDER BY
|
||||
property_id
|
||||
created_at
|
||||
""")
|
||||
|
||||
# Anzahl der extrahierten properties pro Exktraktionsvorgang
|
||||
@@ -281,3 +362,29 @@ class Database:
|
||||
ORDER BY property_id
|
||||
""")
|
||||
|
||||
def property_base_data(self, id):
|
||||
return self.connection.sql(f"""
|
||||
SELECT
|
||||
p.property_platform_id,
|
||||
p.created_at as first_found,
|
||||
p.last_found,
|
||||
r.name as region_name
|
||||
FROM
|
||||
consultancy_d.properties p
|
||||
INNER JOIN consultancy_d.seeds s ON s.id = p.seed_id
|
||||
INNER JOIN consultancy_d.regions r ON s.region_id = r.id
|
||||
WHERE
|
||||
p.id = {id}
|
||||
""")
|
||||
|
||||
def properties_geo(self):
|
||||
return self.connection.sql("""
|
||||
SELECT
|
||||
p.id,
|
||||
p.check_data as coordinates
|
||||
FROM
|
||||
consultancy_d.properties p
|
||||
""")
|
||||
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
import data
|
||||
import polars as pl
|
||||
|
||||
inst = data.load()
|
||||
|
||||
"""
|
||||
test = inst.extractions_for(1).pl()
|
||||
|
||||
out = test.with_columns(
|
||||
pl.col("calendar").str.extract_all(r"([0-9]{4}-[0-9]{2}-[0-9]{2})|[0-2]").alias("extracted_cal"),
|
||||
)
|
||||
out = out.drop(['calendar', 'property_id'])
|
||||
|
||||
print(out.to_dict(as_series=True))
|
||||
"""
|
||||
|
||||
print(inst.price_developement_per_property().pl())
|
||||
Reference in new issue
Block a user