Exemple #1
0
def live_services_csv():
    results = service_api_client.get_live_services_data()["data"]
    live_services_columns = [
        "Service ID", "Organisation", "Organisation type", "Domains",
        "Service name", "Consent to research", "Main contact", "Contact email",
        "Contact mobile", "Live date", "Created date", "SMS volume intent",
        "Email volume intent", "Letter volume intent", "SMS sent this year",
        "Emails sent this year", "Letters sent this year"
    ]
    live_services_data = []
    live_services_data.append(live_services_columns)
    for row in results:
        live_services_data.append([
            row["service_id"],
            row["organisation_name"],
            row.get("organisation_type", "TODO"),
            ', '.join(row["domains"]),
            row["service_name"],
            row.get("consent_to_research", "TODO"),
            row["contact_name"],
            row["contact_email"],
            row["contact_mobile"],
            datetime.strptime(row["live_date"],
                              '%a, %d %b %Y %X %Z').strftime("%d-%m-%Y")
            if row["live_date"] else None,
            datetime.strptime(row["created_date"],
                              '%a, %d %b %Y %X %Z').strftime("%d-%m-%Y"),
            row.get("sms_volume_intent", "TODO"),
            row.get("email_volume_intent", "TODO"),
            row.get("letter_volume_intent", "TODO"),
            row["sms_totals"],
            row["email_totals"],
            row["letter_totals"],
        ])

    return Spreadsheet.from_rows(live_services_data).as_csv_data, 200, {
        'Content-Type':
        'text/csv; charset=utf-8',
        'Content-Disposition':
        'inline; filename="{} live services report.csv"'.format(
            format_date_numeric(
                datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%fZ")), )
    }
def live_services_csv():
    results = service_api_client.get_live_services_data()["data"]

    column_names = OrderedDict(
        [
            ("service_id", "Service ID"),
            ("organisation_name", "Organisation"),
            ("organisation_type", "Organisation type"),
            ("service_name", "Service name"),
            ("consent_to_research", "Consent to research"),
            ("contact_name", "Main contact"),
            ("contact_email", "Contact email"),
            ("contact_mobile", "Contact mobile"),
            ("live_date", "Live date"),
            ("sms_volume_intent", "SMS volume intent"),
            ("email_volume_intent", "Email volume intent"),
            ("letter_volume_intent", "Letter volume intent"),
            ("sms_totals", "SMS sent this year"),
            ("email_totals", "Emails sent this year"),
            ("letter_totals", "Letters sent this year"),
            ("free_sms_fragment_limit", "Free sms allowance"),
        ]
    )

    # initialise with header row
    live_services_data = [[x for x in column_names.values()]]

    for row in results:
        if row["live_date"]:
            row["live_date"] = datetime.strptime(row["live_date"], "%a, %d %b %Y %X %Z").strftime("%d-%m-%Y")

        live_services_data.append([row[api_key] for api_key in column_names.keys()])

    return (
        Spreadsheet.from_rows(live_services_data).as_csv_data,
        200,
        {
            "Content-Type": "text/csv; charset=utf-8",
            "Content-Disposition": 'inline; filename="{} live services report.csv"'.format(
                format_date_numeric(datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%fZ")),
            ),
        },
    )
def live_services_csv():
    results = service_api_client.get_live_services_data()["data"]

    column_names = OrderedDict([
        ('service_id', 'Service ID'),
        ('organisation_name', 'Organisation'),
        ('organisation_type', 'Organisation type'),
        ('service_name', 'Service name'),
        ('consent_to_research', 'Consent to research'),
        ('contact_name', 'Main contact'),
        ('contact_email', 'Contact email'),
        ('contact_mobile', 'Contact mobile'),
        ('live_date', 'Live date'),
        ('sms_volume_intent', 'SMS volume intent'),
        ('email_volume_intent', 'Email volume intent'),
        ('letter_volume_intent', 'Letter volume intent'),
        ('sms_totals', 'SMS sent this year'),
        ('email_totals', 'Emails sent this year'),
        ('letter_totals', 'Letters sent this year'),
        ('free_sms_fragment_limit', 'Free sms allowance'),
    ])

    # initialise with header row
    live_services_data = [[x for x in column_names.values()]]

    for row in results:
        if row['live_date']:
            row['live_date'] = datetime.strptime(
                row["live_date"], '%a, %d %b %Y %X %Z').strftime("%d-%m-%Y")

        live_services_data.append(
            [row[api_key] for api_key in column_names.keys()])

    return Spreadsheet.from_rows(live_services_data).as_csv_data, 200, {
        'Content-Type':
        'text/csv; charset=utf-8',
        'Content-Disposition':
        'inline; filename="{} live services report.csv"'.format(
            format_date_numeric(
                datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%fZ")), )
    }
def performance_platform_xlsx():
    results = service_api_client.get_live_services_data()["data"]
    live_services_columns = ["service_id", "agency", "service_name", "_timestamp", "service", "count"]
    live_services_data = []
    live_services_data.append(live_services_columns)
    for row in results:
        live_services_data.append([
            row["service_id"],
            row["organisation_name"],
            row["service_name"],
            datetime.strptime(
                row["live_date"], '%a, %d %b %Y %X %Z'
            ).strftime("%Y-%m-%dT%H:%M:%S") + "Z" if row["live_date"] else None,
            "notification",
            1
        ])

    return Spreadsheet.from_rows(live_services_data).as_excel_file, 200, {
        'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        'Content-Disposition': 'attachment; filename="{} performance platform report.xlsx"'.format(
            format_date_numeric(datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%fZ")),
        )
    }