def queue_service_class_reports(): from kardboard.app import app from kardboard.models import ServiceClassRecord, ServiceClassSnapshot from kardboard.util import now, month_ranges logger = queue_service_class_reports.get_logger() report_groups = app.config.get('REPORT_GROUPS', {}) group_slugs = report_groups.keys() group_slugs.append('all') for slug in group_slugs: logger.info("ServiceClassSnapshot: %s" % slug) ServiceClassSnapshot.calculate(slug) for x in [1, 3, 6, 9, 12]: start = now() months_ranges = month_ranges(start, x) start_date = months_ranges[0][0] end_date = months_ranges[-1][1] try: logger.info("ServiceClassRecord: %s %s - %s" % (slug, start_date, end_date)) ServiceClassRecord.calculate( start_date=start_date, end_date=end_date, group=slug, ) except Exception, e: msg = "ERROR: Couldn't calc record: %s / %s / %s" % \ (slug, start_date, end_date) log_exception(e, msg)
def report_service_class(group="all", months=None): from kardboard.app import app service_class_order = app.config.get("SERVICE_CLASSES", {}).keys() service_class_order.sort() service_classes = [app.config["SERVICE_CLASSES"][k] for k in service_class_order] if months is None: # We want the current report try: scr = ServiceClassSnapshot.objects.get(group=group) except ServiceClassSnapshot.DoesNotExist: scr = ServiceClassSnapshot.calculate(group=group) time_range = "current" else: start = now() months_ranges = month_ranges(start, months) start_date = months_ranges[0][0] end_date = months_ranges[-1][1] try: scr = ServiceClassRecord.objects.get(group=group, start_date=start_date, end_date=end_date) except ServiceClassRecord.DoesNotExist: scr = ServiceClassRecord.calculate(group=group, start_date=start_date, end_date=end_date) time_range = "past %s months" % months context = { "title": "Service classes: %s" % time_range, "service_classes": service_classes, "data": scr.data, "updated_at": scr.updated_at, "version": VERSION, } return render_template("report-service-class.html", **context)
def report_service_class(group="all", months=None): from kardboard.app import app service_class_order = app.config.get('SERVICE_CLASSES', {}).keys() service_class_order.sort() service_classes = [ app.config['SERVICE_CLASSES'][k] for k in service_class_order ] if months is None: # We want the current report try: scr = ServiceClassSnapshot.objects.get( group=group, ) except ServiceClassSnapshot.DoesNotExist: scr = ServiceClassSnapshot.calculate( group=group, ) time_range = 'current' start_date = make_start_date(date=datetime.datetime.now()) end_date = make_end_date(date=datetime.datetime.now()) else: start = now() months_ranges = month_ranges(start, months) start_date = months_ranges[0][0] end_date = months_ranges[-1][1] try: scr = ServiceClassRecord.objects.get( group=group, start_date=start_date, end_date=end_date, ) except ServiceClassRecord.DoesNotExist: scr = ServiceClassRecord.calculate( group=group, start_date=start_date, end_date=end_date, ) time_range = 'past %s months' % months context = { 'title': "Service classes: %s" % time_range, 'service_classes': service_classes, 'data': scr.data, 'start_date': start_date, 'end_date': end_date, 'updated_at': scr.updated_at, 'version': VERSION, } return render_template('report-service-class.html', **context)
def report_service_class(group="all", months=None): from kardboard.app import app service_class_order = app.config.get('SERVICE_CLASSES', {}).keys() service_class_order.sort() service_classes = [ app.config['SERVICE_CLASSES'][k] for k in service_class_order ] if months is None: # We want the current report try: scr = ServiceClassSnapshot.objects.get(group=group, ) except ServiceClassSnapshot.DoesNotExist: scr = ServiceClassSnapshot.calculate(group=group, ) time_range = 'current' start_date = make_start_date(date=datetime.datetime.now()) end_date = make_end_date(date=datetime.datetime.now()) else: start = now() months_ranges = month_ranges(start, months) start_date = months_ranges[0][0] end_date = months_ranges[-1][1] try: scr = ServiceClassRecord.objects.get( group=group, start_date=start_date, end_date=end_date, ) except ServiceClassRecord.DoesNotExist: scr = ServiceClassRecord.calculate( group=group, start_date=start_date, end_date=end_date, ) time_range = 'past %s months' % months context = { 'title': "Service classes: %s" % time_range, 'service_classes': service_classes, 'data': scr.data, 'start_date': start_date, 'end_date': end_date, 'updated_at': scr.updated_at, 'version': VERSION, } return render_template('report-service-class.html', **context)
from kardboard.models import ServiceClassRecord, ServiceClassSnapshot ServiceClassSnapshot.drop_collection() ServiceClassRecord.drop_collection()