summaryrefslogtreecommitdiffstats
path: root/site/projects/keyr/stats.html
blob: 8559108432062f6d38bdc59f305773276dffd34d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<h1>Keystrokes Reporting</h1>

<p>
  We have counted <span id="global_count">0</span> on <strong>lthms</strong>’
  computers since <span id="start_date">today</span>, thanks to
  <a href="https://sr.ht/~lthms/keyr"><strong>keyr</strong></a>.
</p>

<p>
  <strong>Beware:</strong> Contrary to the rest of this blog, you need to enable
  JavaScript for this webpage to work.
</p>

<h2>during the past 10 days</h2>

<div id="heatmap-weeks"></div>

<h2>during the past 6 months</h2>

<div id="heatmap-year"></div>

<script src="https://soap.coffee/+vendors/d3.js/d3.v3.min.js"></script>
<script src="https://soap.coffee/+vendors/cal-heatmap/cal-heatmap.3.3.10.min.js"></script>

<style>
  #heatmap-weeks,
  #heatmap-year {
      overflow-x : scroll;
  }
</style>

<script type="text/javascript">
  // First, we load the necessary CSS
  document.getElementById('asyncloading')
    .insertAdjacentHTML(
      'beforebegin',
      '<link rel="stylesheet" href="https://soap.coffee/+vendors/cal-heatmap/cal-heatmap.3.3.10.css" />'
  );

  let gcount = document.getElementById("global_count");
  let start_date = document.getElementById("start_date");

  let min_date = new Date();

  const months = {
      0: 'January',
      1: 'February',
      2: 'March',
      3: 'April',
      4: 'May',
      5: 'June',
      6: 'July',
      7: 'August',
      8: 'September',
      9: 'October',
      10: 'November',
      11: 'December'
  }

fetch('https://keyrhub.soap.coffee/view/lthms')
  .then((response) =>
    response.json()
      .then((raw_datas) => {

        var global_count = 0;
        var min_date = new Date() / 1000;

        for (var prop in raw_datas) {
	  global_count += raw_datas[prop];
          min_date = Math.min(min_date, prop);
        }

        min_date = new Date(min_date * 1000);

        start_date.innerText =
          `${months[min_date.getMonth()]} ${min_date.getDate()}, ${min_date.getFullYear()}`;
        gcount.innerText = global_count.toLocaleString();

        var calweeks = new CalHeatMap();

        calweeks.init({
          itemSelector: "#heatmap-weeks",
          itemName: "keystroke",
          data: raw_datas,
          start: new Date(new Date() - 9 * 24 * 60 * 60 * 1000),
          domain: "day",
          subDomain: "hour",
          domainGutter: 0,
          range: 10,
          legend: [500, 3000, 5000, 7000]
        });

        var calyear = new CalHeatMap();

        calyear.init({
          itemSelector: "#heatmap-year",
          itemName: "keystroke",
          data: raw_datas,
          domain: "month",
          subDomain: "day",
          domainGutter: 10,
          start: new Date(new Date() - 5 * 30 * 24 * 60 * 60 * 1000),
          range: 6,
          legend: [1000, 15000, 30000, 45000]
        });
      }));
</script>