Commit 5fcf0767 authored by Jean-Marie Favreau's avatar Jean-Marie Favreau
Browse files

Embed the main structure in a class

parent 5bf31d51
......@@ -118,9 +118,28 @@ class Batch:
def get_first_datetime_with_shift(self):
return self.get_first_datetime() + self.required_shift
batches = []
class TimeSerie:
def __init__(self):
self.batches = []
def add_block(self, block):
if len(self.batches) == 0 or not self.batches[len(batches) - 1].concatenate_if_possible(block):
self.batches.append(Batch(block))
def to_csv(self):
result = ""
for b in self.batches:
i = 0
for bb in b.blocks:
if bb.is_valid():
for e in bb.records:
entry_csv = ";".join([str(v) for v in e])
result += '{:f};{:s}\n'.format(b.get_first_datetime_with_shift() + i / 100, entry_csv)
i += 1
return result
ts = TimeSerie()
with open(input_file, 'rb') as f_input:
while f_input:
......@@ -146,18 +165,14 @@ with open(input_file, 'rb') as f_input:
for entry in result.entries:
b.add_record(entry)
if len(batches) == 0 or not batches[len(batches) - 1].concatenate_if_possible(b):
batches.append(Batch(b))
ts.add_block(b)
except:
print("Skip end of file")
break
for b in batches:
i = 0
for bb in b.blocks:
if bb.is_valid():
for e in bb.records:
entry_csv = ";".join([str(v) for v in e])
print('{:f};{:s}'.format(b.get_first_datetime_with_shift() + i / 100, entry_csv))
i += 1
csv = ts.to_csv()
print(csv)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment