-
Notifications
You must be signed in to change notification settings - Fork 5
/
sentimen.php
executable file
·181 lines (167 loc) · 5.12 KB
/
sentimen.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
174
175
176
177
178
179
180
181
<?php
include 'view/header.php';
if(isset($_POST['submit'])){
$donutData = '';
$barData = '';
$key = $_POST['key'];
$total = $db->query("SELECT label FROM tweets WHERE hastag = '$key'")->count();
$labels = $db->query("SELECT label FROM tweets WHERE hastag = '$key' GROUP BY label")->get();
foreach($labels as $label){
$label = $label['label'];
$datas[$label] = number_format(($db->query("SELECT label FROM tweets WHERE hastag = '$key' AND label = '$label'")->count() / $total) * 100, 2);
}
foreach($datas as $index => $val){
if($index == 'positif'){
$warna = '#00a65a';
}elseif($index == 'negatif'){
$warna = '#dd4b39';
}elseif($index == 'netral'){
$warna = '#00c0ef';
}
$donutData .= "{ label: '$index', data: $val, color: '$warna' },\n";
$barData .= "['$index', $val],";
}
}
$db->clear();
?>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Main content -->
<section class="content container-fluid">
<div class="row">
<div class="col-md-12">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">Pilih Data</h3>
</div>
<div class="box-body">
<form action="" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="file">Kata Kunci ( hastag ) </label>
<select class="form-control" name="key">
<?php foreach($db->query("SELECT hastag FROM `tweets` GROUP BY hastag")->get() as $hastag):?>
<option value="<?= $hastag['hastag'] ?>"> <?= $hastag['hastag'] ?> </option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<input type="submit" value="Lihat Hasil" name="submit" class="btn btn-primary">
</div>
</form>
</div>
</div>
</div>
<?php if(isset($key)): ?>
<!-- ROW 6 -->
<div class="col-md-6">
<!-- Donut chart -->
<div class="box box-primary">
<div class="box-header with-border">
<i class="fa fa-bar-chart-o"></i>
<h3 class="box-title">Hasil Analisis : <?= $key ?> </h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
</button>
<button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
</div>
</div>
<div class="box-body">
<div id="donut-chart" style="height: 300px;"></div>
<p>Jumlah Tweet : <?= $total ?></p>
</div>
<!-- /.box-body-->
</div>
<!-- /.box -->
</div>
<div class="col-md-6">
<div class="box box-primary">
<div class="box-header with-border">
<i class="fa fa-bar-chart-o"></i>
<h3 class="box-title">Hasil Analisis : <?= $key ?> </h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
</button>
<button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
</div>
</div>
<div class="box-body">
<div id="bar-chart" style="height: 300px;"></div>
<p>Jumlah Tweet : <?= $total ?></p>
</div>
<!-- /.box-body-->
</div>
</div>
<?php endif; ?>
</div>
</section>
<!-- /.content -->
</div>
<!-- /.content-wrapper -->
<?php
if(isset($key)):
setJs("
/*
* BAR CHART
* ---------
*/
var bar_data = {
data : [$barData],
color: '#3c8dbc'
}
$.plot('#bar-chart', [bar_data], {
grid : {
borderWidth: 1,
borderColor: '#f3f3f3',
tickColor : '#f3f3f3'
},
series: {
bars: {
show : true,
barWidth: 0.5,
align : 'center'
}
},
xaxis : {
mode : 'categories',
tickLength: 0
}
})
/* END BAR CHART */
/*
* DONUT CHART
* -----------
*/
var donutData = [
$donutData
]
$.plot('#donut-chart', donutData, {
series: {
pie: {
show : true,
radius : 1,
innerRadius: 0.5,
label : {
show : true,
radius : 2 / 3,
formatter: labelFormatter,
threshold: 0.1
}
}
},
legend: {
show: false
}
})
/*
* END DONUT CHART
*/
function labelFormatter(label, series) {
return \"<div style='font-size:13px; text-align:center; padding:2px; color: #fff; font-weight: 600;'>\"
+ label
+ '<br>'
+ Math.round(series.percent) + '%</div>'
}
");
endif;
include 'view/footer.php';
?>