How tonitacker/cimpredict works
Project Type and Purpose
• CIMPredict is a desktop, full-stack application (written in Python) that embeds R modules for statistical computation.
• Purpose: Accepts user input (CIM-blood value and age) via a GUI, runs a trained fracture-risk model (in R), and displays the resulting risk percentage.
High-Level Analysis of the File Structure
Top-level files and folders:
• main.py / main.spec – Python entry point and PyInstaller spec for packaging into an .exe
• R-Skripte/ – folder containing encrypted R scripts (RiskAssessmentModule.R, modelCIMAge.encrypted)
• modelCIMAge.RData – serialized R model data used by the R scripts
• encrypt.py + key.key – Python utility and key for decrypting the R modules at runtime
• README.md – user and developer documentation
Key inferences:
– The app decrypts R code on startup, then invokes R (via subprocess or rpy2) to compute the risk.
– PyInstaller bundles Python runtime, all scripts, model data, and the decryption key into CIMPredict.exe.
– There is an auto-update/checker mechanism that fetches dependency updates on first run.
Main Components and Layers
System into three logical layers:
A. Presentation Layer
• GUI Module (main.py’s UI)
B. Application / Business Logic Layer
• Decryption Service (encrypt.py + key.key)
• Core Controller (Python code orchestrating input validation, decryption, R invocation, and output handling)
• Auto-update Agent (checks for dependency updates on startup)
C. Data Layer
• R Execution Environment (R interpreter / Rscript binary)
• Model Data Store (modelCIMAge.RData + decrypted R scripts)
Data Flows and Interactions
– User launches CIMPredict.exe → Python runtime initializes
– Auto-update Agent checks for new Python/R package versions (Internet)
– GUI prompts user for CIM-value & age → passes inputs to Core Controller
– Core Controller calls Decryption Service to transiently decrypt R scripts into memory or temp files
– Core Controller invokes R engine (Rscript) with:
• decrypted RiskAssessmentModule.R
• modelCIMAge.RData
and the two input parameters
– R script computes fracture risk % → writes result to stdout or file
– Core Controller reads result → updates GUI view → displays risk to user
Important Architectural Patterns and Principles
• Layered Architecture: clear separation of UI, orchestration logic, and data/model
• Modularization: decryption, core logic, GUI and update checker are each independent modules
• External Service Integration: R is treated as an external “model service” called via subprocess/rpy2
• Packaging Strategy: PyInstaller bundles all code, data, and interpreter for a portable .exe
Relevant Technologies
– Python 3.x (main.py, encrypt.py)
– PyInstaller (main.spec → CIMPredict.exe)
– R (Rscript interpreter, .RData model)
– Encryption library (used in encrypt.py + key.key)
– GUI framework (e.g., tkinter or PyQt in main.py—deduced by examining imports)
– Network module (for update checking)