views.export_view.export_logic
Export logic module.
This module contains the core logic for data export operations, separated from the UI components in export_window.py.
ExportLogic
Core logic for data export operations.
Responsibilities
- Identify ID and value columns for export.
- Process column names to remove importer-specific suffixes.
- Collect metadata for the dataset, including geo metadata if available.
- Export the selected columns and metadata as CSV and YAML inside a ZIP archive.
Source code in src/views/export_view/export_logic.py
29 30 31 32 33 34 35 36 37 38 39 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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
__init__()
Initializes the export logic.
- Sets up an internal placeholder for the DataFrame to export.
Source code in src/views/export_view/export_logic.py
40 41 42 43 44 45 46 | |
export_data(id_col, val_col, metadata, target_path)
Exports the data to a ZIP file containing a CSV and a YAML file.
Steps
- Validate that _current_df is set and non-empty; otherwise raise an error.
- Create a temporary directory to hold CSV and YAML files.
- Prepare the export DataFrame with only the two selected columns.
- Rename them to "GEO_ID" and "VALUE" for consistency.
- Write the DataFrame to a CSV file named data.csv in the temp directory.
- Dump the metadata dictionary to a YAML file named metadata.yaml in the temp directory.
- Create a ZIP archive at target_path and add both data.csv and metadata.yaml.
Source code in src/views/export_view/export_logic.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
get_metadata(id_col, val_col, name, description, source, year, data_type)
Collects all metadata required for export.
Steps
- Build a dictionary with trimmed values for name, description, source, year, and type.
- Add processed ID and value column names (without suffixes).
- If geo metadata is available in DataStore, include geo data details.
- Return the complete metadata dictionary.
Source code in src/views/export_view/export_logic.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
load_data(df_stats)
Processes the DataFrame to prepare column lists for export.
Steps
- Store the provided DataFrame as _current_df.
- If the DataFrame is None or empty, return empty lists.
- Identify ID columns by filtering names ending with "_geodata".
- Identify value columns by filtering names ending with "_stats".
- Build display names by removing the suffixes from the column names.
- Return tuples of display and original names for both ID and value columns.
Source code in src/views/export_view/export_logic.py
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 | |
process_column_name(col)
staticmethod
Removes importer-specific suffixes from a column name.
- If name ends with "_geodata", strip that suffix.
- If name ends with "_stats", strip that suffix.
- Otherwise, return the name unchanged.
Source code in src/views/export_view/export_logic.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |