Exemplo n.º 1
0
def get_dashboard_partials(service_id):
    all_statistics = template_statistics_client.get_template_statistics_for_service(
        service_id, limit_days=7)
    template_statistics = aggregate_template_usage(all_statistics)
    stats = aggregate_notifications_stats(all_statistics)
    column_width, max_notifiction_count = get_column_properties(3)

    dashboard_totals = get_dashboard_totals(stats),
    highest_notification_count = max(
        sum(value[key] for key in {'requested', 'failed', 'delivered'})
        for key, value in dashboard_totals[0].items())
    free_sms_allowance = billing_api_client.get_free_sms_fragment_limit_for_year(
        current_service.id,
        get_current_financial_year(),
    )
    yearly_usage = billing_api_client.get_service_usage(
        service_id,
        get_current_financial_year(),
    )
    return {
        'upcoming':
        render_template('views/dashboard/_upcoming.html', ),
        'inbox':
        render_template(
            'views/dashboard/_inbox.html',
            inbound_sms_summary=(
                service_api_client.get_inbound_sms_summary(service_id)
                if current_service.has_permission('inbound_sms') else None),
        ),
        'totals':
        render_template(
            'views/dashboard/_totals.html',
            service_id=service_id,
            statistics=dashboard_totals[0],
            column_width=column_width,
            smaller_font_size=(highest_notification_count >
                               max_notifiction_count),
        ),
        'template-statistics':
        render_template(
            'views/dashboard/template-statistics.html',
            template_statistics=template_statistics,
            most_used_template_count=max(
                [row['count'] for row in template_statistics] or [0]),
        ),
        'jobs':
        render_template(
            'views/dashboard/_jobs.html',
            jobs=current_service.immediate_jobs,
        ),
        'usage':
        render_template(
            'views/dashboard/_usage.html',
            column_width=column_width,
            **calculate_usage(yearly_usage, free_sms_allowance),
        ),
    }
Exemplo n.º 2
0
def get_dashboard_partials(service_id):
    all_statistics = template_statistics_client.get_template_statistics_for_service(
        service_id, limit_days=7)
    template_statistics = aggregate_template_usage(all_statistics)

    scheduled_jobs, immediate_jobs = [], []
    if job_api_client.has_jobs(service_id):
        scheduled_jobs = job_api_client.get_scheduled_jobs(service_id)
        immediate_jobs = [
            add_rate_to_job(job)
            for job in job_api_client.get_immediate_jobs(service_id)
        ]

    stats = aggregate_notifications_stats(all_statistics)
    column_width, max_notifiction_count = get_column_properties(
        number_of_columns=(
            3 if current_service.has_permission('letter') else 2))
    dashboard_totals = get_dashboard_totals(stats),
    highest_notification_count = max(
        sum(value[key] for key in {'requested', 'failed', 'delivered'})
        for key, value in dashboard_totals[0].items())

    return {
        'upcoming':
        render_template('views/dashboard/_upcoming.html',
                        scheduled_jobs=scheduled_jobs),
        'inbox':
        render_template(
            'views/dashboard/_inbox.html',
            inbound_sms_summary=(
                service_api_client.get_inbound_sms_summary(service_id)
                if current_service.has_permission('inbound_sms') else None),
        ),
        'totals':
        render_template(
            'views/dashboard/_totals.html',
            service_id=service_id,
            statistics=dashboard_totals[0],
            column_width=column_width,
            smaller_font_size=(highest_notification_count >
                               max_notifiction_count),
        ),
        'template-statistics':
        render_template(
            'views/dashboard/template-statistics.html',
            template_statistics=template_statistics,
            most_used_template_count=max(
                [row['count'] for row in template_statistics] or [0]),
        ),
        'has_template_statistics':
        bool(template_statistics),
        'jobs':
        render_template('views/dashboard/_jobs.html', jobs=immediate_jobs),
        'has_jobs':
        bool(immediate_jobs)
    }
Exemplo n.º 3
0
def template_history(service_id):
    template_statistics = aggregate_usage(
        template_statistics_client.get_template_statistics_for_service(
            service_id))

    return render_template('views/dashboard/all-template-statistics.html',
                           template_statistics=template_statistics,
                           most_used_template_count=max(
                               [row['count'] for row in template_statistics]
                               or [0]))
Exemplo n.º 4
0
def template_history(service_id):
    template_statistics = aggregate_usage(
        template_statistics_client.get_template_statistics_for_service(service_id)
    )
    return render_template(
        'views/dashboard/all-template-statistics.html',
        template_statistics=template_statistics,
        most_used_template_count=max(
            [row['usage_count'] for row in template_statistics] or [0]
        )
    )
Exemplo n.º 5
0
def get_dashboard_partials(service_id):
    all_statistics = template_statistics_client.get_template_statistics_for_service(
        service_id, limit_days=7)
    template_statistics = aggregate_template_usage(all_statistics)

    scheduled_jobs, immediate_jobs = [], []
    if job_api_client.has_jobs(service_id):
        scheduled_jobs = job_api_client.get_scheduled_jobs(service_id)
        immediate_jobs = [
            add_rate_to_job(job)
            for job in job_api_client.get_immediate_jobs(service_id)
        ]

    stats = aggregate_notifications_stats(all_statistics)
    column_width, max_notifiction_count = get_column_properties(
        number_of_columns=(
            3 if current_service.has_permission("letter") else 2))
    dashboard_totals = (get_dashboard_totals(stats), )
    highest_notification_count = max(
        sum(value[key] for key in {"requested", "failed", "delivered"})
        for key, value in dashboard_totals[0].items())

    return {
        "upcoming":
        render_template("views/dashboard/_upcoming.html",
                        scheduled_jobs=scheduled_jobs),
        "totals":
        render_template(
            "views/dashboard/_totals.html",
            service_id=service_id,
            statistics=dashboard_totals[0],
            column_width=column_width,
            smaller_font_size=(highest_notification_count >
                               max_notifiction_count),
        ),
        "template-statistics":
        render_template(
            "views/dashboard/template-statistics.html",
            template_statistics=template_statistics,
            most_used_template_count=max(
                [row["count"] for row in template_statistics] or [0]),
        ),
        "has_template_statistics":
        bool(template_statistics),
        "jobs":
        render_template("views/dashboard/_jobs.html", jobs=immediate_jobs),
        "has_jobs":
        bool(immediate_jobs),
        "has_scheduled_jobs":
        bool(scheduled_jobs),
    }
Exemplo n.º 6
0
def get_dashboard_partials(service_id):
    # all but scheduled and cancelled
    statuses_to_display = job_api_client.JOB_STATUSES - {
        'scheduled', 'cancelled'
    }

    template_statistics = aggregate_usage(
        template_statistics_client.get_template_statistics_for_service(
            service_id, limit_days=7))

    scheduled_jobs = sorted(job_api_client.get_jobs(service_id,
                                                    statuses=['scheduled'
                                                              ])['data'],
                            key=lambda job: job['scheduled_for'])
    immediate_jobs = [
        add_rate_to_job(job) for job in job_api_client.get_jobs(
            service_id, limit_days=7, statuses=statuses_to_display)['data']
    ]
    service = service_api_client.get_detailed_service(service_id)

    return {
        'upcoming':
        render_template('views/dashboard/_upcoming.html',
                        scheduled_jobs=scheduled_jobs),
        'totals':
        render_template('views/dashboard/_totals.html',
                        service_id=service_id,
                        statistics=get_dashboard_totals(
                            service['data']['statistics'])),
        'template-statistics':
        render_template(
            'views/dashboard/template-statistics.html',
            template_statistics=template_statistics,
            most_used_template_count=max(
                [row['count'] for row in template_statistics] or [0]),
        ),
        'has_template_statistics':
        bool(template_statistics),
        'jobs':
        render_template('views/dashboard/_jobs.html', jobs=immediate_jobs),
        'has_jobs':
        bool(immediate_jobs),
        'usage':
        render_template(
            'views/dashboard/_usage.html',
            **calculate_usage(
                service_api_client.get_service_usage(service_id)['data'])),
    }
Exemplo n.º 7
0
def get_dashboard_partials(service_id):
    # all but scheduled and cancelled
    statuses_to_display = job_api_client.JOB_STATUSES - {'scheduled', 'cancelled'}

    template_statistics = aggregate_usage(
        template_statistics_client.get_template_statistics_for_service(service_id, limit_days=7)
    )

    scheduled_jobs = sorted(
        job_api_client.get_jobs(service_id, statuses=['scheduled'])['data'],
        key=lambda job: job['scheduled_for']
    )
    immediate_jobs = [
        add_rate_to_job(job)
        for job in job_api_client.get_jobs(service_id, limit_days=7, statuses=statuses_to_display)['data']
    ]
    service = service_api_client.get_detailed_service(service_id)

    return {
        'upcoming': render_template(
            'views/dashboard/_upcoming.html',
            scheduled_jobs=scheduled_jobs
        ),
        'totals': render_template(
            'views/dashboard/_totals.html',
            service_id=service_id,
            statistics=get_dashboard_totals(service['data']['statistics'])
        ),
        'template-statistics': render_template(
            'views/dashboard/template-statistics.html',
            template_statistics=template_statistics,
            most_used_template_count=max(
                [row['count'] for row in template_statistics] or [0]
            ),
        ),
        'has_template_statistics': bool(template_statistics),
        'jobs': render_template(
            'views/dashboard/_jobs.html',
            jobs=immediate_jobs
        ),
        'has_jobs': bool(immediate_jobs),
        'usage': render_template(
            'views/dashboard/_usage.html',
            **calculate_usage(service_api_client.get_service_usage(service_id)['data'])
        ),
    }
Exemplo n.º 8
0
def get_dashboard_partials(service_id):
    all_statistics = template_statistics_client.get_template_statistics_for_service(
        service_id, limit_days=7)
    template_statistics = aggregate_template_usage(all_statistics)
    stats = aggregate_notifications_stats(all_statistics)

    dashboard_totals = get_dashboard_totals(stats),
    free_sms_allowance = billing_api_client.get_free_sms_fragment_limit_for_year(
        current_service.id,
        get_current_financial_year(),
    )
    yearly_usage = billing_api_client.get_service_usage(
        service_id,
        get_current_financial_year(),
    )
    return {
        'upcoming':
        render_template('views/dashboard/_upcoming.html', ),
        'inbox':
        render_template('views/dashboard/_inbox.html', ),
        'totals':
        render_template(
            'views/dashboard/_totals.html',
            service_id=service_id,
            statistics=dashboard_totals[0],
        ),
        'template-statistics':
        render_template(
            'views/dashboard/template-statistics.html',
            template_statistics=template_statistics,
            most_used_template_count=max(
                [row['count'] for row in template_statistics] or [0]),
        ),
        'usage':
        render_template(
            'views/dashboard/_usage.html',
            **calculate_usage(yearly_usage, free_sms_allowance),
        ),
    }
Exemplo n.º 9
0
def get_dashboard_partials(service_id):

    template_statistics = aggregate_usage(
        template_statistics_client.get_template_statistics_for_service(service_id, limit_days=7)
    )

    jobs = add_rate_to_jobs(filter(
        lambda job: job['original_file_name'] != current_app.config['TEST_MESSAGE_FILENAME'],
        job_api_client.get_job(service_id, limit_days=7)['data']
    ))
    service = service_api_client.get_detailed_service(service_id)

    return {
        'totals': render_template(
            'views/dashboard/_totals.html',
            service_id=service_id,
            statistics=get_dashboard_totals(service['data']['statistics'])
        ),
        'template-statistics': render_template(
            'views/dashboard/template-statistics.html',
            template_statistics=template_statistics,
            most_used_template_count=max(
                [row['usage_count'] for row in template_statistics] or [0]
            ),
        ),
        'has_template_statistics': bool(template_statistics),
        'jobs': render_template(
            'views/dashboard/_jobs.html',
            jobs=jobs
        ),
        'has_jobs': bool(jobs),
        'usage': render_template(
            'views/dashboard/_usage.html',
            **calculate_usage(service_api_client.get_service_usage(service_id)['data'])
        ),
    }
Exemplo n.º 10
0
def get_dashboard_partials(service_id):
    # all but scheduled and cancelled
    statuses_to_display = job_api_client.JOB_STATUSES - {
        'scheduled', 'cancelled'
    }

    template_statistics = aggregate_usage(
        template_statistics_client.get_template_statistics_for_service(
            service_id, limit_days=7))

    scheduled_jobs = sorted(job_api_client.get_jobs(service_id,
                                                    statuses=['scheduled'
                                                              ])['data'],
                            key=lambda job: job['scheduled_for'])
    immediate_jobs = [
        add_rate_to_job(job) for job in job_api_client.get_jobs(
            service_id, limit_days=7, statuses=statuses_to_display)['data']
    ]
    service = service_api_client.get_detailed_service(service_id)
    column_width, max_notifiction_count = get_column_properties(
        number_of_columns=(
            3 if 'letter' in current_service['permissions'] else 2))
    dashboard_totals = get_dashboard_totals(service['data']['statistics']),
    highest_notification_count = max(
        sum(value[key] for key in {'requested', 'failed', 'delivered'})
        for key, value in dashboard_totals[0].items())

    return {
        'upcoming':
        render_template('views/dashboard/_upcoming.html',
                        scheduled_jobs=scheduled_jobs),
        'inbox':
        render_template(
            'views/dashboard/_inbox.html',
            inbound_sms_summary=(
                service_api_client.get_inbound_sms_summary(service_id)
                if 'inbound_sms' in current_service['permissions'] else None),
        ),
        'totals':
        render_template(
            'views/dashboard/_totals.html',
            service_id=service_id,
            statistics=dashboard_totals[0],
            column_width=column_width,
            smaller_font_size=(highest_notification_count >
                               max_notifiction_count),
        ),
        'template-statistics':
        render_template(
            'views/dashboard/template-statistics.html',
            template_statistics=template_statistics,
            most_used_template_count=max(
                [row['count'] for row in template_statistics] or [0]),
        ),
        'has_template_statistics':
        bool(template_statistics),
        'jobs':
        render_template('views/dashboard/_jobs.html', jobs=immediate_jobs),
        'has_jobs':
        bool(immediate_jobs)
    }