forked from StianF/ecomarathon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstat.php
executable file
·96 lines (91 loc) · 2.3 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
<?PHP
include "db.php";
$type = $_GET['type'];
$n = $_GET['n'];
$offset = $_GET['offset'];
if(isset($offset)){
$offset = ($offset*50).",";
}else{
$offset = "";
}
if(!isset($n) || !isset($type))
return;
$info = mysql_query("SELECT * FROM type WHERE id = ".$type);
$info = mysql_fetch_assoc($info);
$hist = mysql_query("SELECT * FROM log WHERE type = ".$type." AND n = ".$n." ORDER BY time DESC LIMIT ".$offset."50");
$hista = Array();
while($a = mysql_fetch_assoc($hist)){
array_push($hista, $a);
}
$hista = array_reverse($hista);
$a = $hista[0];
$series = "[[".strtotime($a['time'])."000,".$a['value']."]";
for($i = 1; $i < count($hista); $i++){
$a = $hista[$i];
$series .= ",[".strtotime($a['time'])."000,".$a['value']."]";
}
$series .= "]";
mysql_close($conn);
?>
<html>
<head>
<!-- BEGIN: load jquery -->
<script language="javascript" type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<!-- END: load jquery -->
<!-- BEGIN: highcharts -->
<script language="javascript" type="text/javascript" src="js/highcharts.js"></script>
<!-- END: highcharts -->
<script type="text/javascript">
$(document).ready(
function(){
chart = new Highcharts.Chart({
chart: {
renderTo: 'chart1',
},
title: {
text: "<?PHP echo $info['name']." ".$n;?>"
},
xAxis: {
type: 'datetime'
},
tooltip: {
formatter: function(){
var date = new Date(this.point.x);
return "<b>"+date.toUTCString()+'</b>: '+this.y+' <?PHP echo $info['unit'];?>';
}
},
yAxis: {
title: "<?PHP echo $info['unit'];?>"
},
legend: {
enabled: false
},
plotOptions: {
series: {
animation: {
duration: 2000
}
}
},
series: [{
data: <?PHP echo $series;?>
}]
});
}
);
</script>
</head>
<body>
<div id="chart1"></div>
<div>
<div style="float:left"><a href="stat.php?type=<?PHP echo $type;?>&n=<?PHP echo $n;?><?PHP echo "&offset=".($_GET["offset"]+1);?>">Back</a></div>
<?PHP
if(isset($_GET["offset"]) && $_GET["offset"] != 0){
?>
<div style="float:right"><a href="stat.php?type=<?PHP echo $type;?>&n=<?PHP echo $n;?><?PHP echo "&offset=".($_GET["offset"]-1);?>">Forward</a></div>
<?PHP
}
?>
</div>
</body>
</html>