Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

egi's repo catching up and fixed bug with xml out #1

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,29 @@ kemudian ternyata setelah otomatisasi berjalan dengan baik, tiba-tiba
sumber data mengubah pola datanya sehingga regex pengumpul data tidak
sesuai lagi.
-- Youppie Arliansyah

location database
- Key harus bisa diquery dan dalam bentuk tree
- output bisa dalam berbagai versi (xls, csv, json)
- ada versioning.
- perbedaan versi bisa di 'diff' sehingga ketidakvalidan user data bisa langsung
dihighlight
- location database dimiliki oleh admin
- best saved in sqlite

data
- merefer ke location_id dari versi tertentu dari location database
- dimiliki oleh user
- cannot be queried.
- hanya bisa di download sebagai data penuh, dalam berbagai versi
(xls, csv, json)
- waktu upload akan dicek validitas key
- waktu insert data, user bisa download location key terlebih dahulu.
- location key bisa subset di daerah tertentu saja
- orang lain bisa branching data
- best saved in csv
- metadata saved in ini:
- info referal: location database versi tertentu, scope filters
- data owner (user)
- column description
- version data: time, comment
4 changes: 2 additions & 2 deletions data/kabupaten.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ tanggal_dibuat:2010-11-17
nama_file:kabupaten.txt
deskripsi:Data Kabupaten Indonesia, sumber data diambil dari sumbangan Wida Sari dari file group ID-PHP
kegunaan:Demo
lokasi:data/yopi/kabupaten.txt
lokasi:data/kabupaten.txt
primary_key:Id_Kabupaten
sifat_tabel:master;hirarki
struktur_tabel:Id_Kabupaten;Nama_Kabupaten
Expand Down Expand Up @@ -437,4 +437,4 @@ Id_Kabupaten;Nama_Kabupaten
64.73.00.0000;KOTA TARAKAN
64.74.00.0000;KOTA BONTANG
13.01.00.0000;KABUPATEN PESISIR SELATAN
</DATA>
</DATA>
File renamed without changes.
6 changes: 3 additions & 3 deletions data/wilayah.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ author:Youppie Arliansyah
email:[email protected]
tanggal_dibuat:2010-11-17
nama_file:wilayah.txt
deskripsi:Data Wilayah Indonesia, sumber data diambil dari sumbangan Wida Sari dari file group ID-PHP
deskripsi:Data Wilayah (Propinsi, Kabupaten, Kecamatan) Indonesia, sumber data diambil dari sumbangan Wida Sari dari file group ID-PHP
kegunaan:Demo
lokasi:data/yopi/wilayah.txt
lokasi:data/wilayah.txt
primary_key:kode_wilayah
sifat_tabel:master;hirarki
struktur_tabel:kode_wilayah;nama_wilayah
Expand Down Expand Up @@ -68441,4 +68441,4 @@ Id_Kelurahan;Nama_Kelurahan
64.74.03.1001;BELIMBING
64.74.03.1002;GUNUNG TELIHAN
64.74.03.1003;KANAAN
</DATA>
</DATA>
1 change: 1 addition & 0 deletions graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

$ticks_str = "['".(implode("','", $ticks))."']";

$data_strs = array();
$data_str = "[";
foreach($plot_data as $index=>$data)
{
Expand Down
20 changes: 12 additions & 8 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@
* @since 2010-11-13 23:35
* @last_update 2011-12-09 07:48 - IL
*/
if (!file_exists('config.php'))
die(__('config.php tidak ditemukan. Buat config.php dari config.sample.php'));

require_once('config.php');
require_once('lib/php/catalog.class.php');
require_once('lib/php/output.class.php');
require_once('lib/php/gdi.class.php');
require_once('lib/gettext/gettext.inc');

if (!file_exists('config.php'))
die(__('config.php tidak ditemukan. Buat config.php dari config.sample.php'));

require_once('config.php');

// Locale
$locale = 'id';
T_setlocale(LC_MESSAGES, $locale);
Expand All @@ -25,20 +27,22 @@

// Process query or get catalog
$TITLE = 'Gudang Data Indonesia';
$query = $_GET['q'];
$output = $_GET['o'];
$ACTION = '';
$query = isset($_GET['q']) ? $_GET['q'] : null;
$output = isset($_GET['o']) ? $_GET['o'] : null;
if (isset($query))
{
$gdi = new gdi();
$query = file_exists(DATA_DIR . $query .'.txt') ? $query : DEFAULT_DATA;
$output = class_exists($output) ? $output : DEFAULT_OUTPUT;
$data = $gdi->get_data($query, $output);
$o = new $output;
$data = $gdi->get_data($query, $output);
$CONTENT = $o->out($data);
if (in_array($output, array('meta', 'html', 'graph')))
{
$meta = $gdi->get_meta($query, $output);
if ($output == 'meta') $CONTENT = json_encode($meta);
if ($output == 'meta')
$CONTENT = $o->out($meta);
$TITLE = $meta['deskripsi'];
$types = json_decode('{"html":"","meta":"","graph":"","csv":"","json":"","xml":""}', true);
foreach ($types as $key => $val)
Expand All @@ -59,7 +63,7 @@
}

// Further process if else
$MENU .= '<li><a href="./?">Katalog</a></li>';
$MENU = '<li><a href="./?">Katalog</a></li>';
$MENU .= '<li><a href="#">Dataset baru</a></li>';
$MENU = '<ul class="menu">' . $MENU . '</ul>';
$HEADER = sprintf('<h2>%1$s</h2>', $TITLE) . $MENU . $ACTION;
Expand Down
4 changes: 2 additions & 2 deletions lib/php/catalog.class.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function get_catalog($dir)
*/
function render_catalog()
{
$ret .= '<ul>';
$ret = '<ul>';
foreach($this->data_sets as $data)
{
$ret .= sprintf(
Expand All @@ -57,4 +57,4 @@ function render_catalog()
return($ret);
}
}
?>
?>
2 changes: 1 addition & 1 deletion lib/php/gdi.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class gdi
{
function get_data($file_data, $output='html')
function get_data($file_data, $output='dummy')
{
$handle=fopen(DATA_DIR.$file_data.'.txt',"r");

Expand Down
30 changes: 25 additions & 5 deletions lib/php/gdi_yopi.class.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
*
* @author Yopi <[email protected]>
* @since 2010-11-17
* @last_update Wida Sari <[email protected]> 2011-10-05 11:18
**/

class gdi
{
private $path_data="data/yopi/";
function get_data($file_data)
function get_data($file_data, $output='html')
{
$handle=fopen($this->path_data.$file_data.'.txt',"r");
$handle=fopen(DATA_DIR.$file_data.'.txt',"r");

//ambil meta data;
fgets($handle);
Expand All @@ -23,8 +23,6 @@ function get_data($file_data)
else {$bacafile=0;}
}

//print_r($meta);

/**/
//ambil struktur data
$meta['struktur_tabel']=explode(";",trim($meta['struktur_tabel']));
Expand Down Expand Up @@ -52,4 +50,26 @@ function get_data($file_data)
fclose($handle);
return $data;
}

function get_meta($file_data, $output)
{
$handle=fopen(DATA_DIR.$file_data.'.txt',"r");

//ambil meta data;
fgets($handle);
$bacafile=1;
$meta=Array();
while($bacafile){
$itemmeta=explode(":",fgets($handle));
if (isset($itemmeta[1])) $meta[$itemmeta[0]]=$itemmeta[1];
else {$bacafile=0;}
}

/**/
//ambil struktur data
$meta['struktur_tabel']=explode(";",trim($meta['struktur_tabel']));
fclose($handle);
return $meta;

}
}
24 changes: 20 additions & 4 deletions lib/php/output.class.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ function out($result)

class xml implements output
{
/**
* make valid tag names from keyName. valid tag names only contain
* alphanumeric and underscore characters.
**/
private function _to_tag($key)
{
$key = preg_replace(array('/ /', '/[^A-Z0-9_]/i'), array('_', ''), $key);
return $key;
}

/**
* Array to XML
*/
Expand All @@ -76,7 +86,8 @@ private function array_to_xml(&$array)
$keyName = is_numeric($key) ? 'elm' . $key : $key;
if (!is_array($value))
{
$ret .= sprintf('<%1$s>%2$s</%1$s>', $keyName, $value) . LF;
$ret .= sprintf('<%1$s title="%3$s">%2$s</%1$s>',
$this->_to_tag($keyName), $value, $keyName) . LF;
}
else
{
Expand Down Expand Up @@ -105,12 +116,17 @@ function out($apiData)
class json implements output
{
/**
* output JSON
* output JSON.
* Need to comply to Cross-Origin Resource Sharing (CORS) standard to be
* usable by other sites.
*
* @see https://developer.mozilla.org/En/HTTP_Access_Control
*/
function out($apiData)
{
$data = array('gdi'=>$apiData);
$ret = json_encode($data);
header('Access-Control-Allow-Origin: *');
header('Content-type: application/json');
return($ret);
}
Expand All @@ -136,8 +152,8 @@ class meta implements output
function out($apiData)
{
$data = array('gdi'=>$apiData);
return $apiData;
return json_encode($apiData);
}
}

?>
?>
27 changes: 27 additions & 0 deletions www/contoh_dropdown_propinsi.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<html>
<head>
<script language="javascript" type="text/javascript" src="../lib/jqplot/jquery.min.js"></script>
</head>
<body>

Provinsi: <select id="options" />

<script>
$().ready(function() {
$.ajax({
type: 'GET',
url: 'http://gdi.id-php.org/?q=provinsi&o=json',
contentType: "text/plain",
dataType: 'json',
success: function(result) {
var options = $("#options");
$.each(result.gdi, function() {
options.append($("<option />").val(this.kode_wilayah).text(this.nama_wilayah));
});
}
});
});
</script>

</body>
</html>