//$stationdatas = $station->buildStationdatas(); $fleepdatas = fRecordSet::buildFromSQL('Fleepdata', array("SELECT * FROM `fukushimadatas` WHERE `station_id`=%i AND reading_date > ADDDATE(NOW(), INTERVAL -9 DAY) ORDER BY `reading_date` DESC LIMIT 0 , 6", $station->getStationId())); //$fleepdatas = fRecordSet::buildFromSQL('Fleepdata', array("SELECT * FROM `fukushimadatas` WHERE `station_id`=%i ORDER BY `reading_date` DESC LIMIT 0 , 6",$station->getStationId())); //$stationdatas->sort('getDatetimeString','desc'); $datastreams .= '{"title": "' . $station->getStationNameEn() . '",' . '"title_jp": "' . $station->getStationNameJp() . '",' . '"description": "",' . '"creator": "fukushima_fleep",' . '"feed": "http://www.rdtn.org/feeds/station/' . $station->getStationId() . '.json",' . '"location": {"lon":' . $station->getLongitude() . ', "lat":' . $station->getLatitude() . ', "name": "' . $station->getPrefectureNameEn() . '"},' . '"id":' . $station->getStationId() . ',' . '"datastreams": ['; $success = false; foreach ($fleepdatas as $fleepdata) { $sa = $fleepdata->getReadingValue(); if ($sa != -888 && $sa != -999) { $unit = $fleepdata->createUnit(); $datastreams .= '{"at": "' . $fleepdata->getReadingDate() . '",' . '"max_value": "0",' . '"min_value": "0",' . '"current_value": "' . $fleepdata->getReadingValue() . '",' . '"id": "' . $fleepdata->getReadingId() . '",' . '"unit": {"type": "basicSI","label": "' . $unit->getUnitLabel() . '","symbol": "' . $unit->getUnitSymbol() . '"}}'; $success = true; break; } } if ($success) { //close and append $datastreams .= ']},'; $jsonData .= $datastreams; } $datastreams = ""; } $output .= rtrim($jsonData, ','); $output .= '], "itemsPerPage": ' . $stations->count() . ', "startIndex": 0, "totalResults": ' . $stations->count(TRUE) . '}'; $file = new fFile(DOC_ROOT . '/feeds/fukushima_full_static.json'); $file->write($output); echo $output; ?>
$jsonOutput .= '], "itemsPerPage": ' . $totalRecords . ', "startIndex": 0, "totalResults": ' . $totalRecords . '}'; //dont write files unless there were rows returned if ($jsonCount > 0) { echo DOC_ROOT . '/feeds/driveCache/drive' . $driveId . '.json'; //write JSON try { $file = new fFile(DOC_ROOT . '/feeds/driveCache/drive' . $driveId . '.json'); $file->write($jsonOutput); } catch (fExpectedException $e) { $new_file = fFile::create(DOC_ROOT . '/feeds/driveCache/drive' . $driveId . '.json', $jsonOutput); } catch (fEnvironmentException $e) { } //write KML try { $file = new fFile(DOC_ROOT . '/feeds/driveCache/drive' . $driveId . '.kml'); $file->write($kmlOutput); } catch (fExpectedException $e) { $new_file = fFile::create(DOC_ROOT . '/feeds/driveCache/drive' . $driveId . '.kml', $kmlOutput); } catch (fEnvironmentException $e) { } //write CSV try { $file = new fFile(DOC_ROOT . '/feeds/driveCache/drive' . $driveId . '.csv'); $file->write($csvOutput); } catch (fExpectedException $e) { $new_file = fFile::create(DOC_ROOT . '/feeds/driveCache/drive' . $driveId . '.csv', $csvOutput); } catch (fEnvironmentException $e) { } } $db = null; //echo $output;