-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataviz.html
304 lines (242 loc) · 7.78 KB
/
dataviz.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Text2Meaning</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script type="text/javascript">
function dump(obj) {
out = '';
for (var i in obj) {
if (typeof obj[i] === 'object') line = JSON.stringify(obj[i]);
else line = obj[i];
out += i + ": " + JSON.stringify(obj[i]) + "<br>";
}
return out;
}
function loadJsonDB(isin) {
$.ajax({
url: isin+'.json',
dataType: 'json',
success: function(data) {
loadedJson = data;
console.log("success poll: "+isin);
updateMemory(loadedJson);
updateIsinList(loadedJson);
//console.log(data);
},
complete: function() {
// Schedule the next request when the current one's complete
},
error: function (e) {
$("#errors").append(dump(e));
}
});
};
function pollAll() {
for (i = 0, len = isinArray.length; i < len; i++) {
console.log("polling "+isinArray[i]);
loadJsonDB(isinArray[i]);
}
if (polling == true) setTimeout(pollAll, 2000);
};
function loadJsonTwitter() {
$.ajax({
url: 'twitter.json',
dataType: 'json',
success: function(data) {
loadedJson = data;
console.log("success poll twitter");
if (data.title == lastTwitterTitle) {}
else {
resetPopupTwitter();
$("#popuptabletwitter").append(
$('<tr>').append(
$('<td>',{ "text": data.title })).append(
$('<td>',{ "text": data.author })).append(
));
$("#twitter").dialog("open");
lastTwitterTitle = data.title;
}
},
complete: function() {
// Schedule the next request when the current one's complete
},
error: function (e) {
$("#errors").append(dump(e));
}
});
};
function pollTwitter() {
for (i = 0, len = isinArray.length; i < len; i++) {
loadJsonTwitter(isinArray[i]);
}
if (twitterpolling == true) setTimeout(pollTwitter, 2000);
};
function updateIsinList(data) { // GUI update
console.log(data.isin +" "+data.articles.length);
setScore(data.isin,data.aggregatedScore+" " + "("+data.scoreConfidence+")");
setNewsCounter(data.isin,data.articles.length);
setName(data.isin,data.name);
}
function setNewsCounter(isin,counter) {
$("#content").find("tr#"+isin+" td:nth-child(4)").text(counter);
}
function setScore(isin,score) {
$("#content").find("tr#"+isin+" td:nth-child(3)").text(score);
}
function setName(isin,name) {
$("#content").find("tr#"+isin+" td:nth-child(2)").text(name);
}
function showDetails(isin) {
resetPopup();
var isinData = getIsinData(isin);
var articleArray = isinData.articles;
for (i = 0, len = articleArray.length; i < len; i++) {
var thisArticle = articleArray[i];
$("#popuptable").append(
$('<tr>').append(
$('<td>',{ "text": thisArticle.title })).append(
$('<td>',{ "text": thisArticle.score })).append(
$('<td>',{ "text": thisArticle.scoreConfidence }))
)
}
$("#popup").dialog("open");
}
function getIsinData(isin) {
for (i = 0, len = masterIsinJsonArray.length; i < len; i++) {
var thisObject = masterIsinJsonArray[i];
if (thisObject.isin == isin) {
return thisObject;
}
}
return "error";
}
function updateMemory(data) {
updated = false;
for (i = 0, len = masterIsinJsonArray.length; i < len; i++) {
var thisObject = masterIsinJsonArray[i];
console.log("check "+thisObject.isin +" "+ data.isin);
if (thisObject.isin == data.isin) {
masterIsinJsonArray[i] = data;
console.log("updated in memory "+data.isin);
updated = true;
}
}
if (updated == false) {
console.log("new memory entry for "+data.isin)
masterIsinJsonArray.push(data);
}
}
function resetPopup() {
$("#popup").html(
$('<table>',{ "border": 1, "id": "popuptable" }).append(
$('<tr>').append(
$('<th>',{ "text": "title" })).append(
$('<th>',{ "text": "score" })).append(
$('<th>',{ "text": "ScoreConfidence" }))
)
);
}
function resetPopupTwitter() {
$("#twitter").html(
$('<table>',{ "border": 1, "id": "popuptabletwitter" }).append(
$('<tr>').append(
$('<th>',{ "text": "title" })).append(
$('<th>',{ "text": "author" }))
)
);
}
$( document ).ready(function() {
lastTwitterTitle = ""
polling = true;
loadedJson = {};
isinArray = ["all","US0378331005","CH0012005267","US8552441094"];
masterIsinJsonArray = [];
//classify("This is a text to try language detection.");
//batch_classify(["A Romanian court on Wednesday placed the head of the nation’s electoral monitor in pretrial detention for 30 days on suspicion of influence peddling and money laundering, local media reported. Officials from Romania’s National Anti-Corruption Directorate (DNA) detained and questioned Ana Maria Patru, the chairwoman of the nation’s Permanent Electoral Authority (AEP), on Tuesday following searches of AEP offices and her home. In 2009, while Patru was serving as AEP vice president, she allegedly received a bribe of €210,000 (US$ 308,900) from an IT company that her agency eventually hired to produce the software used to monitor election results, according to DNA officials. The money was then allegedly laundered through several companies including one controlled by her husband. Patru’s husband was caught on Tuesday while trying to flee their home with evidence, Balkan Insight reported. Patru has reportedly resigned from her post."]);
$("#content").append(
$('<table>',{ "border": 1 }).append(
$('<tr>').append(
$('<th>',{ "text": "ISIN" })).append(
$('<th>',{ "text": "Name" })).append(
$('<th>',{ "text": "Score" })).append(
$('<th>',{ "text": "Anzahl News" }))
).append(
$('<tr>',{ "id": "US0378331005" }).append(
$('<td>').append($("<a>", { "href": "#", "text": "US0378331005"} ).click(function() { showDetails("US0378331005"); }))).append(
$('<td>',{ "text": "--" })).append(
$('<td>',{ "text": "--" })).append(
$('<td>',{ "text": "3" }))
).append(
$('<tr>',{ "id": "US8552441094" }).append(
$('<td>').append($("<a>", { "href": "#", "text": "US8552441094"} ).click(function() { showDetails("US8552441094"); }))).append(
$('<td>',{ "text": "--" })).append(
$('<td>',{ "text": "--" })).append(
$('<td>',{ "text": "1" }))
).append(
$('<tr>',{ "id": "CH0012005267" }).append(
$('<td>').append($("<a>", { "href": "#", "text": "CH0012005267"} ).click(function() { showDetails("CH0012005267"); }))).append(
$('<td>',{ "text": "--" })).append(
$('<td>',{ "text": "--" })).append(
$('<td>',{ "text": "1" }))
).append(
$('<tr>',{ "id": "all" }).append(
$('<td>').append($("<a>", { "href": "#", "text": "all"} ).click(function() { showDetails("all"); }))).append(
$('<td>',{ "text": "--" })).append(
$('<td>',{ "text": "--" })).append(
$('<td>',{ "text": "1" }))
)
);
resetPopup();
$("a#stoppoll").click(function() {
polling = false;
});
$("a#startpoll").click(function() {
polling = true;
pollAll();
});
$("a#stoppollt").click(function() {
twitterpolling = false;
});
$("a#startpollt").click(function() {
twitterpolling = true;
pollTwitter();
});
$("#popup").dialog(
{
width: 700,
modal: true
}
);
$("#popup").dialog("close");
$("#twitter").dialog(
{
width: 400,
modal: true
}
);
$("#twitter").dialog("close");
//$("#content").append($("#content").find("tr#CH2132431243 td:nth-child(3)").text());
//$("#content").append($("#content").find("tr#CH2132431243 td:nth-child(4)").text());
});
</script>
</head>
<body>
<div id="content">
</div>
<a href="#" id="stoppoll">stop polling</a> |
<a href="#" id="startpoll">start polling</a>
<br>
<a href="#" id="stoppollt">stop polling twitter</a> |
<a href="#" id="startpollt">start polling twitter</a>
<div id="popup">
</div>
<div id="twitter">
</div>
<div id="errors">
</div>
</body>
</html>