def getMissingDates(data): dbManager = SharedMemoryManager.getInstance(); db = dbManager.query(); missing_dates = {}; today = DateTime.now(tzinfo=msia_tz); # date only state_by = 'state_code'; states = list(db['state'].find({},{'_id': 0, state_by: 1})); current_year = DateTime.getDateCategoryName(date=DateTime.now(tzinfo=msia_tz), element='year'); for rk in data: row = data[rk]; if rk not in missing_dates: missing_dates[rk] = []; dates = groupDates(params={'states': states, 'state_by': state_by}, data=row); for date in dates['missing']: end_date_of_month = DateTime.getDaysAgo(days_to_crawl=1, datefrom=DateTime.getNextMonth(DateTime.convertDateTimeFromString(date))); day_diff = DateTime.getDifferenceBetweenDuration([today, end_date_of_month]); if day_diff >= 0: date_str = DateTime.toString(today); else: date_str = DateTime.toString(end_date_of_month); if date_str not in dates['crawled']: missing_dates[rk].append(date_str); # Logger.v('day_diff', day_diff); # Logger.v('date', DateTime.getDaysAgo(days_to_crawl=1, datefrom=DateTime.getNextMonth(DateTime.convertDateTimeFromString(ed)))); missing_dates[rk] = sorted(list(set(missing_dates[rk])), reverse=True); return missing_dates;
def generateTemplate(params): result = {}; report_keys = fn.getNestedElement(params, 'keys.report', ['procurement', 'budget']); first_date = fn.getNestedElement(params, 'first_date'); last_date = fn.getNestedElement(params, 'last_date'); state_by = fn.getNestedElement(params, 'state_by'); states = fn.getNestedElement(params, 'states'); today = DateTime.now(tzinfo=msia_tz); # date only for rk in report_keys: if rk not in result: result[rk] = {}; for date in DateTime.getBetween([first_date, last_date], element='date')['order']: end_date_of_month = DateTime.getDaysAgo(days_to_crawl=1, datefrom=DateTime.getNextMonth(DateTime.convertDateTimeFromString(date))); year_month = date[:7]; day_diff = DateTime.getDifferenceBetweenDuration([today, end_date_of_month]); if day_diff >= 0: date_str = DateTime.toString(today); else: date_str = DateTime.toString(end_date_of_month); if date_str not in result[rk]: result[rk][date_str] = {}; result[rk][date_str].update({ 'date': date_str, }) for idx in range(0, len(states)): state = states[idx][state_by]; result[rk][date_str].update({ state: 0, }); return result;