This commit is contained in:
2026-05-28 12:11:37 +02:00
parent edb17f04cb
commit d290be0f6b
6 changed files with 38 additions and 14 deletions
+14 -10
View File
@@ -132,18 +132,22 @@ def prejmenuj(directory: Path) -> None:
if 'PANORAMA Dashboard' in filename:
log(f" Detekován PANORAMA Site Contacts: {filename}")
try:
xl = pd.ExcelFile(file_path)
if 'Site Contacts' in xl.sheet_names:
df_a1 = pd.read_excel(file_path, sheet_name='Site Contacts', nrows=1, header=None)
a1 = str(df_a1.iloc[0, 0]) if not df_a1.empty else ''
if 'Title: Site Contacts' in a1:
new_name = f"{get_timestamp(file_path)} PANORAMA Site Contacts.xlsx"
f.rename(directory / new_name)
log(f" ÚSPĚCH: -> '{new_name}'")
with pd.ExcelFile(file_path) as xl:
sheet_names = xl.sheet_names
if 'Site Contacts' in sheet_names:
df_a1 = xl.parse('Site Contacts', nrows=1, header=None)
a1 = str(df_a1.iloc[0, 0]) if not df_a1.empty else ''
else:
log(f" PŘESKOČENO: A1 neodpovídá vzoru ({a1[:50]})")
else:
a1 = None
# soubor je nyní zavřen — přejmenování proběhne bez chyby
if a1 is None:
log(f" PŘESKOČENO: List 'Site Contacts' nenalezen.")
elif 'Title: Site Contacts' in a1:
new_name = f"{get_timestamp(file_path)} PANORAMA Site Contacts.xlsx"
f.rename(directory / new_name)
log(f" ÚSPĚCH: -> '{new_name}'")
else:
log(f" PŘESKOČENO: A1 neodpovídá vzoru ({a1[:50]})")
except Exception as e:
log(f" CHYBA: {e}")
continue
Binary file not shown.
Binary file not shown.
+24 -4
View File
@@ -5,6 +5,7 @@ Podporované typy:
- Issues & Deviations → kolekce IssuesAndDeviations (klíč: ID / fuzzy+hash)
- Site Visit Details → kolekce Visits (klíč: Site Visit ID (Technical))
- FUL details → kolekce FUL (klíč: SVR Document Number)
- PANORAMA Site Contacts → kolekce contacts (klíč: Contact Identifier)
Filtr: pouze řádky s Country Name == "Czechia"
Historie: při změně fields se stará verze uloží do pole history[]
@@ -67,6 +68,18 @@ REPORT_TYPES = {
"fields.FUL Missing?", "fields.FUL Document Status",
],
},
"contacts": {
"pattern": re.compile(r"PANORAMA Site Contacts\.xlsx$", re.IGNORECASE),
"collection": "contacts",
"upsert_key": None,
"composite_keys": ["Contact Identifier", "Protocol ID", "Site ID", "Contact Role"],
"no_country_filter": True,
"indexes": [
"fields.Country Name", "fields.Site ID",
"fields.Protocol ID", "fields.Contact Role",
"fields.Contact Email Address", "fields.Contact Identifier",
],
},
}
@@ -144,6 +157,7 @@ def import_file(xlsx_path: str, collection, report_cfg: dict) -> dict:
upsert_key = report_cfg["upsert_key"]
collection_name = report_cfg["collection"]
use_fuzzy = (collection_name == "IssuesAndDeviations")
apply_country_filter = COUNTRY_FILTER and not report_cfg.get("no_country_filter")
wb = openpyxl.load_workbook(xlsx_path, read_only=True)
ws = wb[wb.sheetnames[0]]
@@ -161,7 +175,7 @@ def import_file(xlsx_path: str, collection, report_cfg: dict) -> dict:
raw = dict(zip(header, row))
country = (raw.get("Country Name") or "")
if COUNTRY_FILTER and country != COUNTRY_FILTER:
if apply_country_filter and country != COUNTRY_FILTER:
filtered_out += 1
continue
@@ -171,10 +185,16 @@ def import_file(xlsx_path: str, collection, report_cfg: dict) -> dict:
continue
fields[k] = clean_value(v)
record_id = raw.get(upsert_key)
composite_keys = report_cfg.get("composite_keys")
record_id = raw.get(upsert_key) if upsert_key else None
has_id = record_id is not None
if has_id:
if composite_keys:
key_parts = [str(raw.get(k) or "").strip() for k in composite_keys]
h = hashlib.sha1("|".join(key_parts).encode("utf-8")).hexdigest()[:16]
record_id = f"C-{h}"
existing = collection.find_one({"record_id": record_id})
elif has_id:
record_id = str(int(record_id)) if isinstance(record_id, (int, float)) else str(record_id).strip()
existing = collection.find_one({"record_id": record_id})
elif use_fuzzy:
@@ -260,7 +280,7 @@ def import_file(xlsx_path: str, collection, report_cfg: dict) -> dict:
if processed != xlsx_count:
print(f" !!! VAROVANI: zpracovano {processed} radku, ale v XLSX je {xlsx_count} datovych radku")
if db_count is not None and db_count != expected_in_db:
if db_count is not None and db_count != expected_in_db and not report_cfg.get("composite_keys"):
print(f" !!! VAROVANI: v DB je {db_count} dokumentu pro Protocol ID {protocol_id}, ocekavano {expected_in_db} (XLSX {xlsx_count} - filtered {filtered_out})")
return stats