public function getObservationsByDate($missionId, $date) { $response = new ApiResponse(); if ($missionId != null) { $mission = Mission::with('devices')->find($missionId); if ($mission == null) { $response->status = 'error'; $response->message = ['id' => '', 'code' => 'mission_null', 'description' => 'The mission was not found']; return \Response::json($response); } $timestamp = \Carbon::parse($date)->timestamp; //for each device, get its observations foreach ($mission->devices as $device) { $deviceUUID = env('RADICAL_CITYNAME') . '.' . $mission->radical_service_id . '.' . $device->device_uuid; $obs = $this->radicalIntegrationManager->getMeasurementsByDeviceUUID($deviceUUID, $timestamp); $device->measurements = json_decode($obs); } $response->status = 'success'; $response->message = ['mission' => $mission]; return \Response::json($response); } else { $response->status = 'error'; $response->message = ['id' => '', 'code' => 'mission_id_null', 'description' => 'The missionId should not null']; return \Response::json($response); } }
public function observationReward() { $mission = Mission::with('type')->find(\Request::get('mission_id')); if ($mission->type->name == 'location') { return $this->locationReward(\Auth::user()->id, $mission->id); } else { return $this->routeReward(\Auth::user()->id, $mission->id); } }
/** * Get the top contributors for a certain mission * * @return \Illuminate\Http\JsonResponse * * @SWG\Get( * summary="Get the top contributors for a certain mission", * path="/missions/topContributors", * description="Get the top contributors", * operationId="api.missions.topContributors", * produces={"application/json"}, * tags={"missions"}, * @SWG\Parameter( * name="missionId", * description="The mission's id", * required=true, * type="string", * in="query" * ), * @SWG\Response( * response=200, * description="", * ), * @SWG\Response( * response=400, * description="Unauthorized action", * ) * ) */ public function topContributors() { $mission = Mission::with('devices.observations', 'devices.user')->find(\Request::get('missionId')); $users = []; if ($mission != null) { foreach ($mission->devices as $device) { $device->user->totalContribution = sizeof($device->observations); array_push($users, $device->user); } $response = new ApiResponse(); $response->status = 'success'; $response->message = ['users' => $users]; return \Response::json($response); } else { $response = new ApiResponse(); $response->status = 'error'; $response->message = []; return \Response::json($response); } }
/** * Validate the observation data before performing any action * */ private function validateObservation() { $response = new ApiResponse(); if (!\Request::has('device_uuid')) { $response->status = 'error'; $response->message = ['id' => '', 'code' => 'device_uuid_null', 'description' => 'The device uuid should not be null']; } else { $device = Device::where('device_uuid', \Request::get('device_uuid'))->first(); if ($device == null) { $response->status = 'error'; $response->message = ['id' => '', 'code' => 'device_not_found', 'description' => 'The device could not be found']; } } if (!\Request::has('mission_id')) { $response->status = 'error'; $response->message = ['id' => '', 'code' => 'mission_id_null', 'description' => 'The mission id should not be null']; } else { //check that the mission_id exists $this->mission = Mission::with('type')->find(\Request::get('mission_id')); if ($this->mission == null) { $response->status = 'error'; $response->message = ['id' => '', 'code' => 'mission_id_not_found', 'description' => 'The requested mission could not be found']; } } if (\Request::has('observation_date')) { if (!$this->validateDate(\Request::get('observation_date'))) { $response->status = 'error'; $response->message = ['id' => '', 'code' => 'wrong_date_format', 'description' => 'The date should be in the following format: Y-m-d hh:mm:ss']; } } if (\Request::has('latitude') && !is_numeric(\Request::get('latitude')) || \Request::has('longitude') && !is_numeric(\Request::get('longitude'))) { $response->status = 'error'; $response->message = ['id' => '', 'code' => 'coordinates_not_numeric', 'description' => 'The coordinates of the observation should be numeric']; } if (!\Request::has('measurements')) { $response->status = 'error'; $response->message = ['id' => '', 'code' => 'measurements_null', 'description' => 'The measurements should not be null']; } else { foreach (\Request::get('measurements') as $measurement) { if (!isset($measurement['latitude']) || $measurement['latitude'] == '' || !isset($measurement['longitude']) || $measurement['longitude'] == '') { $response->status = 'error'; $response->message = ['id' => '', 'code' => 'coordinates_null', 'description' => 'The coordinates of the measurements should not be null']; } else { if (!is_numeric($measurement['latitude']) || !is_numeric($measurement['longitude'])) { $response->status = 'error'; $response->message = ['id' => '', 'code' => 'coordinates_not_numeric', 'description' => 'The coordinates of the measurements should be numeric']; } } } } return $response; }