From 6f6eb6128cf23c852557f73777489ea2fce0c5c8 Mon Sep 17 00:00:00 2001 From: "Fafner [_KeyZee_]" Date: Wed, 25 Nov 2020 20:16:18 +0100 Subject: [PATCH 1/3] reorganise 'scripts' for the stats --- website/web/templates/main.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/website/web/templates/main.html b/website/web/templates/main.html index 9cf33670..e942df40 100644 --- a/website/web/templates/main.html +++ b/website/web/templates/main.html @@ -12,7 +12,11 @@ {{ bootstrap.load_css() }} {% endblock %} - + {% block scripts %} + + {{ bootstrap.load_js() }} + {% endblock %} + {% block title %}{% endblock%} @@ -24,9 +28,5 @@ {% block content %}{% endblock%} - {% block scripts %} - - {{ bootstrap.load_js() }} - {% endblock %} From 1ad1c50540eb0f388d5ac5c16ca182268daa32a4 Mon Sep 17 00:00:00 2001 From: "Fafner [_KeyZee_]" Date: Wed, 25 Nov 2020 20:17:36 +0100 Subject: [PATCH 2/3] adding graph for years stats --- website/web/templates/stats.html | 66 ++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/website/web/templates/stats.html b/website/web/templates/stats.html index 550d3472..53a68b7e 100644 --- a/website/web/templates/stats.html +++ b/website/web/templates/stats.html @@ -4,6 +4,7 @@ {% block content %} +
{% for weeks in stats['weeks'] %}

Week: {{ weeks['week'] }}

@@ -71,4 +72,69 @@ {% endfor %}
+
+{% for name, dict_ in stats['years'].items() %} +
Total Submissions {{ name }}
+ + +{% endfor %} +
+ {% endblock %} From 28ed2b168c0c7052f5b0bc037f6a226c6b995d64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Thu, 26 Nov 2020 22:26:22 +0100 Subject: [PATCH 3/3] chg: Use d3js instead of chart.js --- website/web/static/stats_graph.js | 64 ++++++++++++++++++++++++ website/web/templates/main.html | 9 ++-- website/web/templates/stats.html | 82 +++++-------------------------- 3 files changed, 79 insertions(+), 76 deletions(-) create mode 100644 website/web/static/stats_graph.js diff --git a/website/web/static/stats_graph.js b/website/web/static/stats_graph.js new file mode 100644 index 00000000..6ade081b --- /dev/null +++ b/website/web/static/stats_graph.js @@ -0,0 +1,64 @@ +"use strict"; +var margin = {top: 50, right: 50, bottom: 50, left: 50}; +var width = 1000; +var height = 100; + +var xScale = d3.scaleLinear() + .domain([0, 12]) + .range([0, width]); + +d3.json('/json/stats').then(json => { + for (var year in json['years']) { + var dataset = []; + for (var month in json['years'][year]) { + var i_month = parseInt(month) + if (Number.isInteger(i_month)) { + dataset.push([month, json['years'][year][month]['analysis']]); + height = Math.max(json['years'][year][month]['analysis'] + 50, height); + }; + }; + var yScale = d3.scaleLinear() + .domain([0, height]) + .range([height, 0]); + + var line = d3.line() + .x(d => { return xScale(d[0]); }) + .y(d => { return yScale(d[1]); }) + .curve(d3.curveMonotoneX) + + var svg = d3.select(".graphs").append("svg") + .attr("width", width + margin.left + margin.right) + .attr("height", height + margin.top + margin.bottom) + .append("g") + .attr("transform", `translate(${margin.left}, ${margin.top})`); + + svg.append("text") + .attr("x", (width / 2)) + .attr("y", 0 - (margin.top / 2)) + .attr("text-anchor", "middle") + .style("font-size", "20px") + .text(year); + + svg.append("g") + .attr("class", "x axis") + .attr("transform", `translate(0, ${height})`) + .call(d3.axisBottom(xScale)); + + svg.append("g") + .attr("class", "y axis") + .call(d3.axisLeft(yScale)); + + svg.append("path") + .datum(dataset) + .attr("class", "line") + .attr("d", line); + + svg.selectAll(".dot") + .data(dataset) + .enter().append("circle") + .attr("class", "dot") + .attr("cx", d => { return xScale(d[0]) }) + .attr("cy", d => { return yScale(d[1]) }) + .attr("r", 5); + }; +}); diff --git a/website/web/templates/main.html b/website/web/templates/main.html index e942df40..1cc43eca 100644 --- a/website/web/templates/main.html +++ b/website/web/templates/main.html @@ -12,11 +12,6 @@ {{ bootstrap.load_css() }} {% endblock %} - {% block scripts %} - - {{ bootstrap.load_js() }} - {% endblock %} - {% block title %}{% endblock%} @@ -28,5 +23,9 @@ {% block content %}{% endblock%} + {% block scripts %} + + {{ bootstrap.load_js() }} + {% endblock %} diff --git a/website/web/templates/stats.html b/website/web/templates/stats.html index 53a68b7e..bebcef89 100644 --- a/website/web/templates/stats.html +++ b/website/web/templates/stats.html @@ -2,9 +2,7 @@ {% block title %}Statistics{% endblock %} - {% block content %} -
{% for weeks in stats['weeks'] %}

Week: {{ weeks['week'] }}

@@ -15,8 +13,8 @@ Submissions Submissions with redirects Redirects - Uniq urls - Uniq domains + Unique urls (including redirects) + Unique domains (including redirects) @@ -51,8 +49,8 @@ Submissions Submissions with redirects Redirects - Uniq urls - Uniq domains + Unique urls (including redirects) + Unique domains (including redirects) @@ -72,69 +70,11 @@ {% endfor %}
-
-{% for name, dict_ in stats['years'].items() %} -
Total Submissions {{ name }}
- - -{% endfor %} -
- +
+{% endblock %} + +{% block scripts %} +{{ super() }} + + {% endblock %}