Skip to content
Extraits de code Groupes Projets
Valider 70069228 rédigé par Julien - Le Filament's avatar Julien - Le Filament
Parcourir les fichiers

Improve data reader

parent 4c06b437
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -6,9 +6,10 @@ from datetime import datetime ...@@ -6,9 +6,10 @@ from datetime import datetime
class RepartitionKeyEntryFile: class RepartitionKeyEntryFile:
def __init__(self, data, operation_counter_list): def __init__(self, data, operation_counter_list, file_type="csv"):
self.data = data self.data = data
self.operation_counter_list = operation_counter_list self.operation_counter_list = operation_counter_list
self.file_type = file_type
self.json = self._to_json() self.json = self._to_json()
def check(self): def check(self):
...@@ -41,26 +42,23 @@ class RepartitionKeyEntryFile: ...@@ -41,26 +42,23 @@ class RepartitionKeyEntryFile:
def _to_json(self): def _to_json(self):
""" """
make data ready to send { "horodatage": [{"id": "value"}, ....]} Build data { "horodatage": [{"id": "value"}, ....]}
"""
file_reader = {"csv": self._csv}
return file_reader.get(self.file_type)()
def _csv(self):
"""
read data from csv file { "horodatage": [{"id": "value"}, ....]}
""" """
json = {} json = {}
counter_list_from_file = self.data[0].split(";") counter_list_from_file = self.data[0].split(";")
csv_file = csv.reader(self.data, delimiter=";") counter_list_from_file.remove("Horodate")
line_count = 0 csv_file = csv.DictReader(self.data, delimiter=";")
for line in csv_file: for line in csv_file:
if line: json[line.get("Horodate")] = []
if line_count == 0: for counter in counter_list_from_file:
line_count += 1 json[line.get("Horodate")].append({"id": counter, "key": line.get(counter).replace(",", ".")})
continue
# line[0] is horodatage
json[line[0]] = []
line_count += 1
counter_count = 1
for counter in counter_list_from_file[1:]:
json[line[0]].append(
{"id": counter, "key": line[counter_count].replace(",", ".")}
)
counter_count += 1
return json return json
def data_to_send(self, agreement_id, send_empty_key=True): def data_to_send(self, agreement_id, send_empty_key=True):
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter