src/fwidm/dwdHourlyCrawler/hourly/services/AbstractHourlyService.php
public function parseHourlyDataOld(String $content, DWDStation $nearestStation, Coordinate $coordinate, Carbon $startDate = null, Carbon $endDate = null): array
    {
        $time = microtime(true);
        $lines = explode('eor', $content);
        $data = array();

        /**
         * steps to refactor:
         *  1. get latest date from the last line, parse it
         *  2. from this day, calculate the hour difference between requested and $start+$end
         *  3. jump to the specific lines
         *  4. parse
         *  DOES NOT PROVIDE CORRECT DATA - the dwd files do skip missing data instead of providing "-999" as value, as such the optimization will not work.
         */

//        $newestDate = null;
//        //retrieve the latest line that contains a valid date
//        for ($i = count($lines) - 1; !isset($newestDate); $i++) {
//            $newestData = str_replace(' ', '', $lines[count($lines) - $i]);
//            $cols = explode(';', $newestData);
//            if (sizeof($cols) > 3){
//                $newestDate = Carbon::createFromFormat($this->getTimeFormat(), $cols[1], 'utc');
//                break;
//            }
//        }
//        /* @var $newestDate Carbon */
//        $start = min($newestDate->diffInHours($startDate), $newestDate->diffInHours($endDate));
//        $end = max($newestDate->diffInHours($startDate), $newestDate->diffInHours($endDate));
//        DWDUtil::log("MAXMIN", "start=" .$start."; end=".$end. "available Lines=".count($lines));
//        //Retrieve the rest of the data that is found between start and end.
//        for ($i = $start; $i<count($lines) && $i < $end; $i++) {
//            $lines[$i] = str_replace(' ', '', $lines[$i]);
//            $cols = explode(';', $lines[$i]);
//            $date = Carbon::createFromFormat($this->getTimeFormat(), $cols[1], 'utc');
//            if (isset($date)) {
//                $data[] = $this->createParameter($cols, $date, $nearestStation, $coordinate);
//            } else
//                throw new ParseError(self::class . " - Error while parsing date: col=" . $cols[1] . " | date=" . $date);
//        }

        DWDUtil::log("PARSER", "DATE=[" . $endDate->toIso8601String() . "," . $startDate->toIso8601String() . "]");
        for ($i = sizeof($lines) - 1; $i > 0; $i--) {
            $lines[$i] = str_replace(' ', '', $lines[$i]);

            $cols = explode(';', $lines[$i]);
            //skip empty lines
            if (sizeof($cols) < 3)
                continue;
            $date = Carbon::createFromFormat($this->getTimeFormat(), $cols[1], 'utc');
            if ($date) {
                //todo: optimize search for values - currently i only parse from new to old values, find the window and add to the return list - something akin to a binary search might work.
                switch (func_num_args()) {
                    //$start is set
                    case 4: {
                        if ($date >= $startDate) {
                            $temp = $this->createParameter($cols, $date, $nearestStation, $coordinate);

                            $data[] = $temp;
                        } else
                            //break from loop and switch
                            break 2;

                        break;
                    }
                    //$start & $end are set
                    case 5: {
                        if ($date <= $endDate && $date >= $startDate) {
                            $temp = $this->createParameter($cols, $date, $nearestStation, $coordinate);

                            $data[] = $temp;
                        } else
                            if ($date <= $startDate) {
                                //break from loop and switch
                                break 2;
                            }

                        break;
                    }
                    default: {
                        $temp = $this->createParameter($cols, $date, $nearestStation, $coordinate);

                        $data[] = $temp;
                    }
                }

            } else
                throw new ParseError(self::class . " - Error while parsing date: col=" . $cols[1] . " | date=" . $date);
        }
        DWDUtil::log("PARSER", "RetCount=" . count($data));

        DWDUtil::log("TIMER", "Duration=" . (microtime(true) - $time));

        return $data;
    }
public function parseHourlyDataOld(String $content, DWDStation $nearestStation, Coordinate $coordinate, Carbon $startDate = null, Carbon $endDate = null): array
    {
        $time = microtime(true);
        $lines = explode('eor', $content);
        $data = array();

        /**
         * steps to refactor:
         *  1. get latest date from the last line, parse it
         *  2. from this day, calculate the hour difference between requested and $start+$end
         *  3. jump to the specific lines
         *  4. parse
         *  DOES NOT PROVIDE CORRECT DATA - the dwd files do skip missing data instead of providing "-999" as value, as such the optimization will not work.
         */

//        $newestDate = null;
//        //retrieve the latest line that contains a valid date
//        for ($i = count($lines) - 1; !isset($newestDate); $i++) {
//            $newestData = str_replace(' ', '', $lines[count($lines) - $i]);
//            $cols = explode(';', $newestData);
//            if (sizeof($cols) > 3){
//                $newestDate = Carbon::createFromFormat($this->getTimeFormat(), $cols[1], 'utc');
//                break;
//            }
//        }
//        /* @var $newestDate Carbon */
//        $start = min($newestDate->diffInHours($startDate), $newestDate->diffInHours($endDate));
//        $end = max($newestDate->diffInHours($startDate), $newestDate->diffInHours($endDate));
//        DWDUtil::log("MAXMIN", "start=" .$start."; end=".$end. "available Lines=".count($lines));
//        //Retrieve the rest of the data that is found between start and end.
//        for ($i = $start; $i<count($lines) && $i < $end; $i++) {
//            $lines[$i] = str_replace(' ', '', $lines[$i]);
//            $cols = explode(';', $lines[$i]);
//            $date = Carbon::createFromFormat($this->getTimeFormat(), $cols[1], 'utc');
//            if (isset($date)) {
//                $data[] = $this->createParameter($cols, $date, $nearestStation, $coordinate);
//            } else
//                throw new ParseError(self::class . " - Error while parsing date: col=" . $cols[1] . " | date=" . $date);
//        }

        DWDUtil::log("PARSER", "DATE=[" . $endDate->toIso8601String() . "," . $startDate->toIso8601String() . "]");
        for ($i = sizeof($lines) - 1; $i > 0; $i--) {
            $lines[$i] = str_replace(' ', '', $lines[$i]);

            $cols = explode(';', $lines[$i]);
            //skip empty lines
            if (sizeof($cols) < 3)
                continue;
            $date = Carbon::createFromFormat($this->getTimeFormat(), $cols[1], 'utc');
            if ($date) {
                //todo: optimize search for values - currently i only parse from new to old values, find the window and add to the return list - something akin to a binary search might work.
                switch (func_num_args()) {
                    //$start is set
                    case 4: {
                        if ($date >= $startDate) {
                            $temp = $this->createParameter($cols, $date, $nearestStation, $coordinate);

                            $data[] = $temp;
                        } else
                            //break from loop and switch
                            break 2;

                        break;
                    }
                    //$start & $end are set
                    case 5: {
                        if ($date <= $endDate && $date >= $startDate) {
                            $temp = $this->createParameter($cols, $date, $nearestStation, $coordinate);

                            $data[] = $temp;
                        } else
                            if ($date <= $startDate) {
                                //break from loop and switch
                                break 2;
                            }

                        break;
                    }
                    default: {
                        $temp = $this->createParameter($cols, $date, $nearestStation, $coordinate);

                        $data[] = $temp;
                    }
                }

            } else
                throw new ParseError(self::class . " - Error while parsing date: col=" . $cols[1] . " | date=" . $date);
        }
        DWDUtil::log("PARSER", "RetCount=" . count($data));

        DWDUtil::log("TIMER", "Duration=" . (microtime(true) - $time));

        return $data;
    }
public function parseHourlyDataOld ( String $ content , DWDStation $ nearestStation , Coordinate $ coordinate , Carbon $ startDate = null , Carbon $ endDate = null ) : array { $ time = microtime ( true ) ; $ lines = explode ( 'eor' , $ content ) ; $ data = array ( ) ; /**
         * steps to refactor:
         *  1. get latest date from the last line, parse it
         *  2. from this day, calculate the hour difference between requested and $start+$end
         *  3. jump to the specific lines
         *  4. parse
         *  DOES NOT PROVIDE CORRECT DATA - the dwd files do skip missing data instead of providing "-999" as value, as such the optimization will not work.
         */ //        $newestDate = null; //        //retrieve the latest line that contains a valid date //        for ($i = count($lines) - 1; !isset($newestDate); $i++) { //            $newestData = str_replace(' ', '', $lines[count($lines) - $i]); //            $cols = explode(';', $newestData); //            if (sizeof($cols) > 3){ //                $newestDate = Carbon::createFromFormat($this->getTimeFormat(), $cols[1], 'utc'); //                break; //            } //        } //        /* @var $newestDate Carbon */ //        $start = min($newestDate->diffInHours($startDate), $newestDate->diffInHours($endDate)); //        $end = max($newestDate->diffInHours($startDate), $newestDate->diffInHours($endDate)); //        DWDUtil::log("MAXMIN", "start=" .$start."; end=".$end. "available Lines=".count($lines)); //        //Retrieve the rest of the data that is found between start and end. //        for ($i = $start; $i<count($lines) && $i < $end; $i++) { //            $lines[$i] = str_replace(' ', '', $lines[$i]); //            $cols = explode(';', $lines[$i]); //            $date = Carbon::createFromFormat($this->getTimeFormat(), $cols[1], 'utc'); //            if (isset($date)) { //                $data[] = $this->createParameter($cols, $date, $nearestStation, $coordinate); //            } else //                throw new ParseError(self::class . " - Error while parsing date: col=" . $cols[1] . " | date=" . $date); //        } DWDUtil :: log ( "PARSER" , "DATE=[" . $ endDate -> toIso8601String ( ) . "," . $ startDate -> toIso8601String ( ) . "]" ) ; for ( $ i = sizeof ( $ lines ) - 1 ; $ i > 0 ; $ i -- ) { $ lines [ $ i ] = str_replace ( ' ' , '' , $ lines [ $ i ] ) ; $ cols = explode ( ';' , $ lines [ $ i ] ) ; //skip empty lines if ( sizeof ( $ cols ) < 3 ) continue ; $ date = Carbon :: createFromFormat ( $ this -> getTimeFormat ( ) , $ cols [ 1 ] , 'utc' ) ; if ( $ date ) { //todo: optimize search for values - currently i only parse from new to old values, find the window and add to the return list - something akin to a binary search might work. switch ( func_num_args ( ) ) { //$start is set case 4 : { if ( $ date >= $ startDate ) { $ temp = $ this -> createParameter ( $ cols , $ date , $ nearestStation , $ coordinate ) ; $ data [ ] = $ temp ; } else //break from loop and switch break 2 ; break ; } //$start & $end are set case 5 : { if ( $ date <= $ endDate && $ date >= $ startDate ) { $ temp = $ this -> createParameter ( $ cols , $ date , $ nearestStation , $ coordinate ) ; $ data [ ] = $ temp ; } else if ( $ date <= $ startDate ) { //break from loop and switch break 2 ; } break ; } default : { $ temp = $ this -> createParameter ( $ cols , $ date , $ nearestStation , $ coordinate ) ; $ data [ ] = $ temp ; } } } else throw new ParseError ( self :: class . " - Error while parsing date: col=" . $ cols [ 1 ] . " | date=" . $ date ) ; } DWDUtil :: log ( "PARSER" , "RetCount=" . count ( $ data ) ) ; DWDUtil :: log ( "TIMER" , "Duration=" . ( microtime ( true ) - $ time ) ) ; return $ data ; }
Parse the textual representation of DWD Data, can be filtered by specifying before and after.
This means if you specify after - you will get timestamps after the specified team
If you also specify before you can pinpoint values.
@deprecated
@param String $content - Textual representation of a DWD Hourly/Recent pressure file.
@param Carbon|null $startDate - returns all values after the specific time
@param Carbon|null $endDate - returns all values after $after AND after if set.
@return array of parameters
@throws ParseError
Parse the textual representation of DWD Data can be filtered by specifying before and after . This means if you specify after - you will get timestamps after the specified team If you also specify before you can pinpoint values .