-
Notifications
You must be signed in to change notification settings - Fork 0
/
reader.html
113 lines (99 loc) · 3.4 KB
/
reader.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
<!DOCTYPE html>
<html style="height:100%">
<head>
<meta charset="UTF-8">
<title>title</title>
</head>
<body style="position:relative; width:100%; height:100%;">
<iframe id="viewer" src="" style="width:100%; height:80%;"> </iframe>
<div id="name"> </div>
<div id="choices" style="display:flex; flex-direction:row;">
<div style="margin:0 5px 0 5px"> reuseChoice: </div><div id="reuseChoice"> </div>
<div style="margin:0 5px 0 5px"> currentEventChoice: </div><div id="currentEventChoice"> </div>
</div>
<button onclick="flipChoice('reuseChoice')">Mark as Re-use</button>
<button onclick="flipChoice('currentEventChoice')">Mark as Current Event</button>
<button onclick="goNext()">Next</button>
<button onclick="reset()">Reset</button>
<button onclick="updateMode()">Change Mode</button>
<div id="currentMode"> </div>
<button onclick="saveCSV()">Save Progress to CSV</button>
</body>
<script>
var globalCounter = 0;
var mode = 'reddit';
var data = [];
var choices = {};
var filename = false;
function goNext() {
if(filename !== false){
var dataRow = [filename, choices['currentEventChoice'], choices['reuseChoice']];
data.push(dataRow);
}
filename = '';
if(mode === 'reddit') {
filename += 'SampledRedditThread';
} else {
filename += 'SampledStackOverflowPost';
}
filename += `_sample${globalCounter}of10.html`;
document.getElementById('name').innerHTML = filename;
document.getElementById('viewer').src = filename;
globalCounter += 1;
resetChoices();
}
function reset() {
globalCounter = 0;
}
function updateMode() {
if (mode === 'reddit') {
mode = 'StackOverflow';
document.getElementById("currentMode").innerHTML = 'StackOverflow';
} else {
mode = 'reddit'
document.getElementById("currentMode").innerHTML = 'reddit';
}
}
function resetChoices() {
mark('reuseChoice', 0);
mark('currentEventChoice', 0)
}
function flipChoice(choice) {
var newVal = !choices[choice];
mark(choice, newVal);
}
function mark(choice, val) {
choices[choice] = Number(val);
document.getElementById(choice).innerHTML = val;
}
function saveCSV() {
console.log('write');
var csvContent = "data:text/csv;charset=utf-8,";
data.forEach(function(infoArray, index){
dataString = infoArray.join(",");
csvContent += index < data.length ? dataString+ "\n" : dataString;
});
console.log(data);
var encodedUri = encodeURI(csvContent);
var link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "classifications.csv");
document.body.appendChild(link);
link.click();
}
window.onkeyup = function(e) {
var key = e.keyCode ? e.keyCode : e.which;
if (key == 82) { // r
flipChoice('reuseChoice');
} else if (key == 67) { // c
flipChoice('currentEventChoice');
} else if (key == 13) { // enter
goNext();
} else if (key == 83) { //s
saveCSV();
}
}
goNext()
resetChoices()
</script>
</html>