Commit 38779753 authored by cividesk's avatar cividesk

Adding historical report

parent 50a5fe47
......@@ -18,6 +18,7 @@ done
# Regenerate statistics and push to destination
php generate.php
php historical.php
rsync -a json $DEST
# create .htaccess to allow access from anywhere (cf. CORS for $.getJSON)
echo 'Header add Access-Control-Allow-Origin "*"' > $DEST/.htaccess
......
<?php
$historical = __DIR__ . '/json/historical';
chdir(__DIR__ . '/../archive/');
$reports = array(
'active-sites-version.json' => array(
'start_date' => '2015-12-01',
'increment' => '1 month',
'key' => 'short_version',
'value' => 'num_sites',
),
);
foreach($reports as $file => $params) {
$dir = $params['start_date'];
$report = array();
while(file_exists("$dir/$file")) {
$data = json_decode(file_get_contents("$dir/$file"), true);
if (empty($params['key'])) {
$report[$dir] = $data;
} else {
$results = array();
foreach ($data as $result) {
$results[$result[$params['key']]] = $result[$params['value']];
}
$report[$dir] = $results;
}
$dir = date('Y-m-d', strtotime("$dir + $params[increment]"));
}
file_put_contents("$historical/$file", json_encode($report));
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment