| 232 |
232 |
return {"sources": registry} |
| 233 |
233 |
|
| 234 |
234 |
|
|
235 |
+# Villes de la grande région de Montréal (le reste de la province est |
|
236 |
+# compté dans « autres » — Outaouais, Estrie, Mauricie, Est-du-Québec…) |
|
237 |
+_VILLES_GM = ( |
|
238 |
+ "Montréal", "Montréal-Est", "Laval", "Longueuil", "Brossard", "Terrebonne", |
|
239 |
+ "Mascouche", "Repentigny", "Boucherville", "Saint-Lambert", "Westmount", |
|
240 |
+ "Côte Saint-Luc", "Dorval", "Pointe-Claire", "Verdun", "LaSalle", "Anjou", |
|
241 |
+ "Saint-Constant", "Delson", "Candiac", "Châteauguay", "Chambly", |
|
242 |
+ "Sainte-Julie", "Varennes", "Belœil", "McMasterville", "Mont-Saint-Hilaire", |
|
243 |
+ "Saint-Basile-le-Grand", "Saint-Bruno-de-Montarville", "Boisbriand", |
|
244 |
+ "Richelieu", "Beauharnois", "Salaberry-de-Valleyfield", "Vaudreuil-Dorion", |
|
245 |
+ "Kirkland", "Beaconsfield", "Dollard-des-Ormeaux", "Mont-Royal", "Outremont", |
|
246 |
+) |
|
247 |
+ |
|
248 |
+ |
| 235 |
249 |
@app.get("/api/stats") |
| 236 |
250 |
def stats(): |
| 237 |
251 |
con = db.connect() |
|
252 |
+ gm = ",".join("?" * len(_VILLES_GM)) |
| 238 |
253 |
row = con.execute( |
| 239 |
|
− """SELECT COUNT(*) total, |
|
254 |
+ f"""SELECT COUNT(*) total, |
| 240 |
255 |
SUM(CASE WHEN city='Québec' THEN 1 ELSE 0 END) quebec, |
| 241 |
256 |
SUM(CASE WHEN city='Lévis' THEN 1 ELSE 0 END) levis, |
| 242 |
|
− SUM(CASE WHEN city NOT IN ('Québec','Lévis') THEN 1 ELSE 0 END) montreal, |
|
257 |
+ SUM(CASE WHEN city IN ({gm}) THEN 1 ELSE 0 END) montreal, |
|
258 |
+ SUM(CASE WHEN city NOT IN ('Québec','Lévis') AND city NOT IN ({gm}) |
|
259 |
+ THEN 1 ELSE 0 END) autres, |
| 243 |
260 |
COUNT(DISTINCT source) sources, |
| 244 |
261 |
AVG(price) avg_price |
| 245 |
|
− FROM listings WHERE active=1""").fetchone() |
|
262 |
+ FROM listings WHERE active=1""", |
|
263 |
+ list(_VILLES_GM) + list(_VILLES_GM)).fetchone() |
| 246 |
264 |
log = [dict(r) for r in con.execute( |
| 247 |
265 |
"SELECT * FROM sync_log ORDER BY ts DESC LIMIT 20")] |
| 248 |
266 |
con.close() |
| 249 |
267 |
|