Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
93.33% |
14 / 15 |
|
91.67% |
11 / 12 |
|
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| Ascii | |
93.33% |
14 / 15 |
|
91.67% |
11 / 12 |
|
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
5.01 | |
0.00% |
0 / 1 |
| fetch | |
93.33% |
14 / 15 |
|
91.67% |
11 / 12 |
|
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
5.01 | |||
| 1 | <?php |
| 2 | namespace Hsit\Webservice\Event\ThematicEffect; |
| 3 | |
| 4 | use Hsit\Webservice\Event\ThematicEffect as HWE_ThematicEffect; |
| 5 | use Fdsn\DataStructure\Id as DS_Id; |
| 6 | use Fdsn\DataStructure\LatLon as DS_LatLon; |
| 7 | |
| 8 | /** |
| 9 | * Fetch ASCII thematic effect data from HSIT portal |
| 10 | * |
| 11 | * @param Fdsn\DataStructure\Id $fdsnQuakeId Id quake to scan for data |
| 12 | * @param string $thematicEffect study (now only ????? are supported) |
| 13 | * @param string $localFileFullPath base url to fetch local file (filepath will be: baseUrl/<hsit_filename>.txt) |
| 14 | */ |
| 15 | class Ascii extends HWE_ThematicEffect { |
| 16 | protected const fileExtension = 'txt'; |
| 17 | private const dataStartsAtLine = 7; |
| 18 | |
| 19 | /** |
| 20 | * fetch data from url (remote or local - if $localFileFullPath is set in __construct) |
| 21 | * |
| 22 | * @return int number of data found |
| 23 | */ |
| 24 | public function fetch():int{ |
| 25 | $asciiString = is_null($this->localFileFullPath) ? $this->fetchFromUrl() : $this->fetchFromLocalPath(); |
| 26 | $data = preg_split("/\n/", $asciiString); |
| 27 | |
| 28 | if( count($data) <= self::dataStartsAtLine ) |
| 29 | return 0; |
| 30 | |
| 31 | for($i = self::dataStartsAtLine; $i < count($data); $i++ ){ |
| 32 | //skip empty lines |
| 33 | if( preg_match('/^$/', $data[$i] ) ) |
| 34 | continue; |
| 35 | |
| 36 | list($lon, $lat, $percentage, $reports, $place) = preg_split('/,/', trim($data[$i]) ); |
| 37 | $this->places[] = array( |
| 38 | 'point' => new DS_LatLon($lat, $lon), |
| 39 | 'percentage' => $percentage, |
| 40 | 'reports' => $reports, |
| 41 | 'place' => $place |
| 42 | |
| 43 | ); |
| 44 | } |
| 45 | |
| 46 | return count($this->places); |
| 47 | } |
| 48 | } |
| 49 | ?> |