-
Notifications
You must be signed in to change notification settings - Fork 1
/
age.php
173 lines (159 loc) · 5.27 KB
/
age.php
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
<?php
/* Database connection settings */
$host = 'localhost';
$user = 'utente';
$pass = 'pass123';
$db = 'dbmysql';
$mysqli = new mysqli($host, $user, $pass, $db) or die($mysqli->error);
$result1 = '';
$data1 = '';
$data2 = '';
$file = '';
if (!empty($_POST['db'])) {
$db = $_POST['db'];
if ($db == 'Image') {
$query1 = "SELECT AGE FROM `immquality` GROUP BY WORKER_ID";
$result1 = mysqli_query($mysqli, $query1);
$file = 'Image';
} else
if ($db == 'Video') {
$query2 = "SELECT AGE FROM `vidquality` GROUP BY WORKER_ID";
$result1 = mysqli_query($mysqli, $query2);
$file = 'Video';
}
while ($row = mysqli_fetch_array($result1)) {
$data1 = $data1 . '"' . $row['AGE'] . '",';
}
}
?>
<!DOCTYPE html>
<html>
<link
rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.min.js"></script>
<title>Mechanical Turk HIT Results</title>
<style type="text/css">
body {
font-family: Arial;
margin: 10px 10px 10px 10px;
padding: 0;
color: white;
text-align: center;
background: #555652;
}
.container {
color: #E8E9EB;
background: #222;
border: #555652 1px solid;
padding: 10px;
}
</style>
</head>
<body>
<div class="container">
<h1>AGE DISTRIBUTION</h1>
</div>
<form method="post" id="form">
<div class="btn-group btn-group-toggle container" data-toggle="buttons">
<label class="btn btn-secondary">
<input type="radio" name="db" id="option1" autocomplete="off"
onclick="document.getElementById('form').submit();" value="Video"> Video
</label>
<label class="btn btn-secondary">
<input type="radio" name="db" id="option2" autocomplete="off"
onclick="document.getElementById('form').submit();" value="Image"> Image
</label>
</div>
</form>
<div class="container">
<canvas id="chart"
style="width: 95%; height: 63vh; background: #222; border: 1px solid #555652; margin-top: 10px;"></canvas>
<script>
var ctx = document.getElementById("chart").getContext('2d');
var data1 = [<?php echo $data1; ?>];
var data = ['0-18', '19-39', '40-59', '60-100'];
var count = [];
for (var i = 0; i < 4; i++) {
count[i] = 0;
}
for (var j = 0; j < data1.length; j++) {
if (data1[j] === "0-18") {
count[0] += 1;
} else if (data1[j] === '19-39') {
count[1] += 1;
} else if (data1[j] === '40-59') {
count[2] += 1;
} else if (data1[j] === '60-100') {
count[3] += 1;
}
}
for (var k = 0; k < 4; k++) {
count[k] = Math.round(count[k] * 100 / data1.length);
}
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: data,
datasets:
[{
data: count,
backgroundColor: 'rgb(255,242,0,0.2)',
borderColor: 'rgb(255,242,0)',
borderWidth: 1,
}
]
},
options: {
scales: {scales: {yAxes: [{beginAtZero: false}], xAxes: [{autoskip: true, maxTicketsLimit: 20}]}},
tooltips: {mode: 'index'},
legend: {display: false},
title: {
display: true,
position: 'bottom',
text: '<?php echo $file;?>' + ' Age Percentage',
fontColor: 'rgba(255,249,255,0.5)',
fontSize: 16,
}
}
});
</script>
<div class="container">
<style>
a {
text-decoration: none;
display: inline-block;
padding: 8px 16px;
}
a:hover {
background-color: white;
color: black;
}
.previous {
background-color: white;
color: black;
float: left;
}
.next {
background-color: white;
color: black;
float: right;
}
.round {
border-radius: 50%;
}
</style>
<a href="resolution.php" class="previous round">‹</a>
<button style="font-size:16px" onclick="window.location.href='/Chart'" class="btn btn-secondary">Dashboard <i
class="fa fa-dashboard"></i>
</button>
<a href="chartFile.php" class="next round">›</a>
</div>
</div>
</body>
</html>