System Architecture¶
Version: 0.9.8.1
Overview of the CreativeDynamics library architecture. The library is a flexible, data-source-agnostic toolkit for time-series analysis, using rough path signatures to detect patterns and changes.
Overview¶
Python library providing tools for analysing time-series data, primarily for creative fatigue detection in marketing. Usable via Python script imports, command-line interface (CLI), and FastAPI. CLI approach recommended for most use cases.
Core principle: operates on pandas DataFrames. Users load data from any source (CSV, databases, etc.) and apply the library’s analytical capabilities.
Core Components¶
Structured into core analytical engine and interaction interfaces.
Core Library (src/creativedynamics/)¶
analyzer.py:Heart of the library containing main analysis logic
Primary function
analyze_all_itemstakes dictionary of pandas DataFrames and orchestrates entire analysis pipeline: change-point detection, trend classification, impact metrics calculation, plotting, report generationData-source agnostic; data loading and preparation happen before calling library
signature_calculator.py:Specialised module for computing rough path signatures
Uses
roughpylibrary for efficient and accurate signature calculationsProvides
compute_signature()function used byanalyzer.py
contracts/:Canonical naming contracts for shared concepts
Defines standard metric identifiers (for example
ctr,cpc) and column identifiers (for exampleday)Provides normalisation helpers to reduce casing and naming drift across interfaces
api/main.pyandapi/adapter.py:Implements the FastAPI-based HTTP API
v1 analysis endpoints call the same core pipeline as the CLI/library via the API adapter
Adapter performs input normalisation (records + column mapping) before calling the core pipeline
_version.py&__init__.py:Standard Python files for package initialisation and version tracking
User Interfaces & Scripts¶
Direct Library Use (e.g.,
run_analysis.py):Flexible way to use library, though CLI now recommended for most use cases
User script responsible for:
Loading data from any source into pandas DataFrame
Performing necessary preprocessing (cleaning, filtering)
Structuring data into library format (dictionary of DataFrames, where each key is item to be analysed)
Calling
creativedynamics.analyze_all_itemsto run analysis
cli.py(Top-Level Script):Provides command-line interface for running predefined analysis pipeline
Recommended approach for most analyses, offering standardised, repeatable workflows with YAML configuration
Handles column mapping and data preparation automatically
CLI entry point:
python -m creativedynamics.cli.main
Supporting Components¶
tests/: Unit and integration testsdocumentation/: Sphinx documentation source filesexamples/: Example scripts demonstrating library usagedata/: Sample data files (CSVs, DuckDB databases)Configuration Files:
pyproject.tomlfor packaging and dependency management, development configuration files
Data Flow (Typical Analysis)¶
Primary workflow accessible via CLI (recommended) or direct library use:
Load & Prepare Data:
Process starts with data loading via CLI or user script
Data loaded from source (CSV file) into pandas DataFrame
All column names standardised to lowercase immediately after CSV ingestion
DataFrame cleaned, filtered, and preprocessed as needed
Data grouped by items to be analysed (e.g., by
ad_id) and converted into dictionary of DataFrames
Analyse All Items (
analyzer.analyze_all_items):Core library function processes prepared data dictionary with analysis parameters (metrics, window size, etc.)
Function iterates through each item’s time series and performs analysis:
Detect Change Points: Uses sliding window and path signatures (
roughpy) to find significant change pointsClassify Trends: Determines trend (“improving”, “worsening”) for segments between change points
Calculate Impact Metrics: Computes
actual_overspend_gbp(financial) andengagement_gap_clicks(operational) based on performance benchmarks, with correlation risk context (metrics are not combined)
Generate Outputs:
Plots (
analyzer.plot_item_analysis): For each item, generates plot visualising time series, change points, and trends. Saved as image filesReports (
analyzer.generate_summary_report): Aggregated results used to create detailed summary reports in HTML and CSV format
Technology Stack¶
Core Language: Python 3.10+
Key Libraries:
pandas: Data manipulation and time series handlingnumpy: Numerical operationsroughpy: Core rough path signature calculationsmatplotlib,seaborn: Plot generationscikit-learn,scipy: Statistical and machine learning utilities
Optional/Supporting Tech:
duckdb: Efficient local data storage (not required for analysis)fastapi: HTTP API
Documentation:
Sphinxwithmyst-parserfor Markdown support