-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
164 lines (156 loc) · 6.29 KB
/
index.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>charts</title>
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.0.0-rc7.min.js"></script>
<script src="https://www.google.com/jsapi"></script>
<script src="js/mongosetup.js"></script>
<script src="js/localforage.js"></script>
<script>
window.onload = function() {
refreshDate();
}
var term = 1000 * 60 * 60 * 24 * 7; // 1week
var dynamo = new AWS.DynamoDB();
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
var end = new Date();
var start = new Date(end.getTime() - term);
function drawChart() {
dynamo.query({
TableName: 'hvstat',
KeyConditions:{
// key
'type':{
AttributeValueList:[
{'S':'8h'}
],
ComparisonOperator:'EQ'
},
// range
'datetime':{
AttributeValueList:[
{'N':yyyymmddhh(start)},
{'N':yyyymmddhh(end)},
],
ComparisonOperator:'BETWEEN'
}
},
AttributesToGet:['datetime','hath','gp','base']
},
function(err, res) {
if (err) {
alert(err);
} else {
// hath
var data = new google.visualization.DataTable();
var data2 = new google.visualization.DataTable();
var data3 = new google.visualization.DataTable();
var data4 = new google.visualization.DataTable();
var data5 = new google.visualization.DataTable();
data.addColumn('date', 'Date');
data.addColumn('number', 'max');
data.addColumn('number', 'avg');
data.addColumn('number', 'min');
data2.addColumn('date', 'Date');
data2.addColumn('number', 'max');
data2.addColumn('number', 'avg');
data2.addColumn('number', 'min');
data3.addColumn('date', 'Date');
data3.addColumn('number', 'hath');
data4.addColumn('date', 'Date');
data4.addColumn('number', 'credit');
data4.addColumn('number', 'assets');
data5.addColumn('date', 'Date');
data5.addColumn('number', 'gp');
var items = res.Items;
for (var c in items) {
var dt = items[c].datetime.N;
var ary = items[c].hath.S.split('"');
var ary2 = items[c].gp.S.split('"');
var ary3 = items[c].base.S.split('"');
var day = new Date(dt.substr(0,4), dt.substr(4,2)-1, dt.substr(6,2), dt.substr(8,2));
var c_hath = (ary3[11]-0) * (ary[11]-0);
var c_gp = (ary3[3]-0) * (ary2[11]-0);
data.addRow([day, ary[3]-0, ary[11]-0, ary[15]-0]);
data2.addRow([day, ary2[3]-0, ary2[11]-0, ary2[15]-0]);
data3.addRow([day, ary3[11]-0]);
data4.addRow([day, ary3[7]-0, ary3[7]-0 + c_hath + c_gp]);
data5.addRow([day, ary3[3]-0]);
}
// hath
var chart = new google.visualization.LineChart(document.getElementById('chart_hath'));
chart.draw(data, {
fontSize:'12',
legendTextStyle: {color:'#666666',fontSize:'9'},
title: 'hath rate',
vAxis: {title: "credit"},
hAxis: {title: "date"}
});
// gp
var chart2 = new google.visualization.LineChart(document.getElementById('chart_gp'));
chart2.draw(data2, {
fontSize:'12',
legendTextStyle: {color:'#666666',fontSize:'9'},
title: 'gp rate',
vAxis: {title: "credit"},
hAxis: {title: "date"}
});
// myhath
var chart3 = new google.visualization.LineChart(document.getElementById('chart_myhath'));
chart3.draw(data3, {
fontSize:'12',
legendTextStyle: {color:'#666666',fontSize:'9'},
title: 'own hath',
vAxis: {title: "count"},
hAxis: {title: "date"}
});
// mycredit
var chart4 = new google.visualization.LineChart(document.getElementById('chart_mycredit'));
chart4.draw(data4, {
fontSize:'12',
legendTextStyle: {color:'#666666',fontSize:'9'},
title: 'own credit',
vAxis: {title: "count"},
hAxis: {title: "date"},
series: {
1: {targetAxisIndex: 1}
}
});
// mygp
var chart5 = new google.visualization.LineChart(document.getElementById('chart_mygp'));
chart5.draw(data5, {
fontSize:'12',
legendTextStyle: {color:'#666666',fontSize:'9'},
title: 'own gp',
vAxis: {title: "count"},
hAxis: {title: "date"}
});
localforage.setItem('last_update', new Date(), refreshDate);
}
});
}
function yyyymmddhh(dt) {
var year = dt.getFullYear();
var month = ("0" + (dt.getMonth() + 1)).slice(-2);
var day = ("0" + dt.getDate()).slice(-2);
var hour = ("0" + dt.getHours()).slice(-2);
return "" + year + month + day + hour;
}
function refreshDate() {
localforage.getItem('last_update', function(e) {
document.getElementById("last_update").innerHTML = "last_update: " + e;
});
}
</script>
</head>
<body>
<div id="last_update"></div>
<div id="chart_hath"></div>
<div id="chart_gp"></div>
<div id="chart_myhath"></div>
<div id="chart_mycredit"></div>
<div id="chart_mygp"></div>
</body>
<html>