Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

## Relacionado

*Puedes ver todas las [posibles palabras para accionesa automáticas con el mensaje](https://help.github.com/articles/closing-issues-using-keywords/)*
- Puedes ver todas las [posibles palabras para accionesa automáticas con el mensaje](https://help.github.com/articles/closing-issues-using-keywords/)*
- Origen de la tarea: TASK-

## Checklist

Expand Down
15 changes: 12 additions & 3 deletions mesures/f1.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,12 @@ def writer(self):

existing_files = os.listdir('/tmp')
if existing_files:
versions = [int(f.split('.')[1]) for f in existing_files if self.zip_filename.split('.')[0] in f]
if versions:
self.version = max(versions) + 1
zip_versions = [int(f.split('.')[1]) for f in existing_files if self.zip_filename.split('.')[0] in f and '.zip' in f]
if zip_versions:
self.version = max(zip_versions) + 1

zip_measures_date = self.measures_date
zip_version = self.version
zipped_file = ZipFile(os.path.join('/tmp', self.zip_filename), 'w')
while daymin <= daymax:
di = daymin
Expand All @@ -161,6 +163,11 @@ def writer(self):
dataf = self.file[(self.file['timestamp'] >= di) & (self.file['timestamp'] < df)]
# Avoid to generate file if dataframe is empty
if len(dataf):
existing_files = os.listdir('/tmp')
if existing_files:
versions = [int(f.split('.')[1]) for f in existing_files if self.filename.split('.')[0] in f and '.zip' not in f]
if versions:
self.version = max(versions) + 1
file_path = os.path.join('/tmp', self.filename)
kwargs = {'sep': ';',
'header': False,
Expand All @@ -175,4 +182,6 @@ def writer(self):

daymin = df
zipped_file.close()
self.measures_date = zip_measures_date
self.version = zip_version
return zipped_file.filename
15 changes: 12 additions & 3 deletions mesures/f1qh.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ def writer(self):

existing_files = os.listdir('/tmp')
if existing_files:
versions = [int(f.split('.')[1]) for f in existing_files if self.zip_filename.split('.')[0] in f]
if versions:
self.version = max(versions) + 1
zip_versions = [int(f.split('.')[1]) for f in existing_files if self.zip_filename.split('.')[0] in f and '.zip' in f]
if zip_versions:
self.version = max(zip_versions) + 1

zip_measures_date = self.measures_date
zip_version = self.version
zipped_file = ZipFile(os.path.join('/tmp', self.zip_filename), 'w')
while daymin <= daymax:
di = daymin
Expand All @@ -81,6 +83,11 @@ def writer(self):
dataf = self.file[(self.file['timestamp'] >= di) & (self.file['timestamp'] < df)]
# Avoid to generate file if dataframe is empty
if len(dataf):
existing_files = os.listdir('/tmp')
if existing_files:
versions = [int(f.split('.')[1]) for f in existing_files if self.filename.split('.')[0] in f and '.zip' not in f]
if versions:
self.version = max(versions) + 1
file_path = os.path.join('/tmp', self.filename)
kwargs = {'sep': ';',
'header': False,
Expand All @@ -95,4 +102,6 @@ def writer(self):

daymin = df
zipped_file.close()
self.measures_date = zip_measures_date
self.version = zip_version
return zipped_file.filename
9 changes: 4 additions & 5 deletions mesures/f5d.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,10 @@ def writer(self):
:return: file path of generated F5D File
"""
existing_files = os.listdir('/tmp')
if self.default_compression != 'zip':
if existing_files:
versions = [int(f.split('.')[1]) for f in existing_files if self.filename.split('.')[0] in f and '.zip' not in f]
if versions:
self.version = max(versions) + 1
if existing_files and self.default_compression != 'zip':
versions = [int(f.split('.')[1]) for f in existing_files if self.filename.split('.')[0] in f and '.zip' not in f]
if versions:
self.version = max(versions) + 1

file_path = os.path.join('/tmp', self.filename)
kwargs = {'sep': ';',
Expand Down
12 changes: 11 additions & 1 deletion mesures/mcil345.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ def writer(self):
daymin = self.file['timestamp'].min()
daymax = self.file['timestamp'].max()
self.measures_date = daymin
existing_files = os.listdir('/tmp')
if existing_files:
zip_versions = [int(f.split('.')[1]) for f in existing_files if self.zip_filename.split('.')[0] in f and '.zip' in f]
if zip_versions:
self.version = max(zip_versions) + 1

zip_measures_date = self.measures_date
zip_version = self.version
zipped_file = ZipFile(os.path.join('/tmp', self.zip_filename), 'w')
while daymin <= daymax:
di = daymin
Expand All @@ -160,7 +168,7 @@ def writer(self):
if len(dataf):
existing_files = os.listdir('/tmp')
if existing_files:
versions = [int(f.split('.')[1]) for f in existing_files if self.zip_filename.split('.')[0] in f]
versions = [int(f.split('.')[1]) for f in existing_files if self.filename.split('.')[0] in f and '.zip' not in f]
if versions:
self.version = max(versions) + 1

Expand All @@ -178,4 +186,6 @@ def writer(self):

daymin = df
zipped_file.close()
self.measures_date = zip_measures_date
self.version = zip_version
return zipped_file.filename
12 changes: 11 additions & 1 deletion mesures/mcil345qh.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ def writer(self):
daymin = self.file['timestamp'].min()
daymax = self.file['timestamp'].max()
self.measures_date = daymin
existing_files = os.listdir('/tmp')
if existing_files:
zip_versions = [int(f.split('.')[1]) for f in existing_files if self.zip_filename.split('.')[0] in f and '.zip' in f]
if zip_versions:
self.version = max(zip_versions) + 1

zip_measures_date = self.measures_date
zip_version = self.version
zipped_file = ZipFile(os.path.join('/tmp', self.zip_filename), 'w')
while daymin <= daymax:
di = daymin
Expand All @@ -80,7 +88,7 @@ def writer(self):
if len(dataf):
existing_files = os.listdir('/tmp')
if existing_files:
versions = [int(f.split('.')[1]) for f in existing_files if self.zip_filename.split('.')[0] in f]
versions = [int(f.split('.')[1]) for f in existing_files if self.filename.split('.')[0] in f and '.zip' not in f]
if versions:
self.version = max(versions) + 1

Expand All @@ -98,4 +106,6 @@ def writer(self):

daymin = df
zipped_file.close()
self.measures_date = zip_measures_date
self.version = zip_version
return zipped_file.filename
13 changes: 12 additions & 1 deletion mesures/p1.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(self, data, distributor=None, compression='bz2', columns=COLUMNS, v
self.version = version
self.distributor = distributor
self.default_compression = compression
self.measures_date = None

def __repr__(self):
return "{}: {} kWh".format(self.filename, self.total)
Expand Down Expand Up @@ -141,6 +142,14 @@ def writer(self):
daymin = self.file['timestamp'].min()
daymax = self.file['timestamp'].max()
self.measures_date = daymin
existing_files = os.listdir('/tmp')
if existing_files:
zip_versions = [int(f.split('.')[1]) for f in existing_files if self.zip_filename.split('.')[0] in f and '.zip' in f]
if zip_versions:
self.version = max(zip_versions) + 1

zip_measures_date = self.measures_date
zip_version = self.version
zipped_file = ZipFile(os.path.join('/tmp', self.zip_filename), 'w')
while daymin <= daymax:
di = daymin
Expand All @@ -150,7 +159,7 @@ def writer(self):
if len(dataf):
existing_files = os.listdir('/tmp')
if existing_files:
versions = [int(f.split('.')[1]) for f in existing_files if self.zip_filename.split('.')[0] in f]
versions = [int(f.split('.')[1]) for f in existing_files if self.filename.split('.')[0] in f and '.zip' not in f]
if versions:
self.version = max(versions) + 1
# dataf['timestamp'] = dataf['timestamp'].apply(lambda x: x.strftime(DATETIME_HOUR_MASK))
Expand All @@ -169,6 +178,8 @@ def writer(self):

daymin = df
zipped_file.close()
self.measures_date = zip_measures_date
self.version = zip_version
new_zip_filename = os.path.join('/tmp', self.zip_filename)
os.rename(zipped_file.filename, new_zip_filename)
zipped_file.filename = new_zip_filename
Expand Down
2 changes: 1 addition & 1 deletion mesures/p1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def writer(self):
"""
existing_files = os.listdir('/tmp')
if existing_files:
versions = [int(f.split('.')[1]) for f in existing_files if self.filename.split('.')[0] in f]
versions = [int(f.split('.')[1]) for f in existing_files if self.filename.split('.')[0] in f and '.zip' not in f]
if versions:
self.version = max(versions) + 1

Expand Down
12 changes: 11 additions & 1 deletion mesures/p2.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ def writer(self):
daymin = self.file['timestamp'].min()
daymax = self.file['timestamp'].max()
self.measures_date = daymin
existing_files = os.listdir('/tmp')
if existing_files:
zip_versions = [int(f.split('.')[1]) for f in existing_files if self.zip_filename.split('.')[0] in f and '.zip' in f]
if zip_versions:
self.version = max(zip_versions) + 1

zip_measures_date = self.measures_date
zip_version = self.version
zipped_file = ZipFile(os.path.join('/tmp', self.zip_filename), 'w')
while daymin <= daymax:
di = daymin
Expand All @@ -76,7 +84,7 @@ def writer(self):
if len(dataf):
existing_files = os.listdir('/tmp')
if existing_files:
versions = [int(f.split('.')[1]) for f in existing_files if self.zip_filename.split('.')[0] in f]
versions = [int(f.split('.')[1]) for f in existing_files if self.filename.split('.')[0] in f and '.zip' not in f]
if versions:
self.version = max(versions) + 1

Expand All @@ -94,4 +102,6 @@ def writer(self):

daymin = df
zipped_file.close()
self.measures_date = zip_measures_date
self.version = zip_version
return zipped_file.filename
8 changes: 3 additions & 5 deletions mesures/p2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ def __init__(self, data, distributor=None, comer=None, compression='bz2', column

@property
def filename(self):
filename = "{prefix}_{distributor}_{comer}_{measures_date}_{timestamp}.{version}".format(
filename = "{prefix}_{distributor}_{comer}_{timestamp}.{version}".format(
prefix=self.prefix, distributor=self.distributor, comer=self.comer,
measures_date=self.measures_date[:10].replace('/', ''),
timestamp=self.generation_date.strftime('%Y%m%d'), version=self.version
)
if self.default_compression:
Expand All @@ -33,9 +32,8 @@ def filename(self):

@property
def zip_filename(self):
return "{prefix}_{distributor}_{comer}_{measures_date}_{timestamp}.{version}.zip".format(
return "{prefix}_{distributor}_{comer}_{timestamp}.{version}.zip".format(
prefix=self.prefix, distributor=self.distributor, comer=self.comer,
measures_date=self.measures_date[:10].replace('/', ''),
timestamp=self.generation_date.strftime(SIMPLE_DATE_MASK),
version=self.version
)
Expand All @@ -46,7 +44,7 @@ def writer(self):
"""
existing_files = os.listdir('/tmp')
if existing_files:
versions = [int(f.split('.')[1]) for f in existing_files if self.filename.split('.')[0] in f]
versions = [int(f.split('.')[1]) for f in existing_files if self.filename.split('.')[0] in f and '.zip' not in f]
if versions:
self.version = max(versions) + 1

Expand Down
2 changes: 1 addition & 1 deletion mesures/p5d.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def writer(self):
"""
existing_files = os.listdir('/tmp')
if existing_files:
versions = [int(f.split('.')[1]) for f in existing_files if self.filename.split('.')[0] in f]
versions = [int(f.split('.')[1]) for f in existing_files if self.filename.split('.')[0] in f and '.zip' not in f]
if versions:
self.version = max(versions) + 1

Expand Down
Loading