Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Valo-Plex9# File : moteur/plexmoteur/passe.py10# Description : Passe d'exploitation : socle, loyers, réentraînement11# hebdomadaire, parc.12# Module : moteur13# Repository : https://git.spboucher.ai/valo-plex14# Project Website : https://www.valo-plex.com15# Created : 2026-12-0116# Last Modified : 2026-12-0317#18# =============================================================================19# AUTHOR & PROFESSIONAL AFFILIATION20# =============================================================================21#22# Author : Simon-Pierre Boucher23# Position : Professor of Finance24# Institution : Université du Québec en Outaouais (UQO)25# Department : Département des sciences administratives26# Organization : SP Boucher27#28# Website : https://spboucher.ai29# Git : https://git.spboucher.ai30#31# =============================================================================32# OFFICIAL CONTACT DIRECTORY33# =============================================================================34#35# General : info@spboucher.ai36# Professional : contact@spboucher.ai37# Direct : simon@spboucher.ai38# Research : research@spboucher.ai39# Development : dev@spboucher.ai40# Support : support@spboucher.ai41# Security/Admin : admin@spboucher.ai42# Notifications : notifications@spboucher.ai43#44# Preferred Contact: contact@spboucher.ai45#46# =============================================================================47# COPYRIGHT & INTELLECTUAL PROPERTY48# =============================================================================49#50# Copyright (c) 202651# Simon-Pierre Boucher52#53# All rights reserved where applicable.54#55# This file is governed by the applicable project license,56# copyright notices, institutional agreements and relevant law.57#58# Unless expressly authorized by the applicable license or59# rights holder, copying, redistribution, sublicensing,60# publication and commercial exploitation are not permitted.61#62# Existing third-party rights and notices remain unaffected.63#64# =============================================================================65# CONFIDENTIALITY & SECURITY66# =============================================================================67#68# Classification : Public69# Distribution : Public repository; use is governed by the project license70# Security Contact : admin@spboucher.ai71#72# Access to this source does not independently grant permission73# to redistribute or disclose confidential materials.74#75# Do not embed credentials, private keys, access tokens,76# certificates or confidential personal information.77#78# =============================================================================79# LICENSE & MAINTENANCE80# =============================================================================81#82# License : None specified (no license file in this repository)83# Maintainer : Simon-Pierre Boucher84# Technical Contact: dev@spboucher.ai85#86# =============================================================================87# END OF SP BOUCHER SOURCE HEADER88# =============================================================================8990"""Passe d'exploitation : socle, loyers, réentraînement hebdomadaire des deux91marchés (résidentiel à revenus, commercial), parc.92Un échec laisse la base précédente en service (chaque étape écrit ses tables93dans une transaction)."""94from __future__ import annotations9596import json97import time98import traceback99100from . import config, socle, typologie101102CADENCE_JOURS = 7103104105def _a_reentrainer(con, marche: str) -> bool:106 try:107 r = con.execute("SELECT julianday('now') - julianday(cree) FROM modele WHERE actif = 1 AND marche = ?",108 (marche,)).fetchone()109 except Exception:110 return True111 return r is None or r[0] >= CADENCE_JOURS112113114def passe(verbose: bool = False, forcer: bool = False) -> int:115 from . import estimer, loyers, modele116 from .params import PARAMS117 t0 = time.time()118 etapes = {}119 try:120 etapes["socle"] = socle.construire(verbose=False)121 etapes["loyers"] = loyers.entrainer()122 for marche, cle in ((typologie.RESIDENTIEL, "modele"), (typologie.COMMERCIAL, "modele_commercial")):123 if marche not in typologie.marches_actifs():124 continue125 con = config.ouvrir()126 refaire = forcer or _a_reentrainer(con, marche)127 con.close()128 if refaire:129 etapes[cle] = modele.entrainer(marche=marche)["bilan"]130 etapes["estimation"] = estimer.estimer()131 con = config.ouvrir(ecriture=True)132 with config.transaction(con):133 socle.noter(con, "parametres", PARAMS)134 socle.noter(con, "passe", {"ok": True, "secondes": round(time.time() - t0, 1), "etapes": list(etapes)})135 con.close()136 except Exception as e:137 traceback.print_exc()138 try:139 con = config.ouvrir(ecriture=True)140 with config.transaction(con):141 socle.noter(con, "passe", {"ok": False, "erreur": str(e)[:500]})142 con.close()143 except Exception:144 pass145 return 1146 if verbose:147 print(json.dumps(etapes, ensure_ascii=False, indent=1, default=str))148 return 0149