Central in-memory repository (quasi-singleton) that keeps all
intermediate DataFrames while the import workflow is running.
This class uses only class attributes – no instance is ever created.
Access is always via DataStore., so every window/controller
can read/write data without passing objects around.
DataStore
Source code in src/core/data_store.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121 | class DataStore:
# --------------------------------------------------------------------------
# User data (statistics)
# --------------------------------------------------------------------------
file_path: Optional[str] = None # Absolute path of uploaded file
df_user: Optional[pd.DataFrame] = None # Filtered statistics DataFrame
selected_columns: Optional[list[str]] = None # Columns chosen by the user
# --------------------------------------------------------------------------
# Geo data
# --------------------------------------------------------------------------
geo_meta: Optional[GeoMeta] = None # Metadata about the loaded geo CSV
df_geo: Optional[pd.DataFrame] = None # Geo reference DataFrame
# --------------------------------------------------------------------------
# Mapping result
# --------------------------------------------------------------------------
df_mapped: Optional[pd.DataFrame] = None # Combined statistics-geo mapping
# ========================================================================
# Mutators – always make a copy() so that external code cannot mutate store
# ========================================================================
@classmethod
def set_upload(cls, path: str) -> None:
"""
Store the absolute path of the user-uploaded file.
Steps:
1. Assign the given path to the class attribute `file_path`.
"""
cls.file_path = path
@classmethod
def set_selection(cls, df: pd.DataFrame, columns: Optional[list[str]] | None = None) -> None:
"""
Store the statistics DataFrame after column selection/filtering.
Steps:
1. Copy the given DataFrame to prevent external mutations.
2. Store the user-selected columns for downstream steps.
"""
cls.df_user = df.copy()
cls.selected_columns = columns
@classmethod
def set_geo(cls, df: pd.DataFrame, meta: dict) -> None:
"""
Store the geo reference table together with its meta-information.
Steps:
1. Copy the DataFrame to keep the original immutable.
2. Convert the incoming metadata dict into a GeoMeta instance.
3. Store both DataFrame and GeoMeta.
"""
cls.df_geo = df.copy()
cls.geo_meta = GeoMeta(**meta)
@classmethod
def set_mapping(cls, df: pd.DataFrame) -> None:
"""
Persist the matched table (auto or manual).
Steps:
1. Copy the combined mapping DataFrame.
2. Store it in `df_mapped` for downstream preview/export.
"""
cls.df_mapped = df.copy()
# --------------------------------------------------------------------------
# House-keeping
# --------------------------------------------------------------------------
@classmethod
def clear(cls) -> None:
"""
Reset all stored data – used when the user starts a new workflow run.
Steps:
1. Iterate over all relevant class attributes.
2. Set each attribute to None to release references to DataFrames.
"""
for attr in ("file_path", "df_user", "df_geo", "geo_meta", "df_mapped", "selected_columns"):
setattr(cls, attr, None)
|
clear()
classmethod
Reset all stored data – used when the user starts a new workflow run.
Steps
- Iterate over all relevant class attributes.
- Set each attribute to None to release references to DataFrames.
Source code in src/core/data_store.py
111
112
113
114
115
116
117
118
119
120
121 | @classmethod
def clear(cls) -> None:
"""
Reset all stored data – used when the user starts a new workflow run.
Steps:
1. Iterate over all relevant class attributes.
2. Set each attribute to None to release references to DataFrames.
"""
for attr in ("file_path", "df_user", "df_geo", "geo_meta", "df_mapped", "selected_columns"):
setattr(cls, attr, None)
|
set_geo(df, meta)
classmethod
Store the geo reference table together with its meta-information.
Steps
- Copy the DataFrame to keep the original immutable.
- Convert the incoming metadata dict into a GeoMeta instance.
- Store both DataFrame and GeoMeta.
Source code in src/core/data_store.py
84
85
86
87
88
89
90
91
92
93
94
95 | @classmethod
def set_geo(cls, df: pd.DataFrame, meta: dict) -> None:
"""
Store the geo reference table together with its meta-information.
Steps:
1. Copy the DataFrame to keep the original immutable.
2. Convert the incoming metadata dict into a GeoMeta instance.
3. Store both DataFrame and GeoMeta.
"""
cls.df_geo = df.copy()
cls.geo_meta = GeoMeta(**meta)
|
set_mapping(df)
classmethod
Persist the matched table (auto or manual).
Steps
- Copy the combined mapping DataFrame.
- Store it in
df_mapped for downstream preview/export.
Source code in src/core/data_store.py
97
98
99
100
101
102
103
104
105
106 | @classmethod
def set_mapping(cls, df: pd.DataFrame) -> None:
"""
Persist the matched table (auto or manual).
Steps:
1. Copy the combined mapping DataFrame.
2. Store it in `df_mapped` for downstream preview/export.
"""
cls.df_mapped = df.copy()
|
set_selection(df, columns=None)
classmethod
Store the statistics DataFrame after column selection/filtering.
Steps
- Copy the given DataFrame to prevent external mutations.
- Store the user-selected columns for downstream steps.
Source code in src/core/data_store.py
72
73
74
75
76
77
78
79
80
81
82 | @classmethod
def set_selection(cls, df: pd.DataFrame, columns: Optional[list[str]] | None = None) -> None:
"""
Store the statistics DataFrame after column selection/filtering.
Steps:
1. Copy the given DataFrame to prevent external mutations.
2. Store the user-selected columns for downstream steps.
"""
cls.df_user = df.copy()
cls.selected_columns = columns
|
set_upload(path)
classmethod
Store the absolute path of the user-uploaded file.
Steps
- Assign the given path to the class attribute
file_path.
Source code in src/core/data_store.py
62
63
64
65
66
67
68
69
70 | @classmethod
def set_upload(cls, path: str) -> None:
"""
Store the absolute path of the user-uploaded file.
Steps:
1. Assign the given path to the class attribute `file_path`.
"""
cls.file_path = path
|
Thin container for meta-information accompanying a geographical CSV selection.
Attributes:
| Name |
Type |
Description |
type |
|
Data set family (e.g. 'NUTS', 'LAU', …).
|
version |
|
Release/vintage identifier (e.g. '2023-01').
|
level |
|
Resolution or administrative level of the chosen CSV file.
|
Source code in src/core/data_store.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34 | @dataclass(slots=True)
class GeoMeta:
"""
Thin container for meta-information accompanying a geographical CSV selection.
Attributes:
type : Data set family (e.g. 'NUTS', 'LAU', …).
version : Release/vintage identifier (e.g. '2023-01').
level : Resolution or administrative level of the chosen CSV file.
"""
type: str
version: str
level: str
|