def build_last_month_GIR(): def _last_month_datespan(): today = datetime.date.today() first_of_this_month = datetime.date(day=1, month=today.month, year=today.year) last_month = first_of_this_month - datetime.timedelta(days=1) return DateSpan.from_month(last_month.month, last_month.year) last_month = _last_month_datespan() try: generator = GIRTableGenerator([last_month]) generator.build_table() except Exception as e: soft_assert(to=[settings.DATA_EMAIL], send_to_ops=False)(False, "Error in his month's GIR generation") # pass it so it gets logged in celery as an error as well raise e message = 'Global impact report generation for month {} is now ready. To download go to' \ ' http://www.commcarehq.org/hq/admin/download_gir/'.format( last_month ) send_HTML_email('GIR data is ready', settings.DATA_EMAIL, message, text_content=message)
def handle(self, *args, **options): datespan_list = [] for arg in args: month_year = dateutil.parser.parse(arg) datespan_list.append(DateSpan.from_month(month_year.month, month_year.year)) generator = GIRTableGenerator(datespan_list) print "Building GIR table... for time range {}".format(datespan_list) generator.build_table() print "Finished!"
def handle(self, month_years, **options): datespan_list = [] for arg in month_years: month_year = dateutil.parser.parse(arg) datespan_list.append(DateSpan.from_month(month_year.month, month_year.year)) generator = GIRTableGenerator(datespan_list) print("Building GIR table... for time range {}".format(datespan_list)) generator.build_table() print("Finished!")
def test_max_device_id(self): # test to make sure max device is properly calculated, and that phones are properly combined with patch( 'corehq.apps.data_analytics.gir_generator.get_domain_device_breakdown_es', new=self._fake_device_data): max_device = GIRTableGenerator.get_max_device( Domain(name='dummy'), 'month') self.assertEqual(max_device, 'mobile')
def build_last_month_GIR(): last_month = last_month_datespan() try: generator = GIRTableGenerator([last_month]) generator.build_table() except Exception as e: soft_assert(to=[settings.DATA_EMAIL], send_to_ops=False)(False, "Error in his month's GIR generation") # pass it so it gets logged in celery as an error as well raise e message = 'Global impact report generation for month {} is now ready. To download go to' \ ' http://www.commcarehq.org/hq/admin/download_gir/'.format( last_month ) send_HTML_email('GIR data is ready', settings.DATA_EMAIL, message, text_content=message)
def build_last_month_GIR(): def _last_month_datespan(): today = datetime.date.today() first_of_this_month = datetime.date(day=1, month=today.month, year=today.year) last_month = first_of_this_month - datetime.timedelta(days=1) return DateSpan.from_month(last_month.month, last_month.year) last_month = _last_month_datespan() generator = GIRTableGenerator([last_month]) generator.build_table() message = 'Global impact report generation for month {} is now ready. To download go to' \ ' http://www.commcarehq.org/hq/admin/download_gir/'.format( last_month ) send_HTML_email( 'GIR data is ready', settings.DATA_EMAIL, message, text_content=message )
def build_last_month_GIR(): def _last_month_datespan(): today = datetime.date.today() first_of_this_month = datetime.date(day=1, month=today.month, year=today.year) last_month = first_of_this_month - datetime.timedelta(days=1) return DateSpan.from_month(last_month.month, last_month.year) last_month = _last_month_datespan() generator = GIRTableGenerator([last_month]) generator.build_table() message = 'Global impact report generation for month {} is now ready. To download go to' \ ' http://www.commcarehq.org/hq/admin/download_gir/'.format( last_month ) send_HTML_email('GIR data is ready', settings.DATA_EMAIL, message, text_content=message)
def test_max_device_id(self): # test to make sure max device is properly calculated, and that phones are properly combined with patch('corehq.apps.data_analytics.gir_generator.get_domain_device_breakdown_es', new=self._fake_device_data): max_device = GIRTableGenerator.get_max_device(Domain(name='dummy'), 'month') self.assertEqual(max_device, 'mobile')