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 | <?php function json_graph($sensorID, $timefrom, $timeto) { $values = getSensorValuesByHour($sensorID, $timefrom, $timeto); $label = $sensorID; $data = Array(); $tzoffset = $this->get_timezone_offset("UTC"); foreach ($values as $value) { $data[] = Array((strtotime($value['time']) + $tzoffset) * 1000, intval($value['avg'])); } $this->output ->set_content_type('application/json') ->set_output(json_encode(Array("label" => $label, "data" => $data, "previous" => Array( "from" => $timefrom - (24 * 60 * 60), "to" => $timefrom) , "next" => Array( "to" => $timeto + (24 * 60 * 60), "from" => $timeto) ) )); } function json_data_description($sensorID, $timefrom, $timeto) { $timefrom = strtotime($timefrom); $timeto = strtotime($timeto); $years = getSensorDataYears($sensorID, $timefrom, $timeto); $months = getSensorDataMonths($sensorID, $timefrom, $timeto); $days = getSensorDataDays($sensorID, $timefrom, $timeto); return json_encode(Array("years" => $years, "months" => $months, "days" => $days )); } ?> |