-
Notifications
You must be signed in to change notification settings - Fork 0
/
LiveStats.html
144 lines (133 loc) · 7.1 KB
/
LiveStats.html
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
138
139
140
141
142
143
144
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Voter Sample: Real-Time Results</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../../tools/studio.web/css/jquery.jqplot.min.css" />
<script language="javascript" type="text/javascript" src="../../tools/studio.web/js/jquery-1.6.1.min.js"></script>
<!--[if IE]><script language="javascript" type="text/javascript" src="../../tools/studio.web/js/jqplot/excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="../../tools/studio.web/js/jqplot/jquery.jqplot.min.js"></script>
<script language="javascript" type="text/javascript" src="../../tools/studio.web/js/voltdb.js"></script>
<script language="javascript" type="text/javascript" src="js/canvas-us-map.js"></script>
<script language="javascript" type="text/javascript" src="js/jqplot.mapRenderer.js"></script>
<script type="text/javascript" language="javascript">
var contestants = [{label:'Edwina Burnam',color:'#f00'},{label:'Tabatha Gehling',color:'#900'},{label:'Kelly Clauss',color:'#0f0'},{label:'Jessie Alloway',color:'#090'},{label:'Alana Bregman',color:'#00f'},{label:'Jessie Eichman',color:'#009'}];
var plot;
var con;
var intervalId;
function RefreshData()
{
con.BeginExecute('GetStateHeatmap', [], function(response)
{
try
{
var data = [['XX',0]];
var agg = [0,0,0,0,0,0];
var tot = 1;
for(var i=0;i<response.results[0].data.length;i++)
{
if (response.results[0].data[i][3] == 1)
data.push([response.results[0].data[i][0], response.results[0].data[i][1]-1]);
agg[response.results[0].data[i][1]-1] += response.results[0].data[i][2];
tot += response.results[0].data[i][2];
}
for(var i=0;i<agg.length;i++)
{
$('#statdata' + i).text(formatNumber(agg[i]));
$('#pctdata' + i).text(Math.round(100*agg[i]/tot) + "%");
$('#pctbar' + i).css('width', Math.round(100*agg[i]/tot) + "px");
}
plot.series[0].data = data;
plot.replot({clear:true, resetAxes:true});
}
catch(x) {}
});
}
function SetRefreshInterval(interval)
{
if (intervalId != null)
{
clearInterval(intervalId);
intervalId = null;
}
if(interval > 0)
intervalId = setInterval(RefreshData, interval*1000);
}
function formatNumber(num)
{
var cnum = ""+num;
var parr = [], j = cnum.length, m = Math.floor(j / 3), n = cnum.length % 3 || 3;
for (var i = 0; i < j; i += n)
{
if (i != 0) {n = 3;}
parr[parr.length] = cnum.substr(i, n);
m -= 1;
}
return parr.join(',');
}
$(document).ready(function(){
var states = ['AL','AK','AZ','AR','CA','CO','CT','DE','FL','GA','ID','IL','IN','IA','HI','KS','KY','LA','ME','MD','MA','MI','MN','MS','MO','MT','NE','NV','NH','NJ','NM','NY','NC','ND','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VT','VA','WA','WV','WI','WY'];
var data = [[['XX',0]],[],[],[],[],[]];
var colors = [];
for(var i=0;i<contestants.length;i++)
colors.push(contestants[i].color);
var chartParams = {
legend:{ show: true, yoffset:110, xoffset: -80 },
seriesDefaults:{
renderer: $.jqplot.MapRenderer,
rendererOptions: { mapVarName: 'usMapData' }
},
axesDefaults: {
tickOptions: {
showMark: false,
showLabel: false
}
},
grid: {
drawGridlines: false,
shadow: false,
borderWidth: 0.01,
background: '#fff'
},
series: contestants,
seriesColors: colors
};
plot = $.jqplot('chartUSMap1', data, chartParams);
con = VoltDB.AddConnection('localhost', 8080, false, null, null, false, (function(connection, success)
{}));
SetRefreshInterval(1);
});
</script>
</head>
<body style="background-color:#f9f9f9;font-family: Verdana,Arial,sans-serif;font-size:80%;-moz-user-select: none;">
<table cellspacing="0" cellpadding="0" border="0" width="100%" height="100%">
<tr><td valign="middle=" align="center"><div style="width:580px;padding:20px;padding-top:0px;background-color:white;border:1px solid #ddd;">
<div style="width:580px;text-align:justify">
<h1>Voter Sample: Real-Time Results</h1>
<p>Watch the voting results live - the heat map indicates which contestant is winning in a given state, while the table below the map lists the total number of votes each contestant has received, nationwide. Use the pulldown menu to change the refresh rate..</p>
</div>
<hr size="1" />
<b>Refresh Data: </b><select onchange="SetRefreshInterval(this.value)">
<option value="1">Every second</option>
<option value="5">Every 5 seconds</option>
<option value="10">Every 10 seconds</option>
<option value="30">Every 30 seconds</option>
<option value="60">Every minute</option>
<option value="-1">Paused</option>
</select>
<hr size="1" />
<div class="jqPlot" id="chartUSMap1" style="width:500px;"></div>
<hr size="1" />
<table cellspacing="2" cellpadding="2" border="0" width="100%">
<thead style="background-color:#eee"><tr><th width="200">Contestant</th><th width="150">%</th><th>Votes</th></tr></thead><tbody>
<script type="text/javascript" language="javascript">
for(var i=0;i<contestants.length;i++)
document.write('<tr><td>' + contestants[i].label + '</td><td><div id="pctdata' + i + '" style="float:left;width:30px;text-align:right;">0%</div><div id="pctbar' + i + '" style="float:left;margin-left:10px;margin-right:10px;width:0px;background-color:#ccc"> </div></td><td id="statdata' + i + '" align="right">0</td></tr>');
</script>
</table>
<hr size="1" />
<a href="../../tools/studio.web/index.htm?startup=query" target="_blank">Click here</a> to launch VoltDB Studio and run other queries while the application is running.
</div></td></tr></table>
</body></html>