Skip to content

Instantly share code, notes, and snippets.

@hdary-85
hdary-85 / Py
Created September 25, 2025 19:03
Échange
import pandas as pd
import numpy as np
from math import ceil
from datetime import datetime
# =======================
# Configuration par défaut
# =======================
SLIDING_WEEKS = 8 # Fenêtre glissante (en semaines) pour recalculer les volumes "observés"
RARE_WEEKLY_THRESHOLD = 1.0 # En dessous de 1 dossier/semaine en moyenne => "rare"
@hdary-85
hdary-85 / Card
Created September 24, 2025 15:00
import re
import pandas as pd
from typing import Optional, List
# --- Réseaux & utilitaires ---
CARD_PATTERNS = {
"Visa": re.compile(r"^4\d{12}(?:\d{3})?(?:\d{3})?$"),
"Mastercard": re.compile(r"^(5[1-5]\d{14}|2(?:2[2-9]\d{12}|[3-6]\d{13}|7[01]\d{12}|720\d{12}))$"),
"American Express": re.compile(r"^3[47]\d{13}$"),
"Discover": re.compile(r"^(?:6011\d{12}|65\d{14}|64[4-9]\d{13}|622(?:12[6-9]|1[3-9]\d|[2-8]\d{2}|9(?:[01]\d|2[0-5]))\d{10})$"),
import pandas as pd
from collections import defaultdict, deque
# -------------------------------------------------------------------
# PRÉREQUIS : tu dois déjà avoir ces 3 DataFrames (de ta 1re partie) :
# nodes(doc_id, node_id, tag, parent_id, depth, path)
# attrs(doc_id, node_id, attr, value)
# texts(doc_id, node_id, text)
# -------------------------------------------------------------------
import pandas as pd
from collections import defaultdict, deque
# -------------------------------------------------------------------
# PRÉREQUIS : tu dois déjà avoir ces 3 DataFrames (de ta 1re partie) :
# nodes(doc_id, node_id, tag, parent_id, depth, path)
# attrs(doc_id, node_id, attr, value)
# texts(doc_id, node_id, text)
# -------------------------------------------------------------------
import io
from xml.etree.ElementTree import iterparse
import pandas as pd
from collections import defaultdict
from typing import Dict, List, Optional, Iterable, Set
# ===================== Helpers =====================
def _local(tag: str) -> str:
return tag.split('}', 1)[-1] if '}' in tag else tag
# 1) Parser n’importe quel XML
dfs = parse_xml_to_tables("ton_fichier.xml")
nodes, attrs, texts, id_index, refs = dfs["nodes"], dfs["attrs"], dfs["texts"], dfs["id_index"], dfs["refs"]
# 2) Construire l’index des enfants pour naviguer dans l’arbre
children_idx = build_children_index(nodes)
# 3) Ex.: récupérer tous les "subjects" (peu importe le nom exact, on matche au regex)
subjects = nodes[nodes["tag"].str.contains(r"(?i)subject")] # tu peux ajuster le motif
import re
from xml.etree.ElementTree import iterparse
import pandas as pd
from collections import defaultdict, deque
from typing import Dict, List, Optional, Iterable, Set
# ---------- helpers ----------
def local(tag: str) -> str:
return tag.split('}', 1)[-1] if '}' in tag else tag
TERME (FR) ANGLAIS ESPAGNOL MANDARIN (pinyin) PENDJABI (translit.)
ELEPHANT elephant elefante daxiang hathi
IVOIRE ivory marfil xiangya daant
RHINOCEROS rhino rinoceronte xiniu gainda
CORNE horn cuerno jiao singh
TIGRE tiger tigre laohu bagh
LION lion leon shizi sher
LEOPARD leopard leopardo baozi tendua
PANTHERE panther pantera heibao kali bagh
JAGUAR jaguar jaguar meibao jaguar
df.loc[df["colonne_condition"].str.contains("CDD", na=False) & df["colonne_cible"].isna(), "colonne_cible"] = "CDD"
# app.py
# ------------------------------------------------------------------------------
# LANCER : python app.py
# DEPENDANCE : pip install flask
# ------------------------------------------------------------------------------
from flask import Flask, render_template, jsonify, request, Response
from threading import Thread, Lock
from datetime import datetime
import time, json, uuid, webbrowser
import tkinter as tk