How iivanyaa/staticapp works
Purpose and Entry Points
A local Python document-processing pipeline converts scanned Russian statistical-card PDFs into normalized Excel records and then populates DBF files. Primary CLI entry points are aligner_tool.py for PDF→Excel and the DBF export implementation represented by dbf_debugger_refactored.py / related DBF modules. A desktop UI may be provided by gui.py; packaged Windows output is dist/STATCARD_PROCESSOR.exe.
Input, Templates, and Calibration
PDFs are staged in SCARD/; card/page-type reference material is under EtalonPDFCards/ and template assets are expected in FTEMPLATES/. image_preprocessor.py renders PDF pages and aligns them against page templates. Alignment and OCR depend on persistent coordinate calibration in coordinate_maps.json, derived from field/anchor definitions in calibration_map.py.
Page Classification and Image Alignment
aligner_tool.py orchestrates per-document/page processing. image_preprocessor.py uses OpenCV feature matching/homography to identify a page type and geometrically align it to a canonical template. This creates a critical boundary: downstream OCR assumes aligned images and template-specific coordinate maps; template changes require recalibration.
OCR Extraction and Normalization
data_extractor.py locates text anchors and dynamically derives field ROIs from coordinate_maps.json, then invokes system Tesseract via Python OCR libraries. It also supports the calibration workflow. Raw field values flow to data_postprocessor.py, which cleans OCR artifacts and formats values such as dates before records are accepted for aggregation.
Case-Level Aggregation and Excel Output
Extracted fields from multiple page types are combined around the criminal-case identifier into a unified case row. excel_exporter.py writes the consolidated workbook. The working/output archive Отработано/ contains processed documents and generated spreadsheets, while dist/EXCEL_REPORTS/ shows packaged-runtime report output.
DBF Transformation and Writing
Excel-to-DBF is a separate stage rather than a direct OCR output. Field semantics and target layout are defined by DBFkeys.py and dbf_structure.py; transformation, validation, and file operations are split across dbf_transformer.py, dbf_creator.py, and dbf_writer.py. Target DBF sets are maintained in DBF_FILES/, with baseline/template copies in DBFTemlates/.
Runtime and External Dependencies
The system runs on Python and requires PyMuPDF for PDF rasterization, OpenCV/Numpy for alignment, Tesseract with Russian language data for OCR, OpenPyXL for XLSX, and a DBF library. It is primarily filesystem-driven—no server or database service is evident. Packaging is PyInstaller-oriented, via Gemini_OCR_Processor.spec, STATCARD_OCR_Processor.spec, build_app.py, and distributable artifacts in dist/.
Main entry points: image_preprocessor.py Page alignment · dbf_transformer.py DBF transformation · excel_exporter.py Excel exporter · aligner_tool.py PDF processing CLI
Components 18
Inputs & Templates
- Scanned PDFs
SCARD - Card references
EtalonPDFCards - Page templates
FTEMPLATES - Calibration maps · Persistent template-specific field and anchor coordinates.
coordinate_maps.json - Calibration definitions
calibration_map.py
PDF to Excel
- PDF processing CLI · Processes each document and page through alignment and extraction.
aligner_tool.py - Page alignment · Classifies pages and aligns them with OpenCV feature matching and homography.
image_preprocessor.py - OCR extraction · Derives ROIs from aligned pages and coordinate maps, then invokes Tesseract.
data_extractor.py - Value normalization
data_postprocessor.py - Case aggregation · Combines page fields into rows keyed by criminal-case identifier.
- Excel exporter
excel_exporter.py - Processed archive · Stores processed documents and generated spreadsheets.
Отработано
Excel to DBF
- DBF schema · Defines DBF field semantics and structure.
DBFkeys.py - DBF structure
dbf_structure.py - DBF transformation · Transforms and validates Excel records for DBF targets.
dbf_transformer.py - DBF creation & writing
dbf_writer.py - DBF target sets
DBF_FILES
Runtime & Delivery
- Desktop packaging · PyInstaller-oriented desktop runtime and executable output.
dist/STATCARD_PROCESSOR.exe
Connections 17
- Scanned PDFs → PDF processing CLI: PDF input
- PDF processing CLI → Page alignment: per page
- Card references → Page alignment: page references
- Page templates → Page alignment: canonical templates
- Page alignment → OCR extraction: aligned page + type
- Calibration definitions → Calibration maps: defines anchors
- Calibration maps → OCR extraction: field ROIs
- OCR extraction → Value normalization: raw OCR fields
- Value normalization → Case aggregation: normalized fields
- Case aggregation → Excel exporter: case rows
- Excel exporter → Processed archive: workbooks
- Excel exporter → DBF transformation: Excel records
- DBF schema → DBF transformation: field mapping
- DBF structure → DBF transformation: record layout
- DBF transformation → DBF creation & writing: validated DBF records
- DBF creation & writing → DBF target sets: DBF files
- Desktop packaging → PDF processing CLI: packages pipeline