-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstat.php
137 lines (121 loc) · 3.4 KB
/
stat.php
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
include '../include/top.php';
include '../include/dbsetup.php'; // Setter opp tilkobling mot postgresql-database, så man bare kan bruke pg_query() direkte.
include 'klaus_inc.php';
//bare for innlogga folk
//if (!$sess_level){ header("Location: login.php?lfunk=loginfail&ref=".$_SERVER['REQUEST_URI']);exit;}
$sqlaar = "
SELECT kallenavn AS navn,
ABS( SUM( belop ) ) AS sum
FROM klaus_personer
WHERE dato > ( NOW() - INTERVAL '1 YEAR' )
AND type >0
GROUP BY navn
ORDER BY sum DESC
LIMIT 20
;";
$aar = pg_query($sqlaar) or die(pg_last_error());
$aart = pg_query($sqlaar);
$sqlmnd = "
SELECT kallenavn AS navn ,
ABS( SUM( belop ) ) AS sum
FROM klaus_personer
WHERE dato > ( NOW() - INTERVAL '1 MONTH' )
AND type >0
GROUP BY navn
ORDER BY sum DESC
LIMIT 20
;";
$mnd = pg_query($sqlmnd);
$mndt = pg_query($sqlmnd);
$sqlall = "
SELECT kallenavn AS navn ,
ABS( SUM( belop ) ) AS sum
FROM klaus_personer
WHERE type >0
GROUP BY navn
ORDER BY sum DESC
LIMIT 40
;";
$all = pg_query($sqlall);
$allt = pg_query($sqlall);
$sqlmonth = "
SELECT TO_CHAR( dato, 'FMMonth' ) AS month, ABS( SUM( belop ) ) AS sum
FROM klaus_personer
WHERE dato > (NOW() - INTERVAL '1 YEAR')
AND type > 0
GROUP BY month, DATE_PART( 'MONTH', dato )
ORDER BY DATE_PART( 'MONTH', dato )
LIMIT 12
;";
$month = pg_query($sqlmonth) or die(pg_last_error());
//FUNKSJONER
function listeHor($res, $del) {
$f = 0;
while ($row = pg_fetch_array($res)) {
$r = 200;
$g = 200*$f;
$b = 200*$f;
echo "<div style=\"width:".round($row[1]/$del).
"px;background-color:rgb(".$r.",".$g.",".$b.")\">".$row[0].": ".$row[1]."</div>\n";
if ($f == 1) $f = 0;
else $f = 1;
}
}
function listeVer($res, $del) {
$max = 0;
$f = 0;
while ($row = pg_fetch_array($res)) {
$months[$row[0]] = $row[1];
if ($row[1] > $max) $max = $row[1];
}
foreach ($months as $month => $total) {
$r = 200;
$g = 200*$f;
$b = 200*$f;
$graph .= "<div style=\"width:60px;height:".(round($total/$del)+3).
"px;top:".($max/$del-round($total/$del))."px;float:left;position:relative;background-color:rgb(".$r.",".$g.",".$b.")\"><div style=\"position:absolute;bottom:5px\">$month: $total</div></div>\n";
if ($f == 1) $f = 0;
else $f = 1;
}
$height = $max/$del;
echo "<div style=\"height:".$height."px;margin:15px\">$graph</div>";
}
function liste($res) {
while ($row = pg_fetch_array($res)) {
echo $row[0]." drakk for ".$row[1]." kr <br>";
}
}
function lagDel($t) {
$res = $t;
$storst = 0;
while ($row = pg_fetch_array($res)) {
if ($row[1] > $storst) $storst = $row[1];
}
$del = round($storst/750);
return $del;
}
//PRESENTASJON
// TODO: La bruker velge hvilken type statistikk man vil se, og gjøre det mulig å velge en spesifikk tidsperiode...
?>
<a href='index.php'>Tilbake</a><br />
<?
echo "<h3>Siste år:</h3>";
$del = lagDel($aart);
listeHor($aar, $del); //30
echo "";
echo "<h3>Siste måned:</h3>";
$del = lagDel($mndt);
listeHor($mnd, $del); //10
echo "";
echo "<h3>Siste år, måned for måned:</h3>";
listeVer($month, 147); //130
echo "";
echo "<h3>All time:</h3>";
$del = lagDel($allt);
listeHor($all, $del); //100
echo "";
$alltime = pg_fetch_array(pg_query("select sum(belop), min(registrert) from klaus where belop < 0"));
echo "<p>Totalt har det blitt registrert kryss for <b><i>kr. " . number_format(abs($alltime['sum']), 2, ',', ' ') . "</i></b> siden <i>" . substr($alltime['min'],0,10) . "</i></p>";
include("../include/foot.php");
?>