From 6b8b8571605e831a9b8da5bf82b271c5851cc250 Mon Sep 17 00:00:00 2001 From: Sergei Date: Sun, 17 Dec 2023 19:01:26 +0500 Subject: [PATCH 01/12] Recovery - from SportOrg SI log, SportOrg HTML reports, SI master station CSV --- sportorg/gui/dialogs/file_dialog.py | 4 +- sportorg/gui/menu/actions.py | 19 ++++ sportorg/gui/menu/menu.py | 12 +++ .../modules/recovery/recovery_orgeo_json.py | 0 .../recovery/recovery_si_master_csv.py | 70 +++++++++++++++ .../recovery/recovery_sportorg_html.py | 38 ++++++++ .../recovery/recovery_sportorg_si_log.py | 86 +++++++++++++++++++ .../modules/sportident/fix_time_sicard_5.py | 44 ++++++++++ 8 files changed, 271 insertions(+), 2 deletions(-) create mode 100644 sportorg/modules/recovery/recovery_orgeo_json.py create mode 100644 sportorg/modules/recovery/recovery_si_master_csv.py create mode 100644 sportorg/modules/recovery/recovery_sportorg_html.py create mode 100644 sportorg/modules/recovery/recovery_sportorg_si_log.py create mode 100644 sportorg/modules/sportident/fix_time_sicard_5.py diff --git a/sportorg/gui/dialogs/file_dialog.py b/sportorg/gui/dialogs/file_dialog.py index 758ea751..907d4b73 100644 --- a/sportorg/gui/dialogs/file_dialog.py +++ b/sportorg/gui/dialogs/file_dialog.py @@ -7,11 +7,11 @@ from sportorg.modules.configs.configs import Config, ConfigFile -def get_open_file_name(caption='', filter_text=''): +def get_open_file_name(caption='', filter_text='', set_dir=True): result = QFileDialog.getOpenFileName(None, caption, get_default_dir(), filter_text)[ 0 ] - if result: + if result and set_dir: set_default_dir(os.path.dirname(os.path.abspath(result))) return result diff --git a/sportorg/gui/menu/actions.py b/sportorg/gui/menu/actions.py index 024fa560..b3826faa 100644 --- a/sportorg/gui/menu/actions.py +++ b/sportorg/gui/menu/actions.py @@ -59,6 +59,7 @@ from sportorg.modules.live.live import live_client from sportorg.modules.ocad import ocad from sportorg.modules.ocad.ocad import OcadImportException +from sportorg.modules.recovery import recovery_sportorg_html, recovery_sportorg_si_log, recovery_si_master_csv from sportorg.modules.rfid_impinj.rfid_impinj import ImpinjClient from sportorg.modules.sfr.sfrreader import SFRReaderClient from sportorg.modules.sportident.sireader import SIReaderClient @@ -345,6 +346,24 @@ def execute(self): ) +class RecoverySportorgHtmlAction(Action, metaclass=ActionFactory): + def execute(self): + recovery_sportorg_html.recovery() + self.app.refresh() + + +class RecoverySportorgSiLogAction(Action, metaclass=ActionFactory): + def execute(self): + recovery_sportorg_si_log.recovery() + self.app.refresh() + + +class RecoverySportidentMasterCsvAction(Action, metaclass=ActionFactory): + def execute(self): + recovery_si_master_csv.recovery() + self.app.refresh() + + class AddObjectAction(Action, metaclass=ActionFactory): def execute(self): self.app.add_object() diff --git a/sportorg/gui/menu/menu.py b/sportorg/gui/menu/menu.py index 4243ce4b..fd22f56e 100644 --- a/sportorg/gui/menu/menu.py +++ b/sportorg/gui/menu/menu.py @@ -72,6 +72,18 @@ def menu_list(): 'title': translate('IOF xml'), 'action': 'IOFEntryListImportAction', }, + { + 'title': translate('SPORTident master station CSV'), + 'action': 'RecoverySportidentMasterCsvAction', + }, + { + 'title': translate('SportOrg SI log'), + 'action': 'RecoverySportorgSiLogAction', + }, + { + 'title': translate('SportOrg HTML'), + 'action': 'RecoverySportorgHtmlAction', + }, ], }, { diff --git a/sportorg/modules/recovery/recovery_orgeo_json.py b/sportorg/modules/recovery/recovery_orgeo_json.py new file mode 100644 index 00000000..e69de29b diff --git a/sportorg/modules/recovery/recovery_si_master_csv.py b/sportorg/modules/recovery/recovery_si_master_csv.py new file mode 100644 index 00000000..6a337b42 --- /dev/null +++ b/sportorg/modules/recovery/recovery_si_master_csv.py @@ -0,0 +1,70 @@ +""" +Parse backup memory CSV file of BSM SPORTident station generated by SI Config Plus + +-- Format: +CSV, separator ";" +Needed positions: card number (2), start (15), finish (21), splits (44): count of punches, (code + time) * n + +No;Read on;SIID;Start no;Clear CN;Clear DOW;Clear time;Clear_r CN;Clear_r DOW;Clear_r time;Check CN;Check DOW;Check time +;Start CN;Start DOW;Start time;Start_r CN;Start_r DOW;Start_r time;Finish CN;Finish DOW;Finish time;Finish_r CN;Finish_r +DOW;Finish_r time;Class;First name;Last name;Club;Country;Email;Date of birth;Sex;Phone;Street;ZIP;City;Hardware version +;Software version;Battery date;Battery voltage;Clear count;Character set;SEL_FEEDBACK;No. of records;Record 1 CN;Record +1 DOW;Record 1 time;Record 2 CN;Record 2 DOW;Record 2 time;Record 3 CN; + +-- Example: +440;2023-12-17 11:59:02;2007313;;2;Su; 12:40:50;;;;2;Su; 12:40:50;;;;;;;1;Su; 14:50:45;;;;;2007313;SPORTident Ru;;;;;;;; +;;;;;;;;;10;34;Su; 12:41:33;49;Su; 12:54:39;43;Su; 13:22:28;39;Su; 13:51:28;42;Su; 14:02:34;46;Su; 14:15:04;40;Su; 14:31 +:03;47;Su; 14:39:54;37;Su; 14:47:02;90;Su; 14:49:21; + +""" +from sportorg.common.otime import OTime +from sportorg.gui.dialogs.file_dialog import get_open_file_name +from sportorg.language import translate +from sportorg.models.memory import race, ResultSportident, Split +from sportorg.modules.sportident.fix_time_sicard_5 import fix_time +from sportorg.utils.time import hhmmss_to_time + +POS_CARD = 2 +POS_START = 15 +POS_FINISH = 21 +POS_COUNT = 44 +race = race() + + +def recovery(): + + file_name = get_open_file_name( + translate('Open SPORTident master station backup file'), translate('CSV file (*.csv)'), False + ) + + text_file = open(file_name, "r") + lines = text_file.readlines() + + separator = ";" + + zero_time_val = race.get_setting('system_zero_time', (8, 0, 0)) + zero_time = OTime(hour=zero_time_val[0], minute=zero_time_val[1], sec=zero_time_val[2]) + + for line in lines: + print(line) + + tokens = line.split(separator) + if tokens[0] == "No" or len(tokens) < 45: + continue + + res = ResultSportident() + res.card_number = int(tokens[POS_CARD]) + res.start_time = hhmmss_to_time(tokens[POS_START]) + res.finish_time = hhmmss_to_time(tokens[POS_FINISH]) + + punch_count = int(tokens[POS_COUNT]) + existing_punches = (len(tokens) - POS_COUNT - 1) // 3 + + for i in range(min(punch_count, existing_punches)): + punch = Split() + punch.code = tokens[POS_COUNT + 3 * i + 1] + punch.time = hhmmss_to_time(tokens[POS_COUNT + 3 * i + 3]) + res.splits.append(punch) + + fix_time(res, zero_time) + race.results.append(res) diff --git a/sportorg/modules/recovery/recovery_sportorg_html.py b/sportorg/modules/recovery/recovery_sportorg_html.py new file mode 100644 index 00000000..a23090c2 --- /dev/null +++ b/sportorg/modules/recovery/recovery_sportorg_html.py @@ -0,0 +1,38 @@ +""" +Parse SportOrg HTML report (containing full json) + +""" +import os.path +import string +from io import open +from random import choices +from tempfile import gettempdir +from sportorg.gui.dialogs.file_dialog import get_open_file_name +from sportorg.gui.dialogs.sportorg_import_dialog import SportOrgImportDialog +from sportorg.language import translate +from sportorg.modules.backup.json import get_races_from_file + + +def recovery(): + + file_name = get_open_file_name( + translate('Open SportOrg html file'), translate('SportOrg html report (*.html)'), False + ) + + text_file = open(file_name, "r", encoding="utf-8") + lines = text_file.readlines() + + for line in lines: + if line.find("var race = {\"courses\":") > -1: + json = line.strip()[11:-1] + + # save json to tmp file and op[en with standard import action + tmp_filename = os.path.join(gettempdir(), + "sportorg_" + ''.join(choices(string.ascii_letters, k=10)) + ".json") + temp_file = open(tmp_filename, "w") + temp_file.write(json) + temp_file.close() + + with open(tmp_filename) as f: + attr = get_races_from_file(f) + SportOrgImportDialog(*attr).exec_() diff --git a/sportorg/modules/recovery/recovery_sportorg_si_log.py b/sportorg/modules/recovery/recovery_sportorg_si_log.py new file mode 100644 index 00000000..977bd957 --- /dev/null +++ b/sportorg/modules/recovery/recovery_sportorg_si_log.py @@ -0,0 +1,86 @@ +""" +Parse backup SI log generated in C:\\Program Files (x86)\\SportOrg\\log + +-- Format: + +start +[SI_CARD] +[START] - 0:00:00 if not exist +[FINISH] - 0:00:00 if not exist +split_start +[CODE_1] [TIME_1] +... +[CODE_N] [TIME_N] +split_end +end + +-- Example: + +start +8013787 +00:00:00 +11:39:25 +split_start +57 11:43:05 +69 11:37:59 +90 11:39:07 +split_end +end + +""" +from sportorg.common.otime import OTime +from sportorg.gui.dialogs.file_dialog import get_open_file_name +from sportorg.language import translate +from sportorg.models.memory import race, ResultSportident, Split +from sportorg.modules.sportident.fix_time_sicard_5 import fix_time +from sportorg.utils.time import hhmmss_to_time + +race = race() + + +def recovery(): + zero_time_val = race.get_setting('system_zero_time', (8, 0, 0)) + zero_time = OTime(hour=zero_time_val[0], minute=zero_time_val[1], sec=zero_time_val[2]) + + file_name = get_open_file_name( + translate('Open SportOrg SI log file'), translate('SportOrg SI log (*.log)'), False + ) + + text_file = open(file_name, "r") + lines = text_file.readlines() + + cur_res = ResultSportident() + read_num = False + read_start = False + read_spl = False + read_finish = False + + for line in lines: + print(line) + line = line.strip() + if read_num: + cur_res.card_number = int(line) + read_start = True + read_num = False + elif read_start: + cur_res.start_time = hhmmss_to_time(line) + read_start = False + read_finish = True + elif read_finish: + cur_res.finish_time = hhmmss_to_time(line) + read_finish = False + elif line == 'end': + fix_time(cur_res, zero_time) + race.results.append(cur_res) + cur_res = ResultSportident() + elif line == 'start': + read_num = True + elif line == 'split_start': + read_spl = True + elif line == 'split_end': + read_spl = False + elif read_spl: + spl = Split() + spl.code = line.split(" ")[0] + spl.time = hhmmss_to_time(line.split(" ")[1]) + cur_res.splits.append(spl) diff --git a/sportorg/modules/sportident/fix_time_sicard_5.py b/sportorg/modules/sportident/fix_time_sicard_5.py new file mode 100644 index 00000000..8d89f803 --- /dev/null +++ b/sportorg/modules/sportident/fix_time_sicard_5.py @@ -0,0 +1,44 @@ +from sportorg.common.otime import OTime +DEF_START_TIME = OTime(hour=8) + + +def if_si_card_5(card_number): + return card_number < 1000000 + + +def _fix_time(time, zero_time): + """ + takes nearest to zero time, assuming, that original time is in only 12h format (SPORTident SICard 5) + exclude 00:00:00, meaning no time + 00:15:18 (10:00:00) -> 12:15:18 + 00:15:18 (14:00:00) -> 00:15:18 + 11:15:18 (10:00:00) -> 11:15:18 + 11:15:18 (17:00:00) -> 23:15:18 + 22:15:18 (10:00:00) -> 10:15:18 + 22:15:18 (11:00:00) -> 22:15:18 + """ + origin_time = time + + if time == OTime(0): + return time + + time_12h = OTime(hour=12) + + if time >= time_12h: + time -= time_12h + + if zero_time > time: + if zero_time - time < time_12h: + time += time_12h + + return time + + +# fix time in result for SI Card 5 (12h format) +def fix_time(res, zero_time=DEF_START_TIME): + if if_si_card_5(res.card_number): + res.finish_time = _fix_time(res.finish_time, zero_time) + res.start_time = _fix_time(res.start_time, zero_time) + + for i in range(len(res.splits)): + res.splits[i].time = _fix_time(res.splits[i].time, zero_time) From 01fcc9f1d73f8d7d85102ff6d8f744fcb95e59f6 Mon Sep 17 00:00:00 2001 From: Sergei Date: Sun, 17 Dec 2023 19:18:20 +0500 Subject: [PATCH 02/12] Recovery - from SportOrg SI log, SportOrg HTML reports, SI master station CSV / translation --- languages/ru_RU/LC_MESSAGES/sportorg.po | 31 +++++++++++++++++-- .../modules/recovery/recovery_orgeo_json.py | 0 .../recovery/recovery_sportorg_html.py | 2 +- 3 files changed, 30 insertions(+), 3 deletions(-) delete mode 100644 sportorg/modules/recovery/recovery_orgeo_json.py diff --git a/languages/ru_RU/LC_MESSAGES/sportorg.po b/languages/ru_RU/LC_MESSAGES/sportorg.po index 1d830def..0021a859 100644 --- a/languages/ru_RU/LC_MESSAGES/sportorg.po +++ b/languages/ru_RU/LC_MESSAGES/sportorg.po @@ -3,7 +3,7 @@ msgstr "" "Project-Id-Version: SportOrg\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2018-04-12 11:13+0300\n" -"PO-Revision-Date: 2023-08-27 15:09+0500\n" +"PO-Revision-Date: 2023-12-17 19:16+0500\n" "Last-Translator: SportOrg\n" "Language-Team: SportOrg\n" "Language: ru_RU\n" @@ -12,7 +12,7 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" "X-Loco-Source-Locale: ru_RU\n" -"X-Generator: Poedit 3.3.2\n" +"X-Generator: Poedit 3.4.1\n" "X-Poedit-SourceCharset: UTF-8\n" "X-Loco-Parser: loco_parse_po\n" "X-Poedit-Basepath: ../../../sportorg\n" @@ -1568,3 +1568,30 @@ msgstr "Ошибка открытия файла. Файл уже открыт msgid "Multi day race" msgstr "Многодневная гонка" + +msgid "SportOrg HTML" +msgstr "Файл HTML, SportOrg" + +msgid "SportOrg HTML report (*.html)" +msgstr "Файл HTML, SportOrg (*.html)" + +msgid "Open SportOrg HTML file" +msgstr "Открыть файл HTML, SportOrg" + +msgid "SportOrg SI log" +msgstr "Файл лога чипов, SportOrg" + +msgid "SportOrg SI log (*.log)" +msgstr "Файл лога чипов, SportOrg (*.log)" + +msgid "Open SportOrg SI log file" +msgstr "Открыть файл лога чипов, SportOrg" + +msgid "SPORTident master station CSV" +msgstr "Файл CSV мастер-станции SPORTident" + +msgid "CSV file (*.csv)" +msgstr "Файл CSV (*.csv)" + +msgid "Open SPORTident master station backup file" +msgstr "Открыть файл CSV мастер-станции SPORTident" diff --git a/sportorg/modules/recovery/recovery_orgeo_json.py b/sportorg/modules/recovery/recovery_orgeo_json.py deleted file mode 100644 index e69de29b..00000000 diff --git a/sportorg/modules/recovery/recovery_sportorg_html.py b/sportorg/modules/recovery/recovery_sportorg_html.py index a23090c2..2986bf53 100644 --- a/sportorg/modules/recovery/recovery_sportorg_html.py +++ b/sportorg/modules/recovery/recovery_sportorg_html.py @@ -16,7 +16,7 @@ def recovery(): file_name = get_open_file_name( - translate('Open SportOrg html file'), translate('SportOrg html report (*.html)'), False + translate('Open SportOrg HTML file'), translate('SportOrg HTML report (*.html)'), False ) text_file = open(file_name, "r", encoding="utf-8") From dd9a44adbb818fab72f779dd95eace11521ee108 Mon Sep 17 00:00:00 2001 From: Sergei Date: Sun, 17 Dec 2023 19:26:05 +0500 Subject: [PATCH 03/12] Formatting --- sportorg/gui/menu/actions.py | 6 +++++- .../modules/recovery/recovery_si_master_csv.py | 17 ++++++++++------- .../modules/recovery/recovery_sportorg_html.py | 16 ++++++++++------ .../recovery/recovery_sportorg_si_log.py | 16 ++++++++++------ .../modules/sportident/fix_time_sicard_5.py | 1 + 5 files changed, 36 insertions(+), 20 deletions(-) diff --git a/sportorg/gui/menu/actions.py b/sportorg/gui/menu/actions.py index b3826faa..6b864879 100644 --- a/sportorg/gui/menu/actions.py +++ b/sportorg/gui/menu/actions.py @@ -59,7 +59,11 @@ from sportorg.modules.live.live import live_client from sportorg.modules.ocad import ocad from sportorg.modules.ocad.ocad import OcadImportException -from sportorg.modules.recovery import recovery_sportorg_html, recovery_sportorg_si_log, recovery_si_master_csv +from sportorg.modules.recovery import ( + recovery_si_master_csv, + recovery_sportorg_html, + recovery_sportorg_si_log, +) from sportorg.modules.rfid_impinj.rfid_impinj import ImpinjClient from sportorg.modules.sfr.sfrreader import SFRReaderClient from sportorg.modules.sportident.sireader import SIReaderClient diff --git a/sportorg/modules/recovery/recovery_si_master_csv.py b/sportorg/modules/recovery/recovery_si_master_csv.py index 6a337b42..657757a6 100644 --- a/sportorg/modules/recovery/recovery_si_master_csv.py +++ b/sportorg/modules/recovery/recovery_si_master_csv.py @@ -20,7 +20,7 @@ from sportorg.common.otime import OTime from sportorg.gui.dialogs.file_dialog import get_open_file_name from sportorg.language import translate -from sportorg.models.memory import race, ResultSportident, Split +from sportorg.models.memory import ResultSportident, Split, race from sportorg.modules.sportident.fix_time_sicard_5 import fix_time from sportorg.utils.time import hhmmss_to_time @@ -32,24 +32,27 @@ def recovery(): - file_name = get_open_file_name( - translate('Open SPORTident master station backup file'), translate('CSV file (*.csv)'), False + translate('Open SPORTident master station backup file'), + translate('CSV file (*.csv)'), + False, ) - text_file = open(file_name, "r") + text_file = open(file_name, 'r') lines = text_file.readlines() - separator = ";" + separator = ';' zero_time_val = race.get_setting('system_zero_time', (8, 0, 0)) - zero_time = OTime(hour=zero_time_val[0], minute=zero_time_val[1], sec=zero_time_val[2]) + zero_time = OTime( + hour=zero_time_val[0], minute=zero_time_val[1], sec=zero_time_val[2] + ) for line in lines: print(line) tokens = line.split(separator) - if tokens[0] == "No" or len(tokens) < 45: + if tokens[0] == 'No' or len(tokens) < 45: continue res = ResultSportident() diff --git a/sportorg/modules/recovery/recovery_sportorg_html.py b/sportorg/modules/recovery/recovery_sportorg_html.py index 2986bf53..9e617cd1 100644 --- a/sportorg/modules/recovery/recovery_sportorg_html.py +++ b/sportorg/modules/recovery/recovery_sportorg_html.py @@ -7,6 +7,7 @@ from io import open from random import choices from tempfile import gettempdir + from sportorg.gui.dialogs.file_dialog import get_open_file_name from sportorg.gui.dialogs.sportorg_import_dialog import SportOrgImportDialog from sportorg.language import translate @@ -14,12 +15,13 @@ def recovery(): - file_name = get_open_file_name( - translate('Open SportOrg HTML file'), translate('SportOrg HTML report (*.html)'), False + translate('Open SportOrg HTML file'), + translate('SportOrg HTML report (*.html)'), + False, ) - text_file = open(file_name, "r", encoding="utf-8") + text_file = open(file_name, 'r', encoding='utf-8') lines = text_file.readlines() for line in lines: @@ -27,9 +29,11 @@ def recovery(): json = line.strip()[11:-1] # save json to tmp file and op[en with standard import action - tmp_filename = os.path.join(gettempdir(), - "sportorg_" + ''.join(choices(string.ascii_letters, k=10)) + ".json") - temp_file = open(tmp_filename, "w") + tmp_filename = os.path.join( + gettempdir(), + 'sportorg_' + ''.join(choices(string.ascii_letters, k=10)) + '.json', + ) + temp_file = open(tmp_filename, 'w') temp_file.write(json) temp_file.close() diff --git a/sportorg/modules/recovery/recovery_sportorg_si_log.py b/sportorg/modules/recovery/recovery_sportorg_si_log.py index 977bd957..35db3c90 100644 --- a/sportorg/modules/recovery/recovery_sportorg_si_log.py +++ b/sportorg/modules/recovery/recovery_sportorg_si_log.py @@ -31,7 +31,7 @@ from sportorg.common.otime import OTime from sportorg.gui.dialogs.file_dialog import get_open_file_name from sportorg.language import translate -from sportorg.models.memory import race, ResultSportident, Split +from sportorg.models.memory import ResultSportident, Split, race from sportorg.modules.sportident.fix_time_sicard_5 import fix_time from sportorg.utils.time import hhmmss_to_time @@ -40,13 +40,17 @@ def recovery(): zero_time_val = race.get_setting('system_zero_time', (8, 0, 0)) - zero_time = OTime(hour=zero_time_val[0], minute=zero_time_val[1], sec=zero_time_val[2]) + zero_time = OTime( + hour=zero_time_val[0], minute=zero_time_val[1], sec=zero_time_val[2] + ) file_name = get_open_file_name( - translate('Open SportOrg SI log file'), translate('SportOrg SI log (*.log)'), False + translate('Open SportOrg SI log file'), + translate('SportOrg SI log (*.log)'), + False, ) - text_file = open(file_name, "r") + text_file = open(file_name, 'r') lines = text_file.readlines() cur_res = ResultSportident() @@ -81,6 +85,6 @@ def recovery(): read_spl = False elif read_spl: spl = Split() - spl.code = line.split(" ")[0] - spl.time = hhmmss_to_time(line.split(" ")[1]) + spl.code = line.split(' ')[0] + spl.time = hhmmss_to_time(line.split(' ')[1]) cur_res.splits.append(spl) diff --git a/sportorg/modules/sportident/fix_time_sicard_5.py b/sportorg/modules/sportident/fix_time_sicard_5.py index 8d89f803..d6d81003 100644 --- a/sportorg/modules/sportident/fix_time_sicard_5.py +++ b/sportorg/modules/sportident/fix_time_sicard_5.py @@ -1,4 +1,5 @@ from sportorg.common.otime import OTime + DEF_START_TIME = OTime(hour=8) From 28f89e377b9b52cf5a8add1f7c3f9b73a7ffb355 Mon Sep 17 00:00:00 2001 From: Sergei Date: Mon, 18 Dec 2023 13:01:48 +0500 Subject: [PATCH 04/12] Removing of debug print() calls --- sportorg/modules/recovery/recovery_si_master_csv.py | 2 -- sportorg/modules/recovery/recovery_sportorg_si_log.py | 1 - 2 files changed, 3 deletions(-) diff --git a/sportorg/modules/recovery/recovery_si_master_csv.py b/sportorg/modules/recovery/recovery_si_master_csv.py index 657757a6..f29952be 100644 --- a/sportorg/modules/recovery/recovery_si_master_csv.py +++ b/sportorg/modules/recovery/recovery_si_master_csv.py @@ -49,8 +49,6 @@ def recovery(): ) for line in lines: - print(line) - tokens = line.split(separator) if tokens[0] == 'No' or len(tokens) < 45: continue diff --git a/sportorg/modules/recovery/recovery_sportorg_si_log.py b/sportorg/modules/recovery/recovery_sportorg_si_log.py index 35db3c90..fec253de 100644 --- a/sportorg/modules/recovery/recovery_sportorg_si_log.py +++ b/sportorg/modules/recovery/recovery_sportorg_si_log.py @@ -60,7 +60,6 @@ def recovery(): read_finish = False for line in lines: - print(line) line = line.strip() if read_num: cur_res.card_number = int(line) From ebbb042db92dc2e812c2efca38852ca3b0220289 Mon Sep 17 00:00:00 2001 From: Sergei Date: Mon, 18 Dec 2023 14:34:40 +0500 Subject: [PATCH 05/12] Refactoring after Danil's comments --- sportorg/gui/menu/actions.py | 26 ++++++- .../recovery/recovery_si_master_csv.py | 49 ++++++------- .../recovery/recovery_sportorg_html.py | 48 +++++-------- .../recovery/recovery_sportorg_si_log.py | 71 ++++++++----------- 4 files changed, 92 insertions(+), 102 deletions(-) diff --git a/sportorg/gui/menu/actions.py b/sportorg/gui/menu/actions.py index 6b864879..ac0a4657 100644 --- a/sportorg/gui/menu/actions.py +++ b/sportorg/gui/menu/actions.py @@ -2,6 +2,7 @@ import socket import time import uuid +from os import remove from typing import Any, Dict, Type from PySide2 import QtCore @@ -352,19 +353,38 @@ def execute(self): class RecoverySportorgHtmlAction(Action, metaclass=ActionFactory): def execute(self): - recovery_sportorg_html.recovery() + file_name = get_open_file_name( + translate('Open SportOrg HTML file'), + translate('SportOrg HTML report (*.html)'), + False, + ) + tmp_filename = recovery_sportorg_html.recovery(file_name) + with open(tmp_filename) as f: + attr = get_races_from_file(f) + SportOrgImportDialog(*attr).exec_() + remove(tmp_filename) self.app.refresh() class RecoverySportorgSiLogAction(Action, metaclass=ActionFactory): def execute(self): - recovery_sportorg_si_log.recovery() + file_name = get_open_file_name( + translate('Open SportOrg SI log file'), + translate('SportOrg SI log (*.log)'), + False, + ) + recovery_sportorg_si_log.recovery(file_name) self.app.refresh() class RecoverySportidentMasterCsvAction(Action, metaclass=ActionFactory): def execute(self): - recovery_si_master_csv.recovery() + file_name = get_open_file_name( + translate('Open SPORTident master station backup file'), + translate('CSV file (*.csv)'), + False, + ) + recovery_si_master_csv.recovery(file_name) self.app.refresh() diff --git a/sportorg/modules/recovery/recovery_si_master_csv.py b/sportorg/modules/recovery/recovery_si_master_csv.py index f29952be..c4021456 100644 --- a/sportorg/modules/recovery/recovery_si_master_csv.py +++ b/sportorg/modules/recovery/recovery_si_master_csv.py @@ -17,9 +17,9 @@ :03;47;Su; 14:39:54;37;Su; 14:47:02;90;Su; 14:49:21; """ +import csv + from sportorg.common.otime import OTime -from sportorg.gui.dialogs.file_dialog import get_open_file_name -from sportorg.language import translate from sportorg.models.memory import ResultSportident, Split, race from sportorg.modules.sportident.fix_time_sicard_5 import fix_time from sportorg.utils.time import hhmmss_to_time @@ -31,15 +31,7 @@ race = race() -def recovery(): - file_name = get_open_file_name( - translate('Open SPORTident master station backup file'), - translate('CSV file (*.csv)'), - False, - ) - - text_file = open(file_name, 'r') - lines = text_file.readlines() +def recovery(file_name): separator = ';' @@ -48,24 +40,25 @@ def recovery(): hour=zero_time_val[0], minute=zero_time_val[1], sec=zero_time_val[2] ) - for line in lines: - tokens = line.split(separator) - if tokens[0] == 'No' or len(tokens) < 45: - continue + with open(file_name, encoding='cp1251') as csv_file: + spam_reader = csv.reader(csv_file, delimiter=separator) + for tokens in spam_reader: + if tokens[0] == 'No' or len(tokens) < 45: + continue - res = ResultSportident() - res.card_number = int(tokens[POS_CARD]) - res.start_time = hhmmss_to_time(tokens[POS_START]) - res.finish_time = hhmmss_to_time(tokens[POS_FINISH]) + res = ResultSportident() + res.card_number = int(tokens[POS_CARD]) + res.start_time = hhmmss_to_time(tokens[POS_START]) + res.finish_time = hhmmss_to_time(tokens[POS_FINISH]) - punch_count = int(tokens[POS_COUNT]) - existing_punches = (len(tokens) - POS_COUNT - 1) // 3 + punch_count = int(tokens[POS_COUNT]) + existing_punches = (len(tokens) - POS_COUNT - 1) // 3 - for i in range(min(punch_count, existing_punches)): - punch = Split() - punch.code = tokens[POS_COUNT + 3 * i + 1] - punch.time = hhmmss_to_time(tokens[POS_COUNT + 3 * i + 3]) - res.splits.append(punch) + for i in range(min(punch_count, existing_punches)): + punch = Split() + punch.code = tokens[POS_COUNT + 3 * i + 1] + punch.time = hhmmss_to_time(tokens[POS_COUNT + 3 * i + 3]) + res.splits.append(punch) - fix_time(res, zero_time) - race.results.append(res) + fix_time(res, zero_time) + race.results.append(res) diff --git a/sportorg/modules/recovery/recovery_sportorg_html.py b/sportorg/modules/recovery/recovery_sportorg_html.py index 9e617cd1..b766286b 100644 --- a/sportorg/modules/recovery/recovery_sportorg_html.py +++ b/sportorg/modules/recovery/recovery_sportorg_html.py @@ -8,35 +8,21 @@ from random import choices from tempfile import gettempdir -from sportorg.gui.dialogs.file_dialog import get_open_file_name -from sportorg.gui.dialogs.sportorg_import_dialog import SportOrgImportDialog -from sportorg.language import translate -from sportorg.modules.backup.json import get_races_from_file - -def recovery(): - file_name = get_open_file_name( - translate('Open SportOrg HTML file'), - translate('SportOrg HTML report (*.html)'), - False, - ) - - text_file = open(file_name, 'r', encoding='utf-8') - lines = text_file.readlines() - - for line in lines: - if line.find("var race = {\"courses\":") > -1: - json = line.strip()[11:-1] - - # save json to tmp file and op[en with standard import action - tmp_filename = os.path.join( - gettempdir(), - 'sportorg_' + ''.join(choices(string.ascii_letters, k=10)) + '.json', - ) - temp_file = open(tmp_filename, 'w') - temp_file.write(json) - temp_file.close() - - with open(tmp_filename) as f: - attr = get_races_from_file(f) - SportOrgImportDialog(*attr).exec_() +def recovery(file_name): + + with open(file_name, 'r', encoding='utf-8') as f: + for line in f.readlines(): + if line.find("var race = {\"courses\":") > -1: + json = line.strip()[11:-1] + + # save json to tmp file and op[en with standard import action + tmp_filename = os.path.join( + gettempdir(), + 'sportorg_' + ''.join(choices(string.ascii_letters, k=10)) + '.json', + ) + temp_file = open(tmp_filename, 'w') + temp_file.write(json) + temp_file.close() + return tmp_filename + return None diff --git a/sportorg/modules/recovery/recovery_sportorg_si_log.py b/sportorg/modules/recovery/recovery_sportorg_si_log.py index fec253de..e1ee27ba 100644 --- a/sportorg/modules/recovery/recovery_sportorg_si_log.py +++ b/sportorg/modules/recovery/recovery_sportorg_si_log.py @@ -28,9 +28,8 @@ end """ + from sportorg.common.otime import OTime -from sportorg.gui.dialogs.file_dialog import get_open_file_name -from sportorg.language import translate from sportorg.models.memory import ResultSportident, Split, race from sportorg.modules.sportident.fix_time_sicard_5 import fix_time from sportorg.utils.time import hhmmss_to_time @@ -38,52 +37,44 @@ race = race() -def recovery(): +def recovery(file_name): zero_time_val = race.get_setting('system_zero_time', (8, 0, 0)) zero_time = OTime( hour=zero_time_val[0], minute=zero_time_val[1], sec=zero_time_val[2] ) - file_name = get_open_file_name( - translate('Open SportOrg SI log file'), - translate('SportOrg SI log (*.log)'), - False, - ) - - text_file = open(file_name, 'r') - lines = text_file.readlines() - cur_res = ResultSportident() read_num = False read_start = False read_spl = False read_finish = False - for line in lines: - line = line.strip() - if read_num: - cur_res.card_number = int(line) - read_start = True - read_num = False - elif read_start: - cur_res.start_time = hhmmss_to_time(line) - read_start = False - read_finish = True - elif read_finish: - cur_res.finish_time = hhmmss_to_time(line) - read_finish = False - elif line == 'end': - fix_time(cur_res, zero_time) - race.results.append(cur_res) - cur_res = ResultSportident() - elif line == 'start': - read_num = True - elif line == 'split_start': - read_spl = True - elif line == 'split_end': - read_spl = False - elif read_spl: - spl = Split() - spl.code = line.split(' ')[0] - spl.time = hhmmss_to_time(line.split(' ')[1]) - cur_res.splits.append(spl) + with open(file_name) as f: + for line in f.readlines(): + line = line.strip() + if read_num: + cur_res.card_number = int(line) + read_start = True + read_num = False + elif read_start: + cur_res.start_time = hhmmss_to_time(line) + read_start = False + read_finish = True + elif read_finish: + cur_res.finish_time = hhmmss_to_time(line) + read_finish = False + elif line == 'end': + fix_time(cur_res, zero_time) + race.results.append(cur_res) + cur_res = ResultSportident() + elif line == 'start': + read_num = True + elif line == 'split_start': + read_spl = True + elif line == 'split_end': + read_spl = False + elif read_spl: + spl = Split() + spl.code = line.split(' ')[0] + spl.time = hhmmss_to_time(line.split(' ')[1]) + cur_res.splits.append(spl) From 5bf49ab3b589d08a71642b58b6080d215e7fc81c Mon Sep 17 00:00:00 2001 From: Sergei Date: Mon, 18 Dec 2023 15:39:29 +0500 Subject: [PATCH 06/12] Code formatting --- sportorg/modules/recovery/recovery_sportorg_html.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sportorg/modules/recovery/recovery_sportorg_html.py b/sportorg/modules/recovery/recovery_sportorg_html.py index b766286b..ec1076b5 100644 --- a/sportorg/modules/recovery/recovery_sportorg_html.py +++ b/sportorg/modules/recovery/recovery_sportorg_html.py @@ -19,7 +19,9 @@ def recovery(file_name): # save json to tmp file and op[en with standard import action tmp_filename = os.path.join( gettempdir(), - 'sportorg_' + ''.join(choices(string.ascii_letters, k=10)) + '.json', + 'sportorg_' + + ''.join(choices(string.ascii_letters, k=10)) + + '.json', ) temp_file = open(tmp_filename, 'w') temp_file.write(json) From c42a88ae45995fd10cac196378c6984020d613f8 Mon Sep 17 00:00:00 2001 From: Sergei Date: Mon, 18 Dec 2023 19:25:27 +0500 Subject: [PATCH 07/12] Formatting (windows: poe format) --- sportorg/modules/recovery/recovery_si_master_csv.py | 1 - sportorg/modules/recovery/recovery_sportorg_html.py | 1 - 2 files changed, 2 deletions(-) diff --git a/sportorg/modules/recovery/recovery_si_master_csv.py b/sportorg/modules/recovery/recovery_si_master_csv.py index c4021456..1a651404 100644 --- a/sportorg/modules/recovery/recovery_si_master_csv.py +++ b/sportorg/modules/recovery/recovery_si_master_csv.py @@ -32,7 +32,6 @@ def recovery(file_name): - separator = ';' zero_time_val = race.get_setting('system_zero_time', (8, 0, 0)) diff --git a/sportorg/modules/recovery/recovery_sportorg_html.py b/sportorg/modules/recovery/recovery_sportorg_html.py index ec1076b5..98fe5f7f 100644 --- a/sportorg/modules/recovery/recovery_sportorg_html.py +++ b/sportorg/modules/recovery/recovery_sportorg_html.py @@ -10,7 +10,6 @@ def recovery(file_name): - with open(file_name, 'r', encoding='utf-8') as f: for line in f.readlines(): if line.find("var race = {\"courses\":") > -1: From 1c907efd35f9bc6bf7114cebf6b67c71aa96bb7a Mon Sep 17 00:00:00 2001 From: Sergei Date: Mon, 18 Dec 2023 21:27:30 +0500 Subject: [PATCH 08/12] Recovery data from orgeo.ru CSV --- languages/ru_RU/LC_MESSAGES/sportorg.po | 6 + sportorg/gui/menu/actions.py | 12 ++ sportorg/gui/menu/menu.py | 4 + .../recovery/recovery_orgeo_finish_csv.py | 114 ++++++++++++++++++ 4 files changed, 136 insertions(+) create mode 100644 sportorg/modules/recovery/recovery_orgeo_finish_csv.py diff --git a/languages/ru_RU/LC_MESSAGES/sportorg.po b/languages/ru_RU/LC_MESSAGES/sportorg.po index 0021a859..9c8f82e7 100644 --- a/languages/ru_RU/LC_MESSAGES/sportorg.po +++ b/languages/ru_RU/LC_MESSAGES/sportorg.po @@ -1595,3 +1595,9 @@ msgstr "Файл CSV (*.csv)" msgid "Open SPORTident master station backup file" msgstr "Открыть файл CSV мастер-станции SPORTident" + +msgid "Orgeo.ru CSV" +msgstr "Файл финиша orgeo.ru, CSV" + +msgid "Open orgeo.ru finish CSV file" +msgstr "Открыть файл финиша orgeo.ru, CSV (https://orgeo.ru/event/export?event_id=XXX&sub_id=Y&format=excel_finish)" diff --git a/sportorg/gui/menu/actions.py b/sportorg/gui/menu/actions.py index ac0a4657..5544a2aa 100644 --- a/sportorg/gui/menu/actions.py +++ b/sportorg/gui/menu/actions.py @@ -61,6 +61,7 @@ from sportorg.modules.ocad import ocad from sportorg.modules.ocad.ocad import OcadImportException from sportorg.modules.recovery import ( + recovery_orgeo_finish_csv, recovery_si_master_csv, recovery_sportorg_html, recovery_sportorg_si_log, @@ -388,6 +389,17 @@ def execute(self): self.app.refresh() +class RecoveryOrgeoFinishCsvAction(Action, metaclass=ActionFactory): + def execute(self): + file_name = get_open_file_name( + translate('Open orgeo.ru finish CSV file'), + translate('CSV file (*.csv)'), + False, + ) + recovery_orgeo_finish_csv.recovery(file_name) + self.app.refresh() + + class AddObjectAction(Action, metaclass=ActionFactory): def execute(self): self.app.add_object() diff --git a/sportorg/gui/menu/menu.py b/sportorg/gui/menu/menu.py index fd22f56e..f6972126 100644 --- a/sportorg/gui/menu/menu.py +++ b/sportorg/gui/menu/menu.py @@ -80,6 +80,10 @@ def menu_list(): 'title': translate('SportOrg SI log'), 'action': 'RecoverySportorgSiLogAction', }, + { + 'title': translate('Orgeo.ru CSV'), + 'action': 'RecoveryOrgeoFinishCsvAction', + }, { 'title': translate('SportOrg HTML'), 'action': 'RecoverySportorgHtmlAction', diff --git a/sportorg/modules/recovery/recovery_orgeo_finish_csv.py b/sportorg/modules/recovery/recovery_orgeo_finish_csv.py new file mode 100644 index 00000000..bbbe5a23 --- /dev/null +++ b/sportorg/modules/recovery/recovery_orgeo_finish_csv.py @@ -0,0 +1,114 @@ +""" +Parse finish CSV from online-service orgeo.ru (2023) + +-- Format: +CSV, separator ";" +SPLITS: [hh:mm:ss|code|]* +П/п;Группа;Фамилия, имя участника;Команда;№;Номер чипа;Место;Результат;Отст.;Время старта;[TV;90cp;]Сплиты; + +-- Example: +1;Ж10;Лимонникова Анна;72_СШ №2 Кобелева;39;8510418;1;00:09:10;+00:00;12:33:00;00:01:41|59|00:00:55|60|00:01:14|61| +2;Ж10;Глухарева Светлана;72_СШ №2 Глухарева;35;2102481;2;00:11:06;+01:56;12:29:00;00:01:30|59|00:00:43|60|00:01:28|61| +18;Ж10;Радченко Милана;72_СШ №2 Кобелева;37;9111137;;не старт;;12:37:00; +33;Ж12;Аристова Надежда;55_Омская обл.;162;8517947;;непр.отмет.;;13:09:00;00:03:00|70| +""" +import csv + +from sportorg.models.memory import ( + Group, + Organization, + Person, + ResultSportident, + ResultStatus, + Split, + race, +) +from sportorg.utils.time import hhmmss_to_time + +POS_GROUP = 1 +POS_NAME = 2 +POS_TEAM = 3 +POS_BIB = 4 +POS_CARD = 5 +POS_RES = 7 +POS_START = 9 +POS_SPLITS = -1 + +DNS_STATUS = ['DNS', 'не старт'] +DSQ_STATUS = ['DSQ', 'непр.отмет.'] + +race = race() + + +def recovery(file_name): + encoding = 'cp1251' + separator = ';' + spl_separator = '|' + + with open(file_name, encoding=encoding) as csv_file: + spam_reader = csv.reader(csv_file, delimiter=separator) + for tokens in spam_reader: + if len(tokens) <= POS_START: + continue + + bib = tokens[POS_BIB] + if bib == '' or not bib.isdigit(): + continue + + name = tokens[POS_NAME] + person = Person() + spl_pos = name.find(' ') + if spl_pos > 0: + person.surname = name[:spl_pos] + person.name = name[spl_pos + 1 :] + else: + person.name = name + person.bib = int(bib) + + team_name = tokens[POS_TEAM] + team = race.find_team(team_name) + if not team: + team = Organization() + team.name = team_name + race.organizations.append(team) + person.organization = team + + group_name = tokens[POS_GROUP] + group = race.find_group(group_name) + if not group: + group = Group() + group.name = group_name + race.groups.append(group) + person.group = group + + if len(tokens[POS_START]) > 0: + person.start_time = hhmmss_to_time(tokens[POS_START]) + + res = ResultSportident() + res.person = person + if tokens[POS_CARD].isdigit(): + res.card_number = int(tokens[POS_CARD]) + res.start_time = hhmmss_to_time(tokens[POS_START]) + result = tokens[POS_RES] + if result.find(':') > 0: + result_value = hhmmss_to_time(result) + res.finish_time = res.start_time + result_value + else: + if result in DNS_STATUS: + res.status = ResultStatus.DID_NOT_START + elif result in DSQ_STATUS: + res.status = ResultStatus.DISQUALIFIED + + splits = tokens[POS_SPLITS] + if len(splits) > 1: + splits_array = splits.split(spl_separator) + cur_time = person.start_time + for i in range(len(splits_array) // 2): + split = Split() + cur_time += hhmmss_to_time(splits_array[i * 2]) + split.time = cur_time + split.code = int(splits_array[i * 2 + 1]) + res.splits.append(split) + + race.persons.append(person) + race.results.append(res) From 9806c1a34d52cba093efb2446ae1ea0c21907727 Mon Sep 17 00:00:00 2001 From: Sergei Date: Tue, 19 Dec 2023 15:09:36 +0500 Subject: [PATCH 09/12] Return types, 'with' for files --- .../modules/recovery/recovery_orgeo_finish_csv.py | 4 ++-- sportorg/modules/recovery/recovery_si_master_csv.py | 2 +- sportorg/modules/recovery/recovery_sportorg_html.py | 13 +++++-------- .../modules/recovery/recovery_sportorg_si_log.py | 2 +- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/sportorg/modules/recovery/recovery_orgeo_finish_csv.py b/sportorg/modules/recovery/recovery_orgeo_finish_csv.py index bbbe5a23..9f900c8e 100644 --- a/sportorg/modules/recovery/recovery_orgeo_finish_csv.py +++ b/sportorg/modules/recovery/recovery_orgeo_finish_csv.py @@ -40,7 +40,7 @@ race = race() -def recovery(file_name): +def recovery(file_name) -> None: encoding = 'cp1251' separator = ';' spl_separator = '|' @@ -88,7 +88,7 @@ def recovery(file_name): res.person = person if tokens[POS_CARD].isdigit(): res.card_number = int(tokens[POS_CARD]) - res.start_time = hhmmss_to_time(tokens[POS_START]) + res.start_time = person.start_time result = tokens[POS_RES] if result.find(':') > 0: result_value = hhmmss_to_time(result) diff --git a/sportorg/modules/recovery/recovery_si_master_csv.py b/sportorg/modules/recovery/recovery_si_master_csv.py index 1a651404..0a3cc86a 100644 --- a/sportorg/modules/recovery/recovery_si_master_csv.py +++ b/sportorg/modules/recovery/recovery_si_master_csv.py @@ -31,7 +31,7 @@ race = race() -def recovery(file_name): +def recovery(file_name) -> None: separator = ';' zero_time_val = race.get_setting('system_zero_time', (8, 0, 0)) diff --git a/sportorg/modules/recovery/recovery_sportorg_html.py b/sportorg/modules/recovery/recovery_sportorg_html.py index 98fe5f7f..78d4b9e4 100644 --- a/sportorg/modules/recovery/recovery_sportorg_html.py +++ b/sportorg/modules/recovery/recovery_sportorg_html.py @@ -9,7 +9,7 @@ from tempfile import gettempdir -def recovery(file_name): +def recovery(file_name) -> str: with open(file_name, 'r', encoding='utf-8') as f: for line in f.readlines(): if line.find("var race = {\"courses\":") > -1: @@ -18,12 +18,9 @@ def recovery(file_name): # save json to tmp file and op[en with standard import action tmp_filename = os.path.join( gettempdir(), - 'sportorg_' - + ''.join(choices(string.ascii_letters, k=10)) - + '.json', + f"sportorg_{''.join(choices(string.ascii_letters, k=10))}.json", ) - temp_file = open(tmp_filename, 'w') - temp_file.write(json) - temp_file.close() + with open(tmp_filename, 'w') as temp_file: + temp_file.write(json) + return tmp_filename - return None diff --git a/sportorg/modules/recovery/recovery_sportorg_si_log.py b/sportorg/modules/recovery/recovery_sportorg_si_log.py index e1ee27ba..3bcc9592 100644 --- a/sportorg/modules/recovery/recovery_sportorg_si_log.py +++ b/sportorg/modules/recovery/recovery_sportorg_si_log.py @@ -37,7 +37,7 @@ race = race() -def recovery(file_name): +def recovery(file_name) -> None: zero_time_val = race.get_setting('system_zero_time', (8, 0, 0)) zero_time = OTime( hour=zero_time_val[0], minute=zero_time_val[1], sec=zero_time_val[2] From 7d14da263d39e18f2957160364438689918fcf8d Mon Sep 17 00:00:00 2001 From: Sergei Date: Wed, 20 Dec 2023 12:01:22 +0500 Subject: [PATCH 10/12] Send race as a parameter of recovery functions --- sportorg/gui/menu/actions.py | 6 +++--- sportorg/modules/recovery/recovery_orgeo_finish_csv.py | 6 ++---- sportorg/modules/recovery/recovery_si_master_csv.py | 5 ++--- sportorg/modules/recovery/recovery_sportorg_html.py | 2 +- sportorg/modules/recovery/recovery_sportorg_si_log.py | 6 ++---- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/sportorg/gui/menu/actions.py b/sportorg/gui/menu/actions.py index 5544a2aa..1d51c771 100644 --- a/sportorg/gui/menu/actions.py +++ b/sportorg/gui/menu/actions.py @@ -374,7 +374,7 @@ def execute(self): translate('SportOrg SI log (*.log)'), False, ) - recovery_sportorg_si_log.recovery(file_name) + recovery_sportorg_si_log.recovery(file_name, race()) self.app.refresh() @@ -385,7 +385,7 @@ def execute(self): translate('CSV file (*.csv)'), False, ) - recovery_si_master_csv.recovery(file_name) + recovery_si_master_csv.recovery(file_name, race()) self.app.refresh() @@ -396,7 +396,7 @@ def execute(self): translate('CSV file (*.csv)'), False, ) - recovery_orgeo_finish_csv.recovery(file_name) + recovery_orgeo_finish_csv.recovery(file_name, race()) self.app.refresh() diff --git a/sportorg/modules/recovery/recovery_orgeo_finish_csv.py b/sportorg/modules/recovery/recovery_orgeo_finish_csv.py index 9f900c8e..6abb268f 100644 --- a/sportorg/modules/recovery/recovery_orgeo_finish_csv.py +++ b/sportorg/modules/recovery/recovery_orgeo_finish_csv.py @@ -21,7 +21,7 @@ ResultSportident, ResultStatus, Split, - race, + Race, ) from sportorg.utils.time import hhmmss_to_time @@ -37,10 +37,8 @@ DNS_STATUS = ['DNS', 'не старт'] DSQ_STATUS = ['DSQ', 'непр.отмет.'] -race = race() - -def recovery(file_name) -> None: +def recovery(file_name: str, race: Race) -> None: encoding = 'cp1251' separator = ';' spl_separator = '|' diff --git a/sportorg/modules/recovery/recovery_si_master_csv.py b/sportorg/modules/recovery/recovery_si_master_csv.py index 0a3cc86a..bdc80b8a 100644 --- a/sportorg/modules/recovery/recovery_si_master_csv.py +++ b/sportorg/modules/recovery/recovery_si_master_csv.py @@ -20,7 +20,7 @@ import csv from sportorg.common.otime import OTime -from sportorg.models.memory import ResultSportident, Split, race +from sportorg.models.memory import ResultSportident, Split, Race from sportorg.modules.sportident.fix_time_sicard_5 import fix_time from sportorg.utils.time import hhmmss_to_time @@ -28,10 +28,9 @@ POS_START = 15 POS_FINISH = 21 POS_COUNT = 44 -race = race() -def recovery(file_name) -> None: +def recovery(file_name: str, race: Race) -> None: separator = ';' zero_time_val = race.get_setting('system_zero_time', (8, 0, 0)) diff --git a/sportorg/modules/recovery/recovery_sportorg_html.py b/sportorg/modules/recovery/recovery_sportorg_html.py index 78d4b9e4..ae055db3 100644 --- a/sportorg/modules/recovery/recovery_sportorg_html.py +++ b/sportorg/modules/recovery/recovery_sportorg_html.py @@ -9,7 +9,7 @@ from tempfile import gettempdir -def recovery(file_name) -> str: +def recovery(file_name: str) -> str: with open(file_name, 'r', encoding='utf-8') as f: for line in f.readlines(): if line.find("var race = {\"courses\":") > -1: diff --git a/sportorg/modules/recovery/recovery_sportorg_si_log.py b/sportorg/modules/recovery/recovery_sportorg_si_log.py index 3bcc9592..f5ccc8e5 100644 --- a/sportorg/modules/recovery/recovery_sportorg_si_log.py +++ b/sportorg/modules/recovery/recovery_sportorg_si_log.py @@ -30,14 +30,12 @@ """ from sportorg.common.otime import OTime -from sportorg.models.memory import ResultSportident, Split, race +from sportorg.models.memory import ResultSportident, Split, Race from sportorg.modules.sportident.fix_time_sicard_5 import fix_time from sportorg.utils.time import hhmmss_to_time -race = race() - -def recovery(file_name) -> None: +def recovery(file_name: str, race: Race) -> None: zero_time_val = race.get_setting('system_zero_time', (8, 0, 0)) zero_time = OTime( hour=zero_time_val[0], minute=zero_time_val[1], sec=zero_time_val[2] From a14b4fd4baed529f0666e9367a82e08511e52e4a Mon Sep 17 00:00:00 2001 From: Sergei Date: Wed, 20 Dec 2023 12:07:44 +0500 Subject: [PATCH 11/12] Code formatting --- sportorg/modules/recovery/recovery_orgeo_finish_csv.py | 2 +- sportorg/modules/recovery/recovery_si_master_csv.py | 2 +- sportorg/modules/recovery/recovery_sportorg_si_log.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sportorg/modules/recovery/recovery_orgeo_finish_csv.py b/sportorg/modules/recovery/recovery_orgeo_finish_csv.py index 6abb268f..ff5f55cb 100644 --- a/sportorg/modules/recovery/recovery_orgeo_finish_csv.py +++ b/sportorg/modules/recovery/recovery_orgeo_finish_csv.py @@ -18,10 +18,10 @@ Group, Organization, Person, + Race, ResultSportident, ResultStatus, Split, - Race, ) from sportorg.utils.time import hhmmss_to_time diff --git a/sportorg/modules/recovery/recovery_si_master_csv.py b/sportorg/modules/recovery/recovery_si_master_csv.py index bdc80b8a..706e2cee 100644 --- a/sportorg/modules/recovery/recovery_si_master_csv.py +++ b/sportorg/modules/recovery/recovery_si_master_csv.py @@ -20,7 +20,7 @@ import csv from sportorg.common.otime import OTime -from sportorg.models.memory import ResultSportident, Split, Race +from sportorg.models.memory import Race, ResultSportident, Split from sportorg.modules.sportident.fix_time_sicard_5 import fix_time from sportorg.utils.time import hhmmss_to_time diff --git a/sportorg/modules/recovery/recovery_sportorg_si_log.py b/sportorg/modules/recovery/recovery_sportorg_si_log.py index f5ccc8e5..ab6c5fda 100644 --- a/sportorg/modules/recovery/recovery_sportorg_si_log.py +++ b/sportorg/modules/recovery/recovery_sportorg_si_log.py @@ -30,7 +30,7 @@ """ from sportorg.common.otime import OTime -from sportorg.models.memory import ResultSportident, Split, Race +from sportorg.models.memory import Race, ResultSportident, Split from sportorg.modules.sportident.fix_time_sicard_5 import fix_time from sportorg.utils.time import hhmmss_to_time From 3a42de5fde2b62c2952a4e7dfa6e3bcac219666c Mon Sep 17 00:00:00 2001 From: Sergei Date: Wed, 20 Dec 2023 12:11:19 +0500 Subject: [PATCH 12/12] Code formatting2 --- sportorg/modules/recovery/recovery_sportorg_html.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sportorg/modules/recovery/recovery_sportorg_html.py b/sportorg/modules/recovery/recovery_sportorg_html.py index ae055db3..245da3c6 100644 --- a/sportorg/modules/recovery/recovery_sportorg_html.py +++ b/sportorg/modules/recovery/recovery_sportorg_html.py @@ -24,3 +24,4 @@ def recovery(file_name: str) -> str: temp_file.write(json) return tmp_filename + return ""