Repository Public
1#!/usr/bin/env python32# =============================================================================3# SP BOUCHER | SOFTWARE & RESEARCH4# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# PROJECT METADATA8# -----------------------------------------------------------------------------9# Project : KA Maps Engine10# File : server/pipeline/07-check-tiles.py11# Description : Contrôle un cache de tuiles avant bascule : tuiles témoins12# présentes, décodables (km-tiler inspect), couches13# attendues, tailles sous le plafond.14# Module : server15# Repository : https://git.spboucher.ai/ka-maps-engine16# Created : 2026-12-0117# Last Modified : 2026-12-0118#19# =============================================================================20# AUTHOR & PROFESSIONAL AFFILIATION21# =============================================================================22#23# Author : Simon-Pierre Boucher24# Position : Professor of Finance25# Institution : Université du Québec en Outaouais (UQO)26# Department : Département des sciences administratives27# Organization : SP Boucher28#29# Website : https://spboucher.ai30# Git : https://git.spboucher.ai31#32# =============================================================================33# OFFICIAL CONTACT DIRECTORY34# =============================================================================35#36# General : info@spboucher.ai37# Professional : contact@spboucher.ai38# Direct : simon@spboucher.ai39# Research : research@spboucher.ai40# Development : dev@spboucher.ai41# Support : support@spboucher.ai42# Security/Admin : admin@spboucher.ai43# Notifications : notifications@spboucher.ai44#45# Preferred Contact: support@spboucher.ai46#47# =============================================================================48# COPYRIGHT & INTELLECTUAL PROPERTY49# =============================================================================50#51# Copyright (c) 202652# Simon-Pierre Boucher53#54# All rights reserved where applicable.55#56# This file is governed by the applicable project license,57# copyright notices, institutional agreements and relevant law.58#59# Unless expressly authorized by the applicable license or60# rights holder, copying, redistribution, sublicensing,61# publication and commercial exploitation are not permitted.62#63# Existing third-party rights and notices remain unaffected.64#65# =============================================================================66# CONFIDENTIALITY & SECURITY67# =============================================================================68#69# Classification : Public70# Distribution : Public repository; use is governed by the project license71# Security Contact : admin@spboucher.ai72#73# Access to this source does not independently grant permission74# to redistribute or disclose confidential materials.75#76# Do not embed credentials, private keys, access tokens,77# certificates or confidential personal information.78#79# =============================================================================80# LICENSE & MAINTENANCE81# =============================================================================82#83# License : None specified (no license file in this repository)84# Maintainer : Simon-Pierre Boucher85# Technical Contact: dev@spboucher.ai86#87# =============================================================================88# END OF SP BOUCHER SOURCE HEADER89# =============================================================================9091"""Contrôle un cache de tuiles avant bascule : tuiles témoins présentes, décodables (km-tiler inspect),92couches attendues, tailles sous le plafond. Code de sortie non nul = bascule interdite."""93import argparse94import json95import math96import os97import subprocess98import sys99100ap = argparse.ArgumentParser()101ap.add_argument("--cache", required=True)102ap.add_argument("--tiler", default="/usr/local/bin/km-tiler")103a = ap.parse_args()104105HARD = 500 * 1024106POINTS = { # nom → (lat, lon, zooms, couches exigées au zoom max)107 "montreal": (45.5019, -73.5674, range(0, 15), {"road", "building", "water"}),108 "quebec": (46.8139, -71.2080, range(0, 15), {"road", "building"}),109 "laval": (45.5700, -73.7500, range(6, 15), {"road", "building"}),110 "saguenay-rural": (48.5, -71.9, range(0, 13), set()),111 "cote-nord": (50.2, -66.4, range(0, 13), set()),112 "nunavik": (58.1, -68.4, range(0, 13), set()),113}114115116def tile(lat, lon, z):117 n = 2 ** z118 return int((lon + 180) / 360 * n), int((1 - math.asinh(math.tan(math.radians(lat))) / math.pi) / 2 * n)119120121errors, rows = [], []122for name, (lat, lon, zooms, need) in POINTS.items():123 for z in zooms:124 x, y = tile(lat, lon, z)125 p = os.path.join(a.cache, str(z), str(x), f"{y}.mvt")126 if not os.path.exists(p):127 errors.append(f"{name} {z}/{x}/{y} : absente du cache")128 continue129 size = os.path.getsize(p)130 row = {"point": name, "tile": f"{z}/{x}/{y}", "bytes": size}131 if size > HARD:132 errors.append(f"{name} {z}/{x}/{y} : {size} octets > 500 Ko")133 if size > 0:134 r = subprocess.run([a.tiler, "inspect", p], capture_output=True, text=True)135 if r.returncode != 0:136 errors.append(f"{name} {z}/{x}/{y} : indécodable")137 continue138 layers = {l["name"]: l["features"] for l in json.loads(r.stdout)["layers"]}139 row["layers"] = layers140 if z == max(zooms) and need - set(layers):141 errors.append(f"{name} {z}/{x}/{y} : couches absentes {sorted(need - set(layers))}")142 elif z <= 8:143 errors.append(f"{name} {z}/{x}/{y} : vide à bas zoom")144 rows.append(row)145print(json.dumps({"ok": not errors, "errors": errors, "tiles": rows}, ensure_ascii=False, indent=1))146sys.exit(1 if errors else 0)147