Last active
November 4, 2019 02:40
-
-
Save adibenc/2bb5d97e692b3eda29296f062f53caf9 to your computer and use it in GitHub Desktop.
Gerak & Gas per waktu per hari
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<?php $this->load->view("admin/_partials/head.php") ?> | |
</head> | |
<body id="page-top"> | |
<?php $this->load->view("admin/_partials/navbar.php") ?> | |
<div id="wrapper"> | |
<?php $this->load->view("admin/_partials/sidebar.php") ?> | |
<div id="content-wrapper"> | |
<div class="container-fluid"> | |
<?php $this->load->view("admin/_partials/breadcrumb.php") ?> | |
<!-- Letak Grafik --> | |
<h4>Grafik Kepadatan & Tingkat Polusi Per Hari</h4> | |
<canvas id="myChart"></canvas> | |
<?php | |
ini_set('max_execution_time', 0); | |
ini_set('memory_limit','2048M'); | |
?> | |
</div> | |
<!-- /.container-fluid --> | |
<!-- Sticky Footer --> | |
<?php $this->load->view("admin/_partials/footer.php") ?> | |
</div> | |
<!-- /.content-wrapper --> | |
</div> | |
<!-- /#wrapper --> | |
<?php $this->load->view("admin/_partials/scrolltop.php") ?> | |
<?php $this->load->view("admin/_partials/modal.php") ?> | |
<?php $this->load->view("admin/_partials/js.php") ?> | |
<!-- Grafik Chart JS --> | |
<script> | |
var bg=[ | |
'rgb(40, 178, 170, 0.2)', | |
'#B0C4DE', | |
] | |
var border=[ | |
'rgba(135, 206, 250, 1)', | |
'#00FFFF', | |
] | |
var ctx = document.getElementById('myChart').getContext('2d'); | |
var myChart; | |
function initChart(pctx,pdata){ | |
myChart = new Chart(pctx, { | |
type: 'bar', | |
data: pdata, | |
options: { | |
animation:false, | |
scales: { | |
yAxes: [{ | |
ticks: { | |
// beginAtZero: true | |
} | |
}] | |
} | |
} | |
}); | |
} | |
//ajax | |
function getData(){ | |
console.log("get") | |
$.ajax({ | |
type: 'GET', | |
url: baseurl+'index.php/api/getData', | |
data: {}, | |
success: function(data) { | |
// json = JSON.parse(data); | |
json=data | |
// alert(json.msg); | |
// myChart.data=json | |
initChart(ctx,data) | |
console.log(json) | |
} | |
}); | |
} | |
getData() | |
setInterval(getData, 10000); | |
</script> | |
</body> | |
</html> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<?php $this->load->view("admin/_partials/head.php") ?> | |
</head> | |
<body id="page-top"> | |
<?php $this->load->view("admin/_partials/navbar.php") ?> | |
<div id="wrapper"> | |
<?php $this->load->view("admin/_partials/sidebar.php") ?> | |
<div id="content-wrapper"> | |
<div class="container-fluid"> | |
<?php $this->load->view("admin/_partials/breadcrumb.php") ?> | |
<!-- Letak Grafik --> | |
<h4>Grafik Monitoring Kepadatan & Tingkat Polusi Per Waktu</h4> | |
<ul> | |
<?php | |
//dari controller | |
foreach($ls as $d){ | |
?> | |
<li> | |
<a href="<?php echo base_url().'index.php/grafik/'.$d; ?>"> | |
Ke tanggal <?php echo $d; ?> | |
</a> | |
</li> | |
<?php | |
} | |
?> | |
</ul> | |
<canvas id="myChart"></canvas> | |
<?php | |
// echo $statistik; | |
?> | |
<table class="table"> | |
<thead> | |
<tr> | |
<th rowspan="2">Nilai</th> | |
<th colspan="3">Rata-rata Gas</th> | |
<th colspan="3">Jumlah Gerak</th> | |
</tr> | |
<tr> | |
<th>07-08</th> | |
<th>11-12</th> | |
<th>16-17</th> | |
<th>07-08</th> | |
<th>11-12</th> | |
<th>16-17</th> | |
</tr> | |
</thead> | |
<tbody> | |
<?php | |
// var_dump($statistik); | |
foreach($statistik as $s){ | |
?> | |
<tr> | |
<td><?php echo $s->nama;?></td> | |
<td><?php echo $s->dgaPagi;?></td> | |
<td><?php echo $s->dgaSiang;?></td> | |
<td><?php echo $s->dgaSore;?></td> | |
<td><?php echo $s->dgePagi;?></td> | |
<td><?php echo $s->dgeSiang;?></td> | |
<td><?php echo $s->dgeSore;?></td> | |
</tr> | |
<?php | |
} | |
?> | |
</tbody> | |
</table> | |
</div> | |
<!-- /.container-fluid --> | |
<!-- Sticky Footer --> | |
<?php $this->load->view("admin/_partials/footer.php") ?> | |
</div> | |
<!-- /.content-wrapper --> | |
</div> | |
<!-- /#wrapper --> | |
<?php $this->load->view("admin/_partials/scrolltop.php") ?> | |
<?php $this->load->view("admin/_partials/modal.php") ?> | |
<?php $this->load->view("admin/_partials/js.php") ?> | |
<!-- Grafik Chart JS --> | |
<script> | |
// var ctx = document.getElementById('myChart').getContext('2d'); | |
var ctx = document.getElementById('myChart').getContext('2d'); | |
var myChart; | |
function initChart(pctx,pdata){ | |
myChart = new Chart(pctx, { | |
type: 'bar', | |
data: pdata, | |
options: { | |
animation:false, | |
scales: { | |
yAxes: [{ | |
ticks: { | |
// beginAtZero: true | |
} | |
}] | |
} | |
} | |
}); | |
} | |
//ajax | |
function getData(){ | |
console.log("get") | |
$.ajax({ | |
type: 'GET', | |
url: baseurl+'index.php/api/getDataWaktu', | |
data: { | |
tanggal:'<?php echo $tgl;?>' | |
}, | |
success: function(data) { | |
// json = JSON.parse(data); | |
json=data | |
// alert(json.msg); | |
// myChart.data=json | |
initChart(ctx,data) | |
console.log(json) | |
} | |
}); | |
} | |
getData() | |
setInterval(getData, 10000); | |
</script> | |
</body> | |
</html> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Gerak_model extends CI_Model{ | |
function tampil_data(){ | |
$data = $this->db->get('data_gerak'); | |
} | |
function input_data($data,$table){ | |
$this->db->insert($table,$data); | |
} | |
// $time1 = $tanggal." ".($waktu-1).':'.'00'.':'.'00'; | |
// $time2 = $tanggal." ".($waktu).':'.'00'.':'.'00'; | |
// $query = "SELECT count(*) as jumlah FROM data_gerak WHERE tanggal BETWEEN '".$time1."' and '".$time2."'"; | |
// -- group by substr(tanggal,1,10)"; | |
// echo $this->db->last_query(); | |
// return $this->db->last_query(); | |
function getDataByTime($tanggal=0){ | |
$query = "SELECT count(*) as jumlah FROM data_gerak WHERE substr(tanggal,1,10)='".$tanggal."'"; | |
$data = $this->db->query($query)->row(); | |
return $data->jumlah; | |
} | |
function getDataGroupDay(){ | |
$time1 = $tanggal." ".($waktu-1).':'.'00'.':'.'00'; | |
$time2 = $tanggal." ".($waktu).':'.'00'.':'.'00'; | |
$query = "SELECT count(*) as jumlah FROM data_gerak | |
group by substr(tanggal,1,10)"; | |
$data = $this->db->query($query); | |
// return $this->db->last_query(); | |
return $data; | |
} | |
function getPerHour($time1, $time2, $date){ | |
$query = 'SELECT count(*) as jumlah | |
FROM `data_gerak` | |
WHERE date(tanggal) = "'.$date.'" and hour(tanggal) | |
BETWEEN "'.$time1.'" and "'.$time2.'"'; | |
$q=$this->db->query($query); | |
return $q->result_array(); | |
} | |
function truncateData(){ | |
$query = "TRUNCATE TABLE data_gerak"; | |
$this->db->query($query); | |
} | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ini_set('max_execution_time', 0); | |
ini_set('memory_limit','2048M'); | |
defined('BASEPATH') OR exit('No direct script access allowed'); | |
class Data{ | |
} | |
class Grafik extends CI_Controller | |
{ | |
public function __construct() | |
{ | |
parent::__construct(); | |
$this->load->model("Grafik_model"); | |
$this->load->model("Gerak_model"); | |
$this->load->library('form_validation'); | |
} | |
public function index($date) | |
{ | |
$data["g_perwaktu"] = $this->Product_model->getAll(); | |
$data['tgl'] = $date; | |
$this->load->view("admin/product/g_perwaktu2", $data); | |
} | |
public function getPerHari() | |
{ | |
// $data["g_perhari"] = $this->Grafik_model->getPerDay(); | |
// $data['tgl'] = $date; | |
// $data["perWaktu"] =$this->Grafik_model->getPerHour() | |
$this->load->view("admin/product/g_perhari"); | |
} | |
public function getPerJam($date='2019-08-05') | |
{ | |
$data["g_perwaktu"] = $this->Product_model->getAll(); | |
$data['tgl'] = $date; | |
$dir = "data/"; | |
$files = scandir($dir); | |
$data['ls']=$this->getDir(); | |
$data['statistik']=$this->getStatistik($date); | |
$this->load->view("admin/product/g_perwaktu",$data); | |
} | |
public function preout($v=""){ | |
// echo "<pre>"; | |
var_dump($v); | |
// echo "</pre>"; | |
} | |
public function getDir($dir='data/'){ | |
$files = scandir($dir); | |
// print_r($files); | |
//gen label tanggal | |
$arrayTanggal=[]; | |
$at=0; | |
foreach($files as $f){ | |
if($at<2){ | |
$at++; | |
continue; | |
} | |
$st=substr($f,0,4)."-".substr($f,4,2)."-".substr($f,6,2); | |
// echo $st; | |
$arrayTanggal[]=$st; | |
$at++; | |
} | |
return $arrayTanggal; | |
} | |
public function getData(){ | |
header('Content-Type:text/json'); | |
$dir = "data/"; | |
$files = scandir($dir); | |
// print_r($files); | |
//gen label tanggal | |
$arrayTanggal=$this->getDir(); | |
$labels=$arrayTanggal; | |
$datasets=[]; | |
$data=[ | |
["Sensor Gas",'rgb(40, 178, 170, 0.2)','rgba(135, 206, 250, 1)'], | |
["Gerakan",'#B0C4DE','#00FFFF'] | |
]; | |
$dc=0; | |
foreach($data as $d){ | |
$singleset=new Data(); | |
$singleset->label=$d[0]; | |
$dataarr=[]; | |
$bgarr=[]; | |
$borderarr=[]; | |
// get from db | |
//iterate | |
foreach($arrayTanggal as $att){ | |
$jumlah=""; | |
if($dc==0){ | |
//get data gas by tanggal | |
$jumlah = $this->Grafik_model->getDataByTime($att); | |
}else{ | |
//get data gerak by tanggal | |
$jumlah = $this->Gerak_model->getDataByTime($att); | |
} | |
$dataarr[]=$jumlah; | |
} | |
foreach($labels as $l){ | |
$dbarr=[]; | |
$bgarr[]=$d[1]; | |
$borderarr[]=$d[2]; | |
} | |
// $dataarr=$dbarr; | |
$singleset->data=$dataarr; | |
$singleset->backgroundColor=$bgarr;//json_encode(); | |
$singleset->borderColor=$borderarr;//json_encode($borderarr); | |
$singleset->borderWidth=1; | |
$datasets[]=$singleset; | |
$dc++; | |
} | |
$ret=new Data(); | |
$ret->labels=$labels; | |
$ret->datasets=$datasets; | |
echo json_encode($ret); | |
} | |
public function getDataWaktu($tanggal='2019-08-05'){ | |
header('Content-Type:text/json'); | |
// print_r($files); | |
//gen label tanggal | |
$tanggal=$this->input->get('tanggal'); | |
$labels=[ | |
['07','08','Pagi'], | |
['11','12','Siang'], | |
['16','17','Sore'], | |
]; | |
$datasets=[]; | |
$data=[ | |
["Jumlah Kepadatan",'#B0C4DE','#00FFFF'], | |
["Rata-rata Polusi Per Tanggal",'rgb(40, 178, 170, 0.2)','rgba(135, 206, 250, 1)'], | |
]; | |
$dc=0; | |
foreach($data as $d){ | |
$singleset=new Data(); | |
$singleset->label=$d[0]; | |
$dataarr=[]; | |
$bgarr=[]; | |
$borderarr=[]; | |
// get from db | |
//iterate | |
foreach($labels as $att){ | |
$jumlah=""; | |
if($dc==0){ | |
//get data gerak by time tgl | |
$jumlah = $this->Gerak_model->getPerHour($att[0], $att[1], $tanggal)[0]['jumlah']; | |
}else{ | |
//get data gas by time tgl | |
$jumlah = $this->Grafik_model->getPerHour($att[0], $att[1], $tanggal)->rata; | |
} | |
// $dbarr[]=$jumlah; | |
$dataarr[]=$jumlah; | |
} | |
foreach($labels as $l){ | |
$dbarr=[]; | |
$bgarr[]=$d[1]; | |
$borderarr[]=$d[2]; | |
} | |
// $dataarr=$dbarr; | |
$singleset->data=$dataarr; | |
$singleset->backgroundColor=$bgarr;//json_encode(); | |
$singleset->borderColor=$borderarr;//json_encode($borderarr); | |
$singleset->borderWidth=1; | |
$datasets[]=$singleset; | |
$dc++; | |
} | |
$ret=new Data(); | |
$ret->labels=$labels; | |
$ret->datasets=$datasets; | |
echo json_encode($ret); | |
} | |
public function getStatistik($tanggal='2019-08-05'){ | |
$tgl=$tanggal; | |
$st=[]; | |
$dgaPagi =$this->Grafik_model->getPerHour('07', '08', $tgl)->rata; | |
$dgaSiang =$this->Grafik_model->getPerHour('11', '12', $tgl)->rata; | |
$dgaSore =$this->Grafik_model->getPerHour('16', '17', $tgl)->rata; | |
$dgePagi =$this->Gerak_model->getPerHour('07', '08', $tgl)[0]['jumlah']; | |
$dgeSiang =$this->Gerak_model->getPerHour('11', '12', $tgl)[0]['jumlah']; | |
$dgeSore =$this->Gerak_model->getPerHour('16', '17', $tgl)[0]['jumlah']; | |
$data=["Nilai",]; | |
$ret=[]; | |
foreach($data as $d){ | |
$da=new Data(); | |
$da->nama=$d; | |
$da->dgaPagi=$dgaPagi?$dgaPagi:0; | |
$da->dgaSiang=$dgaSiang?$dgaSiang:0; | |
$da->dgaSore=$dgaSore?$dgaSore:0; | |
$da->dgePagi=$dgePagi?$dgePagi:0; | |
$da->dgeSiang=$dgeSiang?$dgeSiang:0; | |
$da->dgeSore=$dgeSore?$dgeSore:0; | |
$d=$da; | |
$ret[]=$d; | |
} | |
// $st=$data; | |
// var_dump($st); | |
return $ret; | |
} | |
public function getgerak(){ | |
$this->Gerak_model->truncateData(); | |
$dir = "data/"; | |
$files = scandir($dir); | |
//print_r($files); | |
for($i=0;$i<count($files);$i++) | |
{ if(substr($files[$i],0,4)=='2019') | |
{ | |
// echo "Folder = ".$files[$i]." berisi : <br/>"; | |
// $files[$i] = $dir."/".$files[$i]; | |
$file_avi = scandir($dir."/".$files[$i]); | |
$no=1; | |
for($j=0;$j<count($file_avi);$j++) | |
{ if(substr($file_avi[$j],-4)=='.avi') | |
{ | |
$path_file_avi = $files[$i]."/".$file_avi[$j]; | |
// masukkan ke db dan buat grafiknya, digabung dgn data mq7 | |
// echo $no.". ".$file_avi[$j]." >> ".date("d-m-Y H:i:s",filemtime($path_file_avi))." >> ".filesize($path_file_avi)." byte <br/>"; | |
//======================================================================================== | |
// mecah waktu | |
//======================================================================================== | |
$array_name = explode("_", $file_avi[$j]); | |
$waktuText = $array_name[3]; | |
$waktuTextArray = str_split($waktuText); | |
$waktu=$waktuTextArray[0].$waktuTextArray[1].":".$waktuTextArray[2].$waktuTextArray[3].":".$waktuTextArray[4].$waktuTextArray[5]; | |
$tanggal = $files[$i]." ".$waktu; | |
$nama = $file_avi[$j]; | |
//======================= | |
$data = array( | |
'nama' => $nama, | |
'tanggal' => $tanggal, | |
); | |
$this->Gerak_model->input_data($data,'data_gerak'); | |
// echo $no.". ".$file_avi[$j]." >> ".date("d-m-Y H:i:s",filemtime($path_file_avi))." >> ".filesize($path_file_avi)." byte <br/>"; | |
$no++; | |
} | |
} | |
} | |
} | |
echo "Sukses Simpan!"; | |
} | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Grafik_model extends CI_Model{ | |
function report(){ | |
$query = $this->db->query("SELECT * from gas"); | |
if($query->num_rows() > 0){ | |
foreach($query->result() as $data){ | |
$hasil[] = $data; | |
} | |
return $hasil; | |
} | |
} | |
// $time1 = $tanggal." ".($waktu-1).':'.'00'.':'.'00'; | |
// $time2 = $tanggal." ".($waktu).':'.'00'.':'.'00'; | |
// $query = "SELECT count(*) as jumlah FROM data_gerak WHERE tanggal BETWEEN '".$time1."' and '".$time2."'"; | |
function getDataByTime($tanggal=0){ | |
$query = "SELECT count(*) as jumlah FROM gas WHERE substr(waktu,1,10)='".$tanggal."'"; | |
$data = $this->db->query($query)->row(); | |
return $data->jumlah; | |
} | |
function getPerHour($time1, $time2, $date){ | |
$query = 'SELECT AVG(ppm) as rata,count(*) as jumlah | |
FROM `gas` WHERE date(waktu) = "'.$date.'" and hour(waktu) BETWEEN "'.$time1.'" and "'.$time2.'"'; | |
$q=$this->db->query($query); | |
return $q->row(); | |
} | |
function getPerDay($date){ | |
$query = 'SELECT AVG(ppm) as rata FROM `gas` WHERE date(waktu) = "'.$date.'"'; | |
return $this->db->query($query)->result_array(); | |
} | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no"> | |
<title><?php echo SITE_NAME .": ". ucfirst($this->uri->segment(1)) ." - ". ucfirst($this->uri->segment(2)) ?></title> | |
<!-- Bootstrap core CSS--> | |
<link href="<?php echo base_url('assets/bootstrap/css/bootstrap.min.css') ?>" rel="stylesheet"> | |
<!-- Custom fonts for this template--> | |
<link href="<?php echo base_url('assets/fontawesome-free/css/all.min.css') ?>" rel="stylesheet" type="text/css"> | |
<!-- Page level plugin CSS--> | |
<link href="<?php echo base_url('assets/datatables/dataTables.bootstrap4.css') ?>" rel="stylesheet"> | |
<!-- Custom styles for this template--> | |
<link href="<?php echo base_url('css/sb-admin.css') ?>" rel="stylesheet"> | |
<script> | |
var baseurl='<?php echo base_url();?>'; | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$route['default_controller'] = 'welcome'; | |
$route["products"] = "admin/products"; | |
$route["grafik2/(:any)"] = "admin/grafik/index/$1"; | |
$route["grafik/(:any)"] = "admin/grafik/getPerJam/$1"; | |
$route["harian"] = "admin/grafik/getPerHari"; | |
$route["simpan-data"] = "admin/grafik/getgerak"; | |
$route["api/getData"] = "admin/grafik/getData"; | |
$route["api/getDataWaktu"] = "admin/grafik/getDataWaktu"; | |
$route["contoh/(:any)"] = "admin/grafik/contoh/$1"; | |
$route['404_override'] = ''; | |
$route['translate_uri_dashes'] = FALSE; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment