|
3 | 3 |
|
4 | 4 | from submodules.model import enums |
5 | 5 | from .checks import check_argument_allowed, run_checks, run_limit_checks |
6 | | -from submodules.model.models import UploadTask, Attribute |
| 6 | +from submodules.model.models import UploadTask |
7 | 7 | import pandas as pd |
8 | 8 | from submodules.model.enums import NotificationType |
| 9 | +from submodules.model.business_objects import record |
9 | 10 | import os |
10 | 11 | import logging |
11 | 12 | import traceback |
12 | | -from submodules.model.business_objects import export |
13 | 13 | from util import category |
14 | 14 | from util import notification |
15 | 15 |
|
@@ -45,7 +45,7 @@ def convert_to_record_dict( |
45 | 45 | user_id: str, |
46 | 46 | file_import_options: str, |
47 | 47 | project_id: str, |
48 | | -) -> List: |
| 48 | +) -> Tuple[List, str]: |
49 | 49 | if not file_type: |
50 | 50 | notification.create_notification( |
51 | 51 | NotificationType.FILE_TYPE_NOT_GIVEN, |
@@ -100,7 +100,28 @@ def convert_to_record_dict( |
100 | 100 | run_limit_checks(df, project_id, user_id) |
101 | 101 | run_checks(df, project_id, user_id) |
102 | 102 | check_and_convert_category_for_unknown(df, project_id, user_id) |
103 | | - return df.to_dict("records") |
| 103 | + added_col = add_running_id_if_not_present(df, project_id) |
| 104 | + return df.to_dict("records"), added_col |
| 105 | + |
| 106 | + |
| 107 | +def add_running_id_if_not_present(df: pd.DataFrame, project_id: str) -> Optional[str]: |
| 108 | + record_item = record.get_one(project_id) |
| 109 | + if record_item: |
| 110 | + # project already has records => no extensions of existing data |
| 111 | + return |
| 112 | + has_id_like = False |
| 113 | + for key in df.columns: |
| 114 | + if category.infer_category_enum(df, key) == enums.DataTypes.INTEGER.value: |
| 115 | + has_id_like = True |
| 116 | + break |
| 117 | + if has_id_like: |
| 118 | + return |
| 119 | + col_name = "running_id" |
| 120 | + while col_name in df.columns: |
| 121 | + col_name += "_" |
| 122 | + df[col_name] = df.index |
| 123 | + |
| 124 | + return col_name |
104 | 125 |
|
105 | 126 |
|
106 | 127 | def check_and_convert_category_for_unknown( |
@@ -130,7 +151,7 @@ def string_to_import_option_dict( |
130 | 151 | if len(tmp) == 2: |
131 | 152 | parameter = tmp[0].strip() |
132 | 153 | if not check_argument_allowed(parameter): |
133 | | - create_notification( |
| 154 | + notification.create_notification( |
134 | 155 | NotificationType.UNKNOWN_PARAMETER, |
135 | 156 | user_id, |
136 | 157 | project_id, |
|
0 commit comments