SPB Git

Repository Public

typologie.py 10.5 KB 244 lines python

1# =============================================================================2#                  SP BOUCHER | SOFTWARE & RESEARCH3#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project          : Valo-Plex9# File             : moteur/plexmoteur/typologie.py10# Description      : Typologie des immeubles : du code CUBF du rôle à la catégorie.11# Module           : moteur12# Repository       : https://git.spboucher.ai/valo-plex13# Project Website  : https://www.valo-plex.com14# Created          : 2026-12-0315# Last Modified    : 2026-12-0316#17# =============================================================================18# AUTHOR & PROFESSIONAL AFFILIATION19# =============================================================================20#21# Author           : Simon-Pierre Boucher22# Position         : Professor of Finance23# Institution      : Université du Québec en Outaouais (UQO)24# Department       : Département des sciences administratives25# Organization     : SP Boucher26#27# Website          : https://spboucher.ai28# Git              : https://git.spboucher.ai29#30# =============================================================================31# OFFICIAL CONTACT DIRECTORY32# =============================================================================33#34# General          : info@spboucher.ai35# Professional     : contact@spboucher.ai36# Direct           : simon@spboucher.ai37# Research         : research@spboucher.ai38# Development      : dev@spboucher.ai39# Support          : support@spboucher.ai40# Security/Admin   : admin@spboucher.ai41# Notifications    : notifications@spboucher.ai42#43# Preferred Contact: contact@spboucher.ai44#45# =============================================================================46# COPYRIGHT & INTELLECTUAL PROPERTY47# =============================================================================48#49# Copyright (c) 202650# Simon-Pierre Boucher51#52# All rights reserved where applicable.53#54# This file is governed by the applicable project license,55# copyright notices, institutional agreements and relevant law.56#57# Unless expressly authorized by the applicable license or58# rights holder, copying, redistribution, sublicensing,59# publication and commercial exploitation are not permitted.60#61# Existing third-party rights and notices remain unaffected.62#63# =============================================================================64# CONFIDENTIALITY & SECURITY65# =============================================================================66#67# Classification   : Public68# Distribution     : Public repository; use is governed by the project license69# Security Contact : admin@spboucher.ai70#71# Access to this source does not independently grant permission72# to redistribute or disclose confidential materials.73#74# Do not embed credentials, private keys, access tokens,75# certificates or confidential personal information.76#77# =============================================================================78# LICENSE & MAINTENANCE79# =============================================================================80#81# License          : None specified (no license file in this repository)82# Maintainer       : Simon-Pierre Boucher83# Technical Contact: dev@spboucher.ai84#85# =============================================================================86# END OF SP BOUCHER SOURCE HEADER87# =============================================================================8889"""Typologie des immeubles : du code d'utilisation des biens-fonds du rôle90(CUBF) à la catégorie Valo-Plex.9192Deux marchés sont évalués à part, parce qu'ils ne se comparent pas :9394- ``residentiel`` : plex (2 à 5 logements) et multilogements (6 et plus), dont95  l'unité de comparaison est la porte ;96- ``commercial`` : habitations collectives, commerces, centres commerciaux,97  restaurants, hôtels, bureaux, immeubles industriels, entrepôts, loisirs,98  dont l'unité de comparaison est le mètre carré d'aire d'étages.99100Restent hors champ, parce que ce ne sont pas des immeubles de rapport : rues,101parcs, réseaux et services publics, écoles, lieux de culte, administrations,102fermes et forêts, terrains vacants, stationnements, camps et résidences de103tourisme (un chalet loué reste un chalet).104"""105from __future__ import annotations106107import os108109import numpy as np110111RESIDENTIEL, COMMERCIAL = "residentiel", "commercial"112MARCHES = (RESIDENTIEL, COMMERCIAL)113114115def marches_actifs() -> tuple[str, ...]:116    """Marchés évalués. Par défaut le résidentiel à revenus seul : le marché117    commercial est écrit et mesuré (``docs/MODELE_V2.md``), mais la source des118    ventes n'en contient pas assez pour le servir (décision du 2026-12-03).119    ``VX_MARCHES=residentiel,commercial`` le rallume."""120    voulus = [m.strip() for m in os.environ.get("VX_MARCHES", RESIDENTIEL).split(",")]121    return tuple(m for m in MARCHES if m in voulus) or (RESIDENTIEL,)122123124# (code, nom, marché, unité de comparaison)125CATEGORIES = (126    ("plex", "Plex (2 à 5 logements)", RESIDENTIEL, "porte"),127    ("multilogement", "Multilogement (6 logements et plus)", RESIDENTIEL, "porte"),128    ("habitation-collective", "Habitation collective", COMMERCIAL, "m2"),129    ("centre-commercial", "Centre commercial", COMMERCIAL, "m2"),130    ("commerce", "Commerce de détail", COMMERCIAL, "m2"),131    ("restauration", "Restaurant et bar", COMMERCIAL, "m2"),132    ("hebergement", "Hôtel et hébergement", COMMERCIAL, "m2"),133    ("automobile", "Automobile et station-service", COMMERCIAL, "m2"),134    ("bureau", "Bureaux et services professionnels", COMMERCIAL, "m2"),135    ("services", "Commerce de services", COMMERCIAL, "m2"),136    ("industriel", "Industriel", COMMERCIAL, "m2"),137    ("entrepot", "Entrepôt et distribution", COMMERCIAL, "m2"),138    ("loisirs", "Loisirs et divertissement", COMMERCIAL, "m2"),139)140NOMS = {c: n for c, n, _, _ in CATEGORIES}141MARCHE_DE = {c: m for c, _, m, _ in CATEGORIES}142COMMERCIALES = tuple(c for c, _, m, _ in CATEGORIES if m == COMMERCIAL)143144# Groupes de mesure et de réconciliation. Résidentiel : par taille (0 à 4) ; commercial : par catégorie.145GROUPES_RESIDENTIEL = ("duplex", "triplex", "4-5", "6-11", "12+")146N_RES = len(GROUPES_RESIDENTIEL)147GROUPES = GROUPES_RESIDENTIEL + COMMERCIALES148INDICE_COMMERCIAL = {c: N_RES + k for k, c in enumerate(COMMERCIALES)}149150151TRANCHES = ("duplex", "triplex", "4-5", "6-11", "12-23", "24-49", "50+")152ETAGES_TOUR = 5              # à partir de cinq étages : une tour (ascenseur, structure de béton le plus souvent)153154155def tranche(logements) -> np.ndarray:156    """Tranche de taille d'un immeuble résidentiel à revenus."""157    n = np.asarray(logements)158    return np.select([n <= 2, n == 3, n <= 5, n <= 11, n <= 23, n <= 49],159                     ["duplex", "triplex", "4-5", "6-11", "12-23", "24-49"], "50+")160161162def groupes_du_marche(marche: str) -> dict[int, str]:163    """Indice de groupe → nom, pour un marché."""164    if marche == RESIDENTIEL:165        return dict(enumerate(GROUPES_RESIDENTIEL))166    return {N_RES + k: c for k, c in enumerate(COMMERCIALES)}167168169def categorie_cubf(cubf: int | None) -> str | None:170    """Catégorie commerciale d'un code CUBF ; ``None`` : hors champ. Le code171    1000 (logement) n'est pas traité ici : le résidentiel se classe par le172    nombre de logements."""173    if cubf is None:174        return None175    c = int(cubf)176    if 1510 <= c <= 1519 or 1530 <= c <= 1549 or c == 1590 or 1600 <= c <= 1699:177        return "habitation-collective"        # maisons de chambres, résidences d'étudiants et d'aînés, hôtels résidentiels178    if 2000 <= c <= 3999:179        return "industriel"                   # industries manufacturières180    if c == 4221 or 4900 <= c <= 4999:181        return "entrepot"                     # entrepôt de transport, messagerie, déménagement182    if c == 4222:183        return "industriel"                   # garage d'entretien de camions184    if 4000 <= c <= 4999:185        return None                           # voies, réseaux, services publics186    if 5000 <= c <= 5005:187        return "centre-commercial"188    if c == 5020 or 5100 <= c <= 5199:189        return "entrepot"                     # entreposage, vente en gros190    if 5010 <= c <= 5099:191        return "commerce"192    if 5500 <= c <= 5599:193        return "automobile"                   # concessionnaires, stations-service194    if c == 5834:195        return None                           # résidence de tourisme : un logement, pas un immeuble commercial196    if 5830 <= c <= 5839:197        return "hebergement"198    if 5800 <= c <= 5899:199        return "restauration"200    if 5200 <= c <= 5999:201        return "commerce"202    if c == 6000 or 6100 <= c <= 6199 or 6360 <= c <= 6369:203        return "bureau"                       # immeubles à bureaux, finance, assurance, centres de recherche204    if c in (6242, 6243, 6312):205        return None                           # cimetière, mausolée, panneau d'affichage206    if 6370 <= c <= 6379:207        return "entrepot"208    if 6200 <= c <= 6399:209        return "services"210    if 6410 <= c <= 6419 or 6440 <= c <= 6449:211        return "automobile"                   # réparation de véhicules212    if 6400 <= c <= 6499:213        return "services"214    if c in (6513, 6516, 6542) or 6530 <= c <= 6539:215        return None                           # hôpital, convalescence, services sociaux216    if c in (6541, 6543):217        return "services"                     # garderies218    if 6500 <= c <= 6599:219        return "bureau"                       # cabinets médicaux et professionnels220    if 6600 <= c <= 6699:221        return "industriel"                   # entrepreneurs en construction : ateliers et garages222    if 6700 <= c <= 6999:223        return None                           # administrations, écoles, culte, associations224    if 7200 <= c <= 7399 or 7500 <= c <= 7599 or 7900 <= c <= 7999:225        return "loisirs"226    if 7400 <= c <= 7499:227        return None if 7420 <= c <= 7429 or c == 7431 else "loisirs"    # terrains de jeux et plages : publics228    return None229230231def table_cubf(codes) -> list[tuple[int, str]]:232    """(cubf, catégorie) des codes commerciaux retenus, pour une jointure SQL."""233    out = []234    for c in sorted({int(x) for x in codes if x is not None}):235        cat = categorie_cubf(c)236        if cat:237            out.append((c, cat))238    return out239240241def indice_commercial(categories) -> np.ndarray:242    """Indice de groupe des catégories commerciales (−1 : inconnue)."""243    return np.array([INDICE_COMMERCIAL.get(c, -1) for c in categories], dtype=np.int8)244
Files main
Menu

Theme