Exemplo n.º 1
0
        $result = $sth->fetchAll(PDO::FETCH_ASSOC);
        foreach ($result as $r) {
            $out[] = array((double) $r['datetime'], (double) $r['hiveweight']);
        }
        break;
    case "weight_data":
        $sth = $conn->prepare("SELECT hiveid, date, hiveweight, hiverawweight FROM allhivedata WHERE date > datetime('now','{$sqlperiod}') ORDER BY date");
        $sth->execute();
        break;
}
switch ($output) {
    case "csv":
        export_csv($sth, $type, $period);
        break;
    case "json":
        export_json($sth);
        break;
    case "highcharts":
        export_highcharts($out);
        break;
}
#echo "Period is $sqlperiod";
#echo "Type is $type";
// Get Weather/Hive Data First - from a DB view, this may be very slow
function export_highcharts($out)
{
    //?type=temp&period=month&output=highcharts'
    // Convert time to Unix EPOCH, output one value only.
    // Format should be in JSON format, and look like this
    // [122869440000000,14.25],
    // for each series.
    // double check total processed with running totals
    if ($total != $cat_checksum) {
        exit("ERR: MISMATCH! in category: " . $cat_name);
    }
}
## FINSHING
// puts categorized data in Android XML resource file
file_put_contents($oufile_xml, export_xml($output_xml_cat));
// puts un-categorized data into a single string-array in Android XML
file_put_contents($oufile_xml_single, export_xml_single($output_xml_cat));
// puts categorized TSV data into an outfile
file_put_contents($oufile_tsv, export_tsv($output_tsv_arr, $tsv_headers));
// puts categorized JSON into an outfile
file_put_contents($oufile_json, export_json($output_json_arr));
// puts categorized (pretty) JSON into an outfile
file_put_contents($oufile_json_pretty, export_json($output_json_arr, true));
exit;
// returns input text in an XML comment
function android_xml_comments($str)
{
    return str_repeat(" ", 4) . "<!-- {$str} -->";
}
// returns XML string at beginning of XML resource file
function android_xml_start()
{
    $now = date(DATE_RSS);
    return join(PHP_EOL, array("<?xml version=\"1.0\" encoding=\"utf-8\"?>", "", "<!-- Updated: {$now} -->", "<!-- Generated by Project 26 ETL Solution found here: -->", "<!-- https://github.com/pffy/data-mcdonalds-nutrition-facts -->", "", "<resources>", "", ""));
}
// returns XML string at end of XML resource file
function android_xml_end()
{
Exemplo n.º 3
0
     $ext = 'redis';
     $ct = 'text/plain';
 }
 header('Content-type: ' . $ct . '; charset=utf-8');
 header('Content-Disposition: inline; filename="export.' . $ext . '"');
 // JSON
 if ($_POST['type'] == 'json') {
     // Single key
     if (isset($_GET['key'])) {
         echo json_encode(export_json($_GET['key']));
     } else {
         // All keys
         $keys = $redis->keys('*');
         $vals = array();
         foreach ($keys as $key) {
             $vals[$key] = export_json($key);
         }
         echo json_encode($vals);
     }
 } else {
     // Single key
     if (isset($_GET['key'])) {
         export_redis($_GET['key']);
     } else {
         // All keys
         $keys = $redis->keys('*');
         foreach ($keys as $key) {
             export_redis($key);
         }
     }
 }