/** * Run the database seeds. * * @return void */ public function run() { $stations = Station::all(); // holds measurements to add separately from the per-station batches. this speeds up // inserting measurements for stations that don't get a history significantly. $later = []; foreach ($stations as $station) { $date = Carbon::now(); $temp = ['station_id' => $station->id, 'time' => $date->format(DateTime::ATOM), 'temperature' => $this->getRandomDouble(-30, 40, 1), 'dew_point' => $this->getRandomDouble(-40, 35, 1), 'station_pressure' => $this->getRandomDouble(900, 1100, 1), 'sea_level_pressure' => $this->getRandomDouble(900, 1100, 1), 'visibility' => $this->getRandomDouble(0, 165, 1), 'precipitation' => $this->getRandomDouble(0, 15, 1), 'snow_depth' => $this->getRandomDouble(0, 90, 1), 'events' => rand(0, 1) . rand(0, 1) . rand(0, 1) . rand(0, 1) . rand(0, 1) . rand(0, 1), 'cloud_cover' => $this->getRandomDouble(0, 100, 1), 'wind_direction' => rand(0, 359), 'wind_speed' => $this->getRandomDouble(0, 80, 1)]; // generate more measurements for some stations if ($station->longitude > $this->between[0] && $station->longitude < $this->between[1]) { $data = [$temp]; for ($i = 0; $i < $this->seedAmount; $i++) { // travel back in tiiime! $date->subSeconds(44); $temp = ['station_id' => $station->id, 'time' => $date->format(DateTime::ATOM), 'temperature' => $this->createRandomValueBasedOn($temp['temperature']), 'dew_point' => $this->createRandomValueBasedOn($temp['dew_point']), 'station_pressure' => $this->createRandomValueBasedOn($temp['station_pressure']), 'sea_level_pressure' => $this->createRandomValueBasedOn($temp['sea_level_pressure']), 'visibility' => $this->createRandomValueBasedOn($temp['visibility']), 'precipitation' => $this->createRandomValueBasedOn($temp['precipitation']), 'snow_depth' => $this->createRandomValueBasedOn($temp['snow_depth']), 'events' => rand(0, 1) . rand(0, 1) . rand(0, 1) . rand(0, 1) . rand(0, 1) . rand(0, 1), 'cloud_cover' => $this->createRandomValueBasedOn($temp['cloud_cover']), 'wind_direction' => $this->createRandomValueBasedOn($temp['wind_direction']), 'wind_speed' => $this->createRandomValueBasedOn($temp['wind_speed'])]; $data[] = $temp; } DB::table('measurements')->insert($data); } else { $later[] = $temp; if (count($later) > $this->seedAmount) { DB::table('measurements')->insert($later); $later = []; } } } if (count($later) > 0) { DB::table('measurements')->insert($later); } }
public function showStationInformation() { $stations = Station::all(); if (!empty($stations)) { foreach ($stations as $station) { echo $station->name . "<br/>"; } echo "Those were the stations!"; } else { echo "No stations!"; } }
public function index() { $field['numberFields'] = array_merge(self::$FIELDS['measurements']['numberFields'], self::$FIELDS['stations']['numberFields']); $field['nameFields'] = self::$FIELDS['stations']['nameFields']; $field['showOnlyFields'] = ['events']; foreach (self::$FIELDS['measurements']['numberFields'] as $numberField) { $fieldValues[$numberField]['min'] = Measurement::min($numberField); $fieldValues[$numberField]['max'] = Measurement::max($numberField); } foreach (self::$FIELDS['stations']['numberFields'] as $numberField) { $fieldValues[$numberField]['min'] = Station::min($numberField); $fieldValues[$numberField]['max'] = Station::max($numberField); } return view('weather.export', ['fields' => $field, 'stations' => Station::all()->sortBy('name'), 'countries' => Station::distinct('country')->lists('country')->sort(), 'fieldValues' => $fieldValues]); }