-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathviz.html
134 lines (132 loc) · 4.87 KB
/
viz.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
<!DOCTYPE html lang="en">
<html>
<head>
<script>
function getList(cb) {
var xhr = new XMLHttpRequest();
xhr.open('GET', '/points.json', true);
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
var text = xhr.responseText;
cb(JSON.parse(text));
}
}
xhr.send();
}
function getQuote(site, date, text, from, to, cb) {
var xhr = new XMLHttpRequest();
xhr.open('GET', '/scrapes/'+site+'/'+date+'/'+text+'/', true);
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
var text = xhr.responseText;
cb(text.substring(from, to));
}
}
xhr.send();
}
function getWeights(cb) {
var xhr = new XMLHttpRequest();
xhr.open('GET', '/weights.json', true);
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
var text = xhr.responseText;
cb(JSON.parse(text));
}
}
xhr.send();
}
function getRates(cb) {
var xhr = new XMLHttpRequest();
xhr.open('GET', '/rates.json', true);
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
var text = xhr.responseText;
cb(JSON.parse(text));
}
}
xhr.send();
}
function go() {
getList(function(list) {
var i, j, thisSite, thisCrit;
var sites = {};
var crits = {};
for(i = 0; i < list.length; i++) {
sites[list[i].site]=0;
crits[list[i].crit]=true;
}
var str = '<table><tr><td>site:</td><td>rating:</td><td>points:</td>';
for(thisCrit in crits) {
str += '<td>'+thisCrit+'</td>';
}
str += '</tr>';
for(thisSite in sites) {
str += '<tr><td>'+thisSite+'</td><td id="rating_'+thisSite+'"></td><td id="points_'+thisSite+'"></td>';
for(thisCrit in crits) {
str += '<td bgcolor="grey" id="cell_'+thisSite+'_'+thisCrit+'" onclick="getQuotes(\''+thisSite+'\', \''+thisCrit+'\');"></td>';
}
str += '</tr>';
}
document.getElementById('viz').innerHTML = str;
getWeights(function(weights) {
for(i = 0; i < list.length; i++) {
document.getElementById('cell_'+list[i].site+'_'+list[i].crit).setAttribute('bgcolor', list[i].read);
document.getElementById('cell_'+list[i].site+'_'+list[i].crit).innerHTML = weights[list[i].crit][list[i].read];
}
for(thisSite in sites) {
for(thisCrit in crits) {
sites[thisSite] += parseInt(document.getElementById('cell_'+thisSite+'_'+thisCrit).innerHTML);
}
document.getElementById('points_'+thisSite).innerHTML = sites[thisSite];
}
getRates(function(rates) {
var thisRate;
for(thisSite in sites) {
for(thisRate in rates) {
if(sites[thisSite] >= rates[thisRate]) {
document.getElementById('rating_'+thisSite).innerHTML = thisRate;
break;
}
}
}
});
});
});
}
function getQuotes(site, crit) {
getList(function(list) {
var i, j;
for(i = 0; i< list.length; i++) {
if((list[i].site == site) && (list[i].crit == crit)) {
document.getElementById('det').innerHTML = '<h2>Discussion page for '+site+' / '+crit+'</h2>';
for(j = 0; j < list[i].quotes.length; j++) {
getQuote(site, list[i].date, list[i].quotes[j].text, list[i].quotes[j].from, list[i].quotes[j].to, function(text) {
document.getElementById('det').innerHTML = document.getElementById('det').innerHTML
//+ '<br>Quote char '+list[i].quotes[j].from
//+ ' to '+list[i].quotes[j].to
//+ ': <a href="/scrapes/'+site+'/'+list[i].date+'/'+list[i].text+'/index.html">"'+text+'"</a>';
+'<br>'+text+'<br><input type="submit" value="back" onclick="goBack();">';
document.getElementById('det').style.display='block';
document.getElementById('viz').style.display='none';
});
}
}
}
});
}
function goBack() {
document.getElementById('viz').style.display='block';
document.getElementById('det').style.display='none';
}
</script>
</head>
<body onload="go();">
<h2>WARNING: the data on this page is only test data, no real data yet.</h2>
<div id="viz">
(result)
</div>
<div id="det" style="display:none;">
(details)
</div>
</body>
</html>