-
Notifications
You must be signed in to change notification settings - Fork 0
/
results.html
105 lines (88 loc) · 2.78 KB
/
results.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
<style>
.ct-series-a .ct-bar {
stroke: rgb(43, 152, 132);
/* stroke-linecap: round; */
}
.ct-series-b .ct-bar {
stroke: rgb(123, 200, 178);
/* stroke-linecap: round; */
}
.ct-label {
font-size: 10px;
}
</style>
<div class="row">
<div class="col-md-12">
<h2>Results for task <span id="task_id"></span></h2>
</div>
</div>
<div class="row">
<div id="img" class="col-md-4"></div>
<div class="col-md-3">
<div class="ct-chart ct-square"></div>
<button id="prevResult" class="btn btn-default">Check previous result</button>
<button id="nextResult" class="btn btn-default">Check next result</button>
</div>
</div>
<script>
window.last_result_id = [0];
window.project_id = 3472;
function show_a_result(last_result_id) {
if (last_result_id == 0) {
var url = "//crowdcrafting.org/api/result?project_id=" + window.project_id + "&limit=1";
$("#prevResult").hide();
}
else {
$("#prevResult").show();
var url = "//crowdcrafting.org/api/result?project_id=" + window.project_id + "&last_id=" + last_result_id + "&limit=1";
}
var xhrResult = $.ajax({
url: url,
dataType: "json",
});
xhrResult.done(function( results ) {
var result = results[0];
var taskURL = "//crowdcrafting.org/api/task/" + result.task_id;
window.last_result_id.push(result.id);
var xhrTask = $.ajax({
url: taskURL,
dataType: "json",
}).done(function(task){
$("#task_id").text(task.id);
var img = $("<img/>");
img.attr("src", task.info.url_b);
img.addClass("img-responsive");
$("#img").html("").append(img);
createChart(result);
});
});
}
function createChart(result) {
var labels = [];
var series = [];
for ( var label in result.info.analysis) {
labels.push(label);
// var pct = (result.info.analysis[label] * 100) / result.info.summary.count;
series.push(result.info.analysis[label]);
}
new Chartist.Bar('.ct-chart', {
labels: labels,
series: series,
}, {
distributeSeries: true,
axisY: {onlyInteger: true}
});
}
show_a_result(window.last_result_id[0]);
$("#nextResult").off('click').on('click', function(e){
var index = window.last_result_id.length - 1;
show_a_result(window.last_result_id[index]);
});
$("#prevResult").off('click').on('click', function(e){
var index = window.last_result_id.length - 3;
var previous_id = window.last_result_id[index];
window.last_result_id.pop();
window.last_result_id.pop();
show_a_result(previous_id);
});
</script>