Skip to content

Commit

Permalink
Zippeo de valores DTA
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaslavandeira committed Dec 4, 2018
1 parent afc75f4 commit 37e9045
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
14 changes: 8 additions & 6 deletions series_tiempo_ar_api/apps/dump/generator/dta.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django_datajsonar.models import Node

from series_tiempo_ar_api.apps.dump.generator import constants
from series_tiempo_ar_api.apps.dump.models import DumpFile, GenerateDumpTask
from series_tiempo_ar_api.apps.dump.models import DumpFile, GenerateDumpTask, ZipDumpFile


class DtaGenerator:
Expand All @@ -25,15 +25,17 @@ def generate_dump(self, dump_name):
file_name=dump_name,
node=self.node).last()
df = pd.read_csv(dump_file.file)
if dump_file.file_name == DumpFile.FILENAME_VALUES:
if dump_name == DumpFile.FILENAME_VALUES:
df = df[constants.STATA_VALUES_COLS]

with FileWrapper(self.file_name(dump_file)) as f:
save_to_dta(df, f.filepath)
self.task.dumpfile_set.create(file_type=DumpFile.TYPE_DTA,
file_name=dump_name,
node=dump_file.node,
file=File(open(f.filepath, 'rb')))
dump = self.task.dumpfile_set.create(file_type=DumpFile.TYPE_DTA,
file_name=dump_name,
node=dump_file.node,
file=File(open(f.filepath, 'rb')))
if (dump_name, DumpFile.TYPE_DTA) in DumpFile.ZIP_FILES:
ZipDumpFile.create_from_dump_file(dump, f.filepath)

def file_name(self, dump_file: DumpFile):
return f'{dump_file.node}-{dump_file.file_name}-{dump_file.id}.dta'
Expand Down
1 change: 1 addition & 0 deletions series_tiempo_ar_api/apps/dump/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class DumpFile(models.Model):
(FILENAME_FULL, TYPE_CSV),
(FILENAME_VALUES, TYPE_CSV),
(FILENAME_FULL, TYPE_SQL),
(FILENAME_VALUES, TYPE_DTA),
)

file_type = models.CharField(max_length=12, choices=TYPE_CHOICES, default=TYPE_CSV)
Expand Down

0 comments on commit 37e9045

Please sign in to comment.