Пример #1
0
 /**
  * Verifies behavious of toArray function.
  *
  * @return void
  */
 public function testToArray()
 {
     $date = new \DateTime();
     $actual = new DataPoint('uniqueId', 'an offense', $date, 'Gotham', ['lat' => 0, 'lon' => 0], 'FELONY', '1');
     $expected = ['id' => 'uniqueId', 'offense' => 'an offense', 'category' => 'FELONY', 'class' => '1', 'occurred' => $date->format('Y-m-d H:i:s'), 'city' => 'Gotham', 'location' => ['lat' => 0, 'lon' => 0]];
     $this->assertEquals($expected, $actual->toArray());
 }
Пример #2
0
 /**
  * Parse the results from Elasticsearch for the Hampton Crime data set.
  *
  * @param array            $results  The json data from the request.
  * @param HerculesResponse $response The response object to append data to.
  *
  * @return HerculesReponse The response object all pretty.
  */
 private function parseResults(array $results, HerculesResponse $response)
 {
     // Parse the results.
     $resultArray = $results['hits'];
     foreach ($resultArray as $key => $value) {
         $id = $value['_id'];
         $offense = $value['_source']['offense'];
         $category = $value['_source']['category'];
         $class = $value['_source']['class'];
         $occured = new \DateTime($value['_source']['occurred']);
         $city = $value['_source']['city'];
         $location = $value['_source']['location'];
         if (isset($occured) && gettype($location) === 'array') {
             $datapoint = new DataPoint($id, $offense, $occured, $city, $location, $category, $class);
             $response->addDataEntry($datapoint->toArray());
         }
     }
     return $response;
 }