Skip to content

Commit

Permalink
[caso_full] Data final de registros é sempre hoje
Browse files Browse the repository at this point in the history
  • Loading branch information
turicas committed Feb 20, 2021
1 parent 357e808 commit 518fa0f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
1 change: 0 additions & 1 deletion covid19br/spiders/corona_sp_spider.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import csv
import datetime
import io

import rows
Expand Down
15 changes: 9 additions & 6 deletions full.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import rows
from async_process_executor import AsyncProcessExecutor, Task
from rows.utils import load_schema
from rows.utils.date import date_range
from rows.utils.date import date_range, today
from tqdm import tqdm

from covid19br import demographics
Expand Down Expand Up @@ -42,10 +42,11 @@ def row_key(row):
return (row.place_type, row.state, row.city or None)


def get_data(input_filename):
def get_data(input_filename, start_date=None, end_date=None):
casos = read_cases(input_filename, order_by="date")
dates = sorted(set(c.date for c in casos))
start_date, end_date = dates[0], dates[-1]
start_date = start_date or dates[0]
end_date = end_date or dates[-1]
caso_by_key = defaultdict(list)
for caso in casos:
caso_by_key[row_key(caso)].append(caso)
Expand Down Expand Up @@ -105,8 +106,8 @@ def get_data(input_filename):
yield new_case


def get_data_greedy(input_filename):
return list(get_data(input_filename))
def get_data_greedy(input_filename, start_date=None, end_date=None):
return list(get_data(input_filename, start_date=start_date, end_date=end_date))


class CasoFullTaskExecutor(AsyncProcessExecutor):
Expand All @@ -117,8 +118,10 @@ def __init__(self, input_filenames, output_filename, *args, **kwargs):
self.progress = tqdm()

async def tasks(self):
start_date = None
end_date = today()
for filename in self.input_filenames:
yield Task(function=get_data_greedy, args=(filename,))
yield Task(function=get_data_greedy, args=(filename, start_date, end_date))

async def process(self, result):
write_row = self.writer.writerow
Expand Down

0 comments on commit 518fa0f

Please sign in to comment.