Changeset - 6173267a5536
[Not reviewed]
Dennis Fink - 7 years ago 2017-10-17 12:33:36
dennis.fink@c3l.lu
Update
6 files changed with 9 insertions and 252 deletions:
0 comments (0 inline, 0 general)
ennstatus/data/views.py
Show inline comments
 
# Ënnstatus
 
# Copyright (C) 2015  Dennis Fink
 
#
 
# This program is free software: you can redistribute it and/or modify
 
# it under the terms of the GNU General Public License as published by
 
# the Free Software Foundation, either version 3 of the License, or
 
# (at your option) any later version.
 
#
 
# This program is distributed in the hope that it will be useful,
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
#
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 

	
 
import json
 

	
 
from collections import defaultdict
 

	
 
from flask import Blueprint, jsonify
 

	
 
from ennstatus.status.functions import split_all_servers_to_types
 
from ennstatus.donate.functions import all_csv_to_dict, year_sum, month_sum
 

	
 
data_page = Blueprint('data', __name__)
 

	
 

	
 
@data_page.route('/worldmap')
 
def worldmap():
 
    servers = split_all_servers_to_types()
 
    countries = {}
 

	
 
    for key, value in servers.items():
 
        for server in value:
 
            if server.country not in countries:
 
                countries[server.country] = defaultdict(int)
 
            countries[server.country][server.type] += 1
 
            countries[server.country]['total'] += 1
 

	
 
    maximum = max(i['total'] for i in countries.values())
 

	
 
    countries['max'] = maximum
 

	
 
    return jsonify(countries)
 

	
 

	
 
@data_page.route('/year')
 
def yeardata():
 
    data = all_csv_to_dict()
 
    data = year_sum(data)
 
    datalist = []
 

	
 
    for key, values in data.items():
 
        datalist.append({"key": key, "value": float(values)})
 
    datalist.sort(key=lambda x: x["key"])
 

	
 
    return json.dumps(datalist)
 

	
 

	
 
@data_page.route('/month')
 
def monthdata():
 
    data = all_csv_to_dict()
 
    data = month_sum(data)
 
    data_list = []
 

	
 
    for key, values in data.items():
 
        data_list.append({"key": key, "value": float(values)})
 

	
 
    data_list.sort(key=lambda x: x["key"])
 

	
 
    return json.dumps(data_list)
ennstatus/donate/functions.py
Show inline comments
 
# Ënnstatus
 
# Copyright (C) 2015  Dennis Fink
 
#
 
# This program is free software: you can redistribute it and/or modify
 
# it under the terms of the GNU General Public License as published by
 
# the Free Software Foundation, either version 3 of the License, or
 
# (at your option) any later version.
 
#
 
# This program is distributed in the hope that it will be useful,
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
#
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 

	
 
import os
 
import os.path
 
import csv
 
import statistics
 

	
 
from collections import defaultdict
 

	
 
from babel.numbers import parse_decimal
 

	
 

	
 
def load_csv_file(file):
 

	
 
    with open(file, encoding='utf-8', newline='') as csvfile:
 
        csvreader = csv.reader(csvfile, delimiter=',')
 
        rows = list(csvreader)
 
    return rows
 

	
 

	
 
def load_csv(date):
 

	
 
    filename = '.'.join([date, 'csv'])
 
    path = os.path.join('donations', filename)
 

	
 
    for row in load_csv_file(path):
 
        yield row
 
    with open(path, encoding='utf-8', newline='') as csvfile:
 
        csvreader = csv.reader(csvfile, delimiter=',')
 

	
 
        for row in csvreader:
 
            yield row
 

	
 

	
 
def get_choices():
 

	
 
    files = os.listdir('donations')
 

	
 
    for file in files:
 
        if not file.startswith('.') \
 
           and file.endswith('.csv'):
 
            yield os.path.splitext(file)[0]
 

	
 

	
 
def get_all_csv():
 

	
 
    for file in os.listdir('donations'):
 
        path = os.path.join('donations', file)
 
        yield load_csv_file(path)
 

	
 

	
 
def get_all_rows():
 

	
 
    for csvfile in get_all_csv():
 
        for row in csvfile:
 
            yield row
 

	
 

	
 
def all_csv_to_dict():
 

	
 
    data = defaultdict(set)
 

	
 
    for row in get_all_rows():
 
        data[row[0]].add(parse_decimal(row[2], locale='de'))
 
    return data
 

	
 

	
 
def data_to_year(data):
 

	
 
    year_data = defaultdict(set)
 

	
 
    for date, values in data.items():
 
        year = date.split('-')[0]
 
        for value in values:
 
            year_data[year].add(value)
 

	
 
    return year_data
 

	
 

	
 
def data_to_month(data):
 

	
 
    month_data = defaultdict(set)
 

	
 
    for date, values in data.items():
 
        month = date.rsplit('-', maxsplit=1)[0]
 
        for value in values:
 
            month_data[month].add(value)
 

	
 
    return month_data
 

	
 

	
 
def year_sum(data):
 

	
 
    year_data = data_to_year(data)
 

	
 
    for year, values in year_data.items():
 
        year_data[year] = sum(values)
 

	
 
    return year_data
 

	
 

	
 
def month_sum(data):
 

	
 
    month_data = data_to_month(data)
 

	
 
    for month, values in month_data.items():
 
        month_data[month] = sum(values)
 

	
 
    return month_data
 

	
 

	
 
def get_all_years_mean(data):
 

	
 
    mean = set()
 
    year_data = year_sum(data)
 

	
 
    for year, values in year_data.items():
 
        mean.add(values)
 

	
 
    return statistics.mean(mean)
 

	
 

	
 
def get_months_mean(data):
 

	
 
    mean = set()
 
    month_data = month_sum(data)
 

	
 
    for year, values in month_data.items():
 
        mean.add(values)
 

	
 
    return statistics.mean(mean)
 

	
 

	
 
def get_best_year(data):
 

	
 
    year_data = year_sum(data)
 
    return max(year_data.items(), key=lambda x: x[1])
 

	
 

	
 
def get_best_month(data):
 

	
 
    month_data = month_sum(data)
 
    return max(month_data.items(), key=lambda x: x[1])
 

	
 

	
 
def get_highest_donation():
 

	
 
    data = all_csv_to_dict()
 

	
 
    for date, values in data.items():
 
        data[date] = max(values)
 

	
 
    return max(
 
        sorted(
 
            data.items(),
 
            key=lambda x: x[0],
 
            reverse=True
 
        ),
 
        key=lambda x: x[1]
 
    )
 

	
 

	
 
def get_median_donation():
 
    data = all_csv_to_dict()
 
    donations = []
 

	
 
    for value in data.values():
 
        donations.extend(value)
 

	
 
    return statistics.median(donations)
 

	
 

	
 
def get_mode_donation():
 
    data = all_csv_to_dict()
 
    donations = []
 

	
 
    for value in data.values():
 
        donations.extend(value)
 

	
 
    return statistics.mode(donations)
ennstatus/donate/views.py
Show inline comments
 
# Ënnstatus
 
# Copyright (C) 2015  Dennis Fink
 
#
 
# This program is free software: you can redistribute it and/or modify
 
# it under the terms of the GNU General Public License as published by
 
# the Free Software Foundation, either version 3 of the License, or
 
# (at your option) any later version.
 
#
 
# This program is distributed in the hope that it will be useful,
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
#
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 

	
 
import json
 

	
 
from flask import (Blueprint, render_template, request,
 
                   redirect, url_for, current_app)
 

	
 
from babel.numbers import parse_decimal, format_decimal
 

	
 
from ennstatus.donate.forms import DateForm
 
from ennstatus.donate.functions import (load_csv,
 
                                        get_choices,
 
                                        all_csv_to_dict,
 
                                        get_all_years_mean,
 
                                        get_months_mean,
 
                                        get_best_year,
 
                                        get_best_month,
 
                                        get_highest_donation,
 
                                        get_median_donation,
 
                                        get_mode_donation,
 
                                        )
 
from ennstatus.donate.functions import load_csv, get_choices
 

	
 
donate_page = Blueprint('donate', __name__)
 

	
 

	
 
@donate_page.route('/')
 
def index():
 
    return render_template('donate/index.html')
 

	
 

	
 
@donate_page.route('/received',
 
                   methods=('GET', 'POST'))
 
def received():
 

	
 
    current_app.logger.info('Handling received')
 
    form = DateForm()
 

	
 
    current_app.logger.debug('Creating choices')
 

	
 
    files = [name for name in get_choices()]
 
    files.sort()
 

	
 
    year_choices = list({name.split('-')[0] for name in files})
 
    year_choices.sort()
 
    form.year.choices = [(name, name) for name in year_choices]
 

	
 
    if not year_choices:
 
        current_app.logger.warn('No donations found!')
 
        return render_template('donate/received.html',
 
                               form=form, csv_file=None,
 
                               year=None, month=None, total=None)
 

	
 
    if request.method == 'POST':
 
        current_app.logger.debug('Validating form')
 
        if form.validate_on_submit():
 
            year = form.year.data
 
            month = form.month.data
 
            return redirect(url_for('donate.received', year=year, month=month))
 
    else:
 
        if 'year' in request.args and 'month' in request.args:
 
            year = request.args['year']
 
            month = request.args['month']
 
            form.year.data = year
 
            form.month.data = '{:02d}'.format(int(month))
 
            filename = '-'.join([year, month])
 
            if filename in files:
 
                current_app.logger.info('Showing date %s' % filename)
 
                csv_file = load_csv(filename)
 
            else:
 
                current_app.logger.warn('Date %s not found' % filename)
 
                return render_template('donate/received.html',
 
                                       form=form, csv_file=None,
 
                                       year=year, month=month, total=None)
 
        else:
 
            filename = files[-1]
 
            current_app.logger.info('Showing last date %s' % filename)
 
            year, month = filename.split('-')
 
            form.year.data = year
 
            form.month.data = '{:02d}'.format(int(month))
 
            csv_file = load_csv(filename)
 

	
 
        total = format_decimal(
 
            sum(
 
                parse_decimal(row[2], locale='de') for row in csv_file
 
            ),
 
            locale='de'
 
        )
 
        csv_file = load_csv(filename)
 

	
 
        current_app.logger.info('Return result')
 
        return render_template('donate/received.html',
 
                               form=form, csv_file=csv_file,
 
                               year=year, month=month, total=total)
 

	
 

	
 
@donate_page.route('/statistics')
 
def statistics():
 
    data = all_csv_to_dict()
 

	
 
    all_years_mean = format_decimal(
 
        get_all_years_mean(data),
 
        locale='de'
 
    )
 
    month_mean = format_decimal(
 
        get_months_mean(data),
 
        locale='de'
 
    )
 
    best_year = get_best_year(data)
 
    best_year = (best_year[0], format_decimal(best_year[1], locale='de'))
 

	
 
    best_month = get_best_month(data)
 
    best_month = (best_month[0], format_decimal(best_month[1], locale='de'))
 

	
 
    highest_donation = get_highest_donation()
 
    highest_donation = (highest_donation[0], format_decimal(highest_donation[1], locale='de'))
 

	
 
    median_donation = format_decimal(
 
        get_median_donation(),
 
        locale='de'
 
    )
 

	
 
    mode_donation = format_decimal(
 
        get_mode_donation(),
 
        locale='de'
 
    )
 

	
 
    dates = [name for name in get_choices()]
 
    dates.sort()
 

	
 
    last_default_date = dates[-1]
 
    first_default_date = dates[-12]
 

	
 
    return render_template('donate/statistics.html',
 
                           all_years_mean=all_years_mean,
 
                           month_mean=month_mean,
 
                           best_year=best_year,
 
                           best_month=best_month,
 
                           highest_donation=highest_donation,
 
                           median_donation=median_donation,
 
                           mode_donation=mode_donation,
 
                           dates=dates,
 
                           first_default_date=first_default_date,
 
                           last_default_date=last_default_date
 
                           )
ennstatus/static/js/barcharts.js
Show inline comments
 
@@ -56,107 +56,107 @@ function draw(ywidth, yheight, mwidth, m
 
			.attr("class", "y axis")
 
			.call(yaxis)
 
			.append("text")
 
			.attr("transform", "rotate(-90)")
 
			.attr("y", 6)
 
			.attr("dy", ".71em")
 
			.style("text-anchor", "end");
 

	
 
		yearchart.selectAll("rect")
 
			.data(data, key)
 
			.enter()
 
			.append("rect")
 
			.attr("class", "bar")
 
			.attr("x", function(d) {
 
				return xscale(d.key);
 
			})
 
			.attr("width", xscale.rangeBand())
 
			.attr("y", function(d) {
 
				return yscale(d.value);
 
			})
 
			.attr("height", function(d) {
 
				return yheight - yscale(d.value);
 
			})
 
			.attr("fill", function(d) {
 
				return "#00ae18";
 
			})
 
			.on("mouseover", tip.show)
 
			.on("mouseout", tip.hide)
 
			
 
	});
 
	d3.json("/data/month", function(err, data) {
 
		var firstdate = d3.select("#monthfirstdate").node().value;
 
		var lastdate = d3.select("#monthlastdate").node().value;
 
		var newdata = [];
 
		for (var key in data) {
 
			if (data[key]["key"] >= firstdate && data[key]["key"] <= lastdate) {
 
				console.log(key)
 
				newdata.push(data[key])
 
			}
 
		}
 

	
 
		var xscale = d3.scale.ordinal().rangeRoundBands([0, mwidth - (newdata.length - 3) * 5], .1);
 
		xscale.domain(newdata.map(function(d) { return d.key }));
 
		var yscale = d3.scale.linear().range([mheight, 0]);
 
		yscale.domain([0, d3.max(newdata, function(d) { return d.value; })]);
 

	
 
		var key = function(d) { return d.key; };
 
		var xaxis = d3.svg.axis()
 
			.scale(xscale)
 
			.orient("bottom");
 
		var yaxis = d3.svg.axis()
 
			.scale(yscale)
 
			.orient("left");
 

	
 
		monthchart.append("g")
 
			.attr("class", "x axis")
 
			.attr("transform", "translate(0, " + mheight + ")")
 
			.call(xaxis)
 
		monthchart.append("g")
 
			.attr("class", "y axis")
 
			.call(yaxis)
 
			.append("text")
 
			.attr("transform", "rotate(-90)")
 
			.attr("y", 6)
 
			.attr("dy", ".71em")
 
			.style("text-anchor", "end");
 

	
 
		monthchart.selectAll("rect")
 
			.data(newdata, key)
 
			.enter()
 
			.append("rect")
 
			.attr("class", "bar")
 
			.attr("x", function(d) {
 
				return xscale(d.key);
 
			})
 
			.attr("width", xscale.rangeBand())
 
			.attr("y", function(d) {
 
				return yscale(d.value);
 
			})
 
			.attr("height", function(d) {
 
				return mheight - yscale(d.value);
 
			})
 
			.attr("fill", function(d) {
 
				return "#00ae18";
 
			})
 
			.on("mouseover", tip.show)
 
			.on("mouseout", tip.hide)
 
			
 
	});	
 
};
 

	
 
function redraw() {
 
	ywidth = document.getElementById('yearchart').offsetWidth - 40 -30;
 
	yheight = (ywidth / 2) - 20 - 30;
 
	mwidth = document.getElementById('monthchart').offsetWidth - 40 -30;
 
	mheight = (mwidth / 2) - 20 - 30;
 
	d3.select('svg').remove();
 
	d3.selectAll('svg').remove();
 
	setup(ywidth, yheight, mwidth, mheight);
 
}
 

	
 
var throttleTimer;
 
function throttle() {
 
	  window.clearTimeout(throttleTimer);
 
	      throttleTimer = window.setTimeout(function() {
 
		            redraw();
 
			        }, 200);
 
}
ennstatus/templates/base.html
Show inline comments
 
{# Ënnstatus
 
   Copyright (C) 2015  Dennis Fink
 

	
 
   This program is free software: you can redistribute it and/or modify
 
   it under the terms of the GNU General Public License as published by
 
   the Free Software Foundation, either version 3 of the License, or
 
   (at your option) any later version.
 

	
 
   This program is distributed in the hope that it will be useful,
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
   GNU General Public License for more details.
 

	
 
   You should have received a copy of the GNU General Public License
 
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
#}
 

	
 
{% extends "bootstrap/base.html" %}
 

	
 
{% import 'macros.html' as base_macros with context %}
 

	
 
{% if '.onion' in request.url_root %}
 
  {% set wiki_url = config['ENNSTATUS_WIKI_ONION_ADDRESS'] %}
 
{% elif '.bit' in request.url_root %}
 
  {% set wiki_url = config['ENNSTATUS_WIKI_BIT_ADDRESS'] %}
 
{% else %}
 
  {% set wiki_url = "wiki.enn.lu" %}
 
{% endif %}
 

	
 
{% block title %}
 
  Frënn vun der Ënn - {{ title }}
 
{% endblock %}
 

	
 
{% block metas %}
 
  {{ super() }}
 
  <meta charset="utf-8">
 
  <meta name="application-name" content="Ënnstatus">
 
  <meta name="author" content="Frënn vun der Ënn">
 

	
 
  <meta name="twitter:card" content="summary" />
 
  <meta name="twitter:site" content="@FrennVunDerEnn" />
 
  <meta name="twitter:title" content="Frënn vun der Ënn A.S.B.L." />
 
  <meta name="twitter:description" content="Luxembourg based non-profit organization defending civil rights on the internet." />
 
  <meta name="twitter:image" content="{{ url_for('static', filename='images/logo/FVDE_logo_resize.png', _external=True) }}" />
 
{% endblock %}
 

	
 
{% block styles %}
 
  {{ super() }}
 
  <link rel="stylesheet" href="{{ url_for('static', filename='css/ennstatus.css') }}" />
 
  <link rel="shortcut icon" href="{{ url_for('static', filename='images/favicon.png') }}">
 
{% endblock %}
 

	
 
{% block body %}
 
<a href="#content" class="sr-only">Skip to main content</a>
 
<div class="container">
 
  {% block navbar %}
 
  <div class="navbar navbar-default">
 
    <div class="navbar-header">
 
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
 
        <span class="icon-bar"></span>
 
        <span class="icon-bar"></span>
 
        <span class="icon-bar"></span>
 
      </button>
 
      <img class="navbar-brand" src="{{ url_for('static', filename='images/logo/FVDE_logo_thumbnail.png') }}"></img>
 
      <a class="navbar-brand" href="{{ url_for('root.index') }}">Enn.lu</a>
 
    </div>
 
    <div class="navbar-collapse collapse">
 
      <ul class="nav navbar-nav">
 
        <li class="dropdown">
 
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">About <b class="caret"></b></a>
 
          <ul class="dropdown-menu">
 
            <li><a href="//{{ wiki_url }}/doku.php?id=news" target="blank">News</a></li>
 
            <li class="divider"></li>
 
            <li><a href="{{ url_for('root.about') }}">Organization</a></li>
 
            <li><a href="{{ url_for('root.partners') }}">Partners</a></li>
 
          </ul>
 
        </li>
 
        <li class="dropdown">
 
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">Services <b class="caret"></b></a>
 
          <ul class="dropdown-menu">
 
            <li><a href="{{ url_for('status.index') }}">Tor Servers</a></li>
 
            <li class="divider"></li>
 
            <li><a href="{{ url_for('root.mirrors') }}">Mirrors</a></li>
 
            <li><a href="//{{ wiki_url }}">Wiki</a></li>
 
            <li class="divider"></li>
 
            <li><a href="{{ url_for('root.ennstatus') }}">About Ënnstatus</a></li>
 
          </ul>
 
        </li>
 
        <li class="dropdown">
 
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">Support <b class="caret"></b></a>
 
          <ul class="dropdown-menu">
 
            <li><a href="{{ url_for('donate.index') }}">Donate</a></li>
 
            <li><a href="{{ url_for('donate.received') }}">Donation history</a></li>
 
            <li><a href="{{ url_for('root.bridgeprogram')}}">Adopt a Bridge</a></li>
 
            <li class="divider"></li>
 
            <li><a href="{{ url_for('root.member') }}">Join Us</a></li>
 
            <li class="divider"></li>
 
            <li><a href="{{ url_for('donate.statistics') }}">Donation statistics</a></li>
 
            <li class="dropdown-submenu">
 
            </li>
 
          </ul>
 
        </li>
 
        <li class="dropdown">
 
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">Contact <b class="caret"></b></a>
 
          <ul class="dropdown-menu">
 
            <li><a href="{{ url_for('root.contact') }}">General</a></li>
 
            <li><a href="{{ url_for('root.abuse') }}">Abuse</a></li>
 
            <li class="divider"></li>
 
            <li><a href="https://twitter.com/FrennVunDerEnn" target="blank">Twitter</a></li>
 
            <li><a href="http://lists.enn.lu/listinfo/discuss" target="blank">Mailing List</a></li>
 
          </ul>
 
        </li>
 
        <li class="dropdown">
 
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">Statistics <b class="caret"></b></a>
 
          <ul class="dropdown-menu">
 
            <li><a href="https://stats.enn.lu/">Traffic</a></li>
 
            <li class="divider"></li>
 
            <li><a href="{{ url_for('statistics.worldmap') }}">Worldmap</a></li>
 
          </ul>
 
        </li>
 
      </ul>
 
    </div>
 
  </div>
 
  {% endblock %}
 
  <div class="row" id="content">
 
  {% with messages = get_flashed_messages(with_categories=True) %}
 
    {% if messages %}
 
      <div class="col-md-12">
 
        {% for category, message in messages %}
 
          {{ base_macros.display_error(category, message) }}
 
        {% endfor %}
 
      </div>
 
    {% endif %}
 
  {% endwith %}
 
  {% block content %}
 
  {% endblock %}
 
  </div>
 
  <div class="row">
 
    <footer class="col-md-12">
 
      <hr style="margin-bottom: 0.5%;">
 
      <div class="text-center clearfix">
 
        <div class="pull-left">
 
          <a href="https://twitter.com/FrennVunDerEnn" target="blank">@FrennVunDerEnn</a>
 
        </div>
 
        <strong>Frënn vun der Enn a.s.b.l.</strong>  <em>(R.C.S. Luxembourg F 9.478)</em>
 
        <div class="pull-right">
 
          <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_US" target="blank">CC-BY-NC-SA</a>
 
        </div>
 
      </div>
 
    </footer>
 
  </div>
 
</div>
 

	
 
{% block scripts %}
 
  {{ super() }}
 
{% endblock %}
 

	
 
{% endblock %}
ennstatus/templates/donate/statistics.html
Show inline comments
 
{# Ënnstatus
 
   Copyright (C) 2015  Dennis Fink
 

	
 
   This program is free software: you can redistribute it and/or modify
 
   it under the terms of the GNU General Public License as published by
 
   the Free Software Foundation, either version 3 of the License, or
 
   (at your option) any later version.
 

	
 
   This program is distributed in the hope that it will be useful,
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
   GNU General Public License for more details.
 

	
 
   You should have received a copy of the GNU General Public License
 
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
#}
 

	
 
{% extends "base.html" %}
 

	
 
{% set title = "Donate - Statistics" %}
 

	
 
{% block styles %}
 
  {{ super() }}
 
  <link rel="stylesheet" href="{{ url_for('static', filename='css/barchart.css') }}" />
 
{% endblock %}
 

	
 
{% block content %}
 
  <div class="col-md-12">
 
    <h2>Donate Statistics</h2>
 
  </div>
 
  <div class="col-md-12">
 
    <dl class="dl-horizontal">
 
      <dt>Mean per year:</dt>
 
      <dd>{{ all_years_mean }}</dd>
 
      <dt>Mean per month:</dt>
 
      <dd>{{ month_mean }}</dd>
 
      <dt>Best year:</dt>
 
      <dd>{{ best_year[0] }} {{ best_year[1] }}</dd>
 
      <dt>Best month:</dt>
 
      <dd>{{ best_month[0] }} {{ best_month[1] }}</dd>
 
      <dt>Highest donation:</dt>
 
      <dd>{{ highest_donation[0] }} {{ highest_donation[1] }}</dd>
 
      <dt>Median donation:</dt>
 
      <dd>{{ median_donation }}</dd>
 
      <dt>Mode donation:</dt>
 
      <dd>{{ mode_donation }}</dd>
 
    </dl>
 
  </div>
 
  <div class="col-md-12">
 
    <div class="panel panel-default">
 
      <div class="panel-heading">Donations per year</div>
 
      <div class="panel-body">
 
        <div id="yearchart" class="center-block"></div>
 
      </div>
 
    </div>
 
  </div>
 
  <div class="col-md-12">
 
    <div class="panel panel-default">
 
      <div class="panel-heading">Donations per month</div>
 
      <div class="panel-body">
 
        <form class="form-inline" role="form">
 
          <div class="form-group">
 
            <label for="monthfirstdate">First date</label>
 
            <select class="form-control input-sm" id="monthfirstdate" name="monthfirstdate">
 
            <select class="form-control input-sm" id="monthfirstdate" name="monthfirstdate" onchange="redraw()">
 
              {% for date in dates %}
 
                <option {% if date == first_default_date %}selected{% endif %} value="{{ date }}">{{ date }}</option>
 
              {% endfor %}
 
            </select>
 
            <label for="monthlastdate">Last date</label>
 
            <select class="form-control input-sm" id="monthlastdate" name="monthlastdate">
 
            <select class="form-control input-sm" id="monthlastdate" name="monthlastdate" onchange="redraw()">
 
              {% for date in dates %}
 
                <option {% if date == last_default_date %}selected{% endif %} value="{{ date }}">{{ date }}</option>
 
              {% endfor %}
 
            </select>
 
          </div>
 
        </form>
 
        <div id="monthchart"></div>
 
      </div>
 
    </div>
 
  </div>
 
{% endblock %}
 

	
 
{% block scripts %}
 
  {{ super() }}
 
  <script src="{{ url_for('static', filename='js/d3/d3.min.js') }}"></script>
 
  <script src="{{ url_for('static', filename='js/d3-tip/index.js') }}"></script>
 
  <script src="{{ url_for('static', filename='js/barcharts.js') }}"></script>
 
{% endblock %}
0 comments (0 inline, 0 general)