• R/O
  • SSH
  • HTTPS

ogup: Commit


Commit MetaInfo

Revision55 (tree)
Zeit2022-10-27 01:49:31
Autormateuszviste

Log Message

added a histogram of active servers over time

Ändern Zusammenfassung

Diff

--- trunk/frontend/hist/gophermap.php (nonexistent)
+++ trunk/frontend/hist/gophermap.php (revision 55)
@@ -0,0 +1,128 @@
1+<?php
2+
3+//
4+// OGUP servers history over time gophermap
5+//
6+// Copyright (C) 2019-2022 Mateusz Viste
7+//
8+
9+define (GRAPH_H, 21);
10+define (GRAPH_COL_MONTHS, 1); // how many months are contained in a single column
11+
12+
13+// counts all "up" servers in an xz file (servers with "failedsince = 0")
14+function count_up_servers_in_file($f) {
15+ $count = 0;
16+ $list = array();
17+
18+ $cmd = 'xzcat';
19+ if (strstr($f, ".gz") !== false) $cmd = 'zcat';
20+
21+ exec($cmd . ' ' . $f, $list);
22+ foreach ($list as $l) {
23+ $csv = str_getcsv($l);
24+ if (intval($csv[2]) != 0) continue; // skip failed servers
25+ $count++;
26+ }
27+ return($count);
28+}
29+
30+// get count of active gopher servers since Jan 2019
31+function get_history() {
32+ $curtime = date('Y') * 12 + date('m');
33+ $res = array();
34+
35+ for ($i = 2019 * 12; $i <= $curtime; $i += GRAPH_COL_MONTHS) {
36+ $yr = intval($i / 12);
37+ $mo = intval($i % 12) + 1;
38+ $dy = 1;
39+
40+ // dirty hack to fill some missing data...
41+ if (($yr == 2019) && ($mo == 1)) $mo = 2;
42+ if (($yr == 2020) && ($mo == 12)) $mo = 11;
43+ if (($yr == 2021) && ($mo < 11)) $mo = 11;
44+
45+ if (($yr == 2021) && ($mo == 11)) $dy = 27;
46+ if (($yr == 2019) && ($mo == 2)) $dy = 19;
47+
48+ $fname = sprintf('../db/ogupdb-%04d%02d%02d.dat.', $yr, $mo, $dy);
49+ if ($yr > 2020) {
50+ $fname .= 'xz';
51+ } else {
52+ $fname .= 'gz';
53+ }
54+ $res[$i] = count_up_servers_in_file($fname);
55+ }
56+ return $res;
57+}
58+
59+
60+$stats = get_history();
61+
62+echo "i\n";
63+echo "iThis histogram presents the amount of active gopher nodes over time, as\n";
64+echo "imeasured by the Observable Gopherspace Universe Project.\n";
65+echo "i\n";
66+
67+// find highest point for scaling graphs
68+$highest = 0;
69+foreach ($stats as $l) {
70+ if ($l > $highest) $highest = $l;
71+}
72+
73+/* build a 2D graph in an array */
74+$graph = array();
75+$column = 0;
76+//echo "istats = " . count($stats) . " ; highest = " . $highest . "\n";
77+foreach ($stats as $dat => $count) {
78+ //echo "i{$dat} => {$count}\n";
79+ // normalize count to a number of "pixels"
80+ $count = $count * GRAPH_H / $highest;
81+
82+ // mark vertical pixels
83+ for ($y = 0; $y < $count; $y++) {
84+ $graph[$y][$column] = 1;
85+ }
86+
87+ $column++;
88+}
89+
90+/* print out the graph */
91+$endgraphlimit = $column;
92+while ($endgraphlimit % (12 / GRAPH_COL_MONTHS)) $endgraphlimit++;
93+
94+for ($y = 0; $y < GRAPH_H; $y++) {
95+ echo 'i';
96+ for ($x = 0; $x <= $endgraphlimit; $x++) {
97+ /* add a space on year boundaries */
98+ if (($x % (12 / GRAPH_COL_MONTHS)) == 0) {
99+ if ($y & 1) {
100+ echo ' ';
101+ } else {
102+ echo '_';
103+ }
104+ }
105+ if ($graph[GRAPH_H - 1 - $y][$x] == 1) {
106+ echo '#';
107+ } else {
108+ if ($y & 1) {
109+ echo ' ';
110+ } else {
111+ echo '_';
112+ }
113+ }
114+ }
115+ if (($y & 1) == 0) echo intval($highest * (GRAPH_H - 1 - $y) / (GRAPH_H - 1));
116+ echo "\n";
117+}
118+
119+/* print out years */
120+$prevyr = 0;
121+echo "i";
122+foreach ($stats as $dat => $val) {
123+ $yr = intval($dat / 12);
124+ if ($yr != $prevyr) echo ' ' . str_pad($yr, (12 / GRAPH_COL_MONTHS), ' ', STR_PAD_BOTH);
125+ $prevyr = $yr;
126+}
127+
128+?>
Show on old repository browser