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
class RepartitionKeyEntryFile:
def __init__(self, data, operation_counter_list):
def __init__(self, data, operation_counter_list, file_type="csv"):
self.data = data
self.operation_counter_list = operation_counter_list
self.file_type = file_type
self.json = self._to_json()
def check(self):
......@@ -41,26 +42,23 @@ class RepartitionKeyEntryFile:
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 = {}
counter_list_from_file = self.data[0].split(";")
csv_file = csv.reader(self.data, delimiter=";")
line_count = 0
counter_list_from_file.remove("Horodate")
csv_file = csv.DictReader(self.data, delimiter=";")
for line in csv_file:
if line:
if line_count == 0:
line_count += 1
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
json[line.get("Horodate")] = []
for counter in counter_list_from_file:
json[line.get("Horodate")].append({"id": counter, "key": line.get(counter).replace(",", ".")})
return json
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