|
4 | 4 |
|
5 | 5 | import calendar |
6 | 6 | import copy |
| 7 | +import locale |
7 | 8 | import sys |
8 | 9 | from datetime import timedelta |
9 | 10 | from decimal import Decimal |
@@ -115,14 +116,32 @@ def _render_uca_data(uca_data, settings, uca_template, timestamp=None): |
115 | 116 |
|
116 | 117 | uca_events = [] |
117 | 118 | # skipped = 0 |
| 119 | + row_count = 1 |
| 120 | + locale.setlocale(locale.LC_ALL, locale.getlocale()) |
118 | 121 | for row in uca_data: |
119 | 122 | try: |
120 | | - if not row[unit_value_header] or Decimal(row[unit_value_header]) <= 0: |
| 123 | + if not row[unit_value_header]: |
121 | 124 | continue |
| 125 | + |
| 126 | + # support localized numbers |
| 127 | + unit_value = locale.delocalize(row[unit_value_header]) |
| 128 | + |
| 129 | + # skip zero or negative values |
| 130 | + if Decimal(unit_value) <= 0: |
| 131 | + continue |
| 132 | + |
| 133 | + row[unit_value_header] = unit_value |
| 134 | + |
122 | 135 | except Exception as err: |
123 | | - print(f"Error: {err}") |
124 | | - print(f"{row[unit_value_header]}") |
125 | | - sys.exit(-1) |
| 136 | + if "Conversion" in str(err): |
| 137 | + eprint(f"Error processing input data in row {row_count}") |
| 138 | + eprint(f" Column: {unit_value_header}") |
| 139 | + eprint(f" Value: {row[unit_value_header]}") |
| 140 | + sys.exit(-1) |
| 141 | + else: |
| 142 | + eprint(f"Unexpected error: {err}") |
| 143 | + eprint(f"{row[unit_value_header]}") |
| 144 | + sys.exit(-1) |
126 | 145 |
|
127 | 146 | if generate_settings.get("mode") == "random": |
128 | 147 | unit_value = preserve_precision(row[unit_value_header], precision) |
@@ -182,6 +201,8 @@ def _render_uca_data(uca_data, settings, uca_template, timestamp=None): |
182 | 201 | print(row) |
183 | 202 | sys.exit(-1) |
184 | 203 |
|
| 204 | + row_count += 1 |
| 205 | + |
185 | 206 | return uca_events |
186 | 207 |
|
187 | 208 |
|
@@ -224,7 +245,7 @@ def preserve_precision(input_number: (str, int, Decimal), precision: int) -> int |
224 | 245 | return int(round_decimal(Decimal(input_number), precision) * precision) |
225 | 246 |
|
226 | 247 |
|
227 | | -def restore_precision(input_number: (str, int, Decimal), precision: int) -> int: |
| 248 | +def restore_precision(input_number: (str, int, Decimal), precision: int) -> Decimal: |
228 | 249 | """ |
229 | 250 | Restore the precision of a number |
230 | 251 |
|
|
0 commit comments