Diferencia entre revisiones de «Usuario:ManuelRomero/proyecto/proyectoIternova/borrador»

De WikiEducator
Saltar a: navegación, buscar
 
(3 revisiones intermedias por el mismo usuario no mostrado)
Línea 1: Línea 1:
 
<source lang=php>
 
<source lang=php>
  public static function create_matrices_last( $datas, $list_services, $hour ) {
+
/**
        echo "<h2>MRM ---DEBUGANDO ...en create_matrices_fast </h2>";
+
    * @covers Monitorizacion_Controller_Servoces::get_value_of_performance_data
        //Inicializo el primer nivel del array
+
    * @group production
        $matrix[ 'host' ] = array_values( $datas )[ 0 ]->host_id;
+
    * @runInSeparateProcess
        $matrix[ 'date' ] = []; //Será un array indexado de las diferentes fechas
+
    */
        $matrix[ 'services' ] = []; //Array asociativo con cada servicio cada uno tendrá un arrau con los índices
+
    public function testGet_value_of_performance_data() {
        //  //Ahora recorremos para cada documento  (host - día)
+
        //primero inicializamos las fechas
+
        $min = "00";
+
  
         //Nos quedamos con los dos array si los ubiera si no data2 tendrá un false
+
         $array = array(
        reset( $datas );
+
            array( 'expected' => 0.013585, 'input' => "time=0.013585s;;;0.000000;10.000000", 'type' => 'float' ),
         Logs_Controller::vardump( $hour );
+
            array( 'expected' => null, 'input' => "time=;;;0.000000;10.000000", 'type' => 'null' ),
         $data1 = current( $datas );
+
         );
        $data2 = next( $datas );
+
         foreach ( $array as $index => $data ) {
        Logs_Controller::vardump( $data1 );
+
//            echo PHP_EOL;
        Logs_Controller::vardump( $data2 );
+
            $value_returned = Monitorizacion_Controller_Services::get_value_of_performance_data( $data[ 'input' ] );
 +
//            echo ">>>" . $data['input'] . PHP_EOL;
 +
//            echo ">>>" . $data['expected'] . PHP_EOL;
 +
//            echo ">>>" . $value_returned . PHP_EOL;
 +
            $this->assertEquals( $data[ 'expected' ], $value_returned, "ERROR: " . $data[ 'expected' ] . " != " . $value_returned, 0.001 );
 +
            $this->assertInternalType( $data[ 'type' ], $value_returned );
 +
        }
  
        $fecha = substr( $data1->timestamp, 0, 10 ) . " $hour:00:00";
+
    }
        $dateMAX = date( 'Y-m-d H:i:00', strtotime( $fecha . " -3 hour" ) );
+
        $fecha = date( 'Y-m-d H:i:00', strtotime( $fecha . " -2 minute" ) );
+
        $matrix[ 'date' ] = Charts_Controller::get_array_datetime_range( $dateMAX, $fecha, 60, 'H:i:00' );
+
  
 
+
    /**
 
+
    * @covers Monitorizacion_Controller::service_host_to_string
        foreach ( $list_services as $service ) {
+
    * @group production
            $matrix[ 'services' ][ $service ] = [];
+
    * @runInSeparateProcess
            $indexes_service = array_keys( $data1->data[ $service ] );
+
    */
 
+
    public function testService_host_to_string() {
 
+
// Comparacion de fechas
            //Para cada índice de ese servicio
+
        $array = array(
            $datas_of_mongo = [];
+
            Monitorizacion_Constants::SERVICIO_SSH => 'SSH',
            foreach ( $indexes_service as $index_service ) {
+
            Monitorizacion_Constants::SERVICIO_HTTP => 'HTTP',
                //Si hora =1 o 2 necesito datos de los dos días para generar la matriz
+
            Monitorizacion_Constants::SERVICIO_MYSQL => 'MYSQL',
                //Si no lo cogeré de cada día
+
            Monitorizacion_Constants::SERVICIO_DISCOS => 'DISK',
 
+
            Monitorizacion_Constants::SERVICIO_CPU => 'CPU',
                switch ( $hour ) {
+
            Monitorizacion_Constants::SERVICIO_PING => 'PING',
 
+
            -1 => null
                    case 0:
+
        );
                        $h = 21;
+
        foreach ( $array as $servicio => $value_expected ) {
                        //Primer array de documentos
+
            $this->assertEquals( $value_expected, Monitorizacion_Controller::service_host_to_string( $servicio ), "ERROR: $value_expected != " . Monitorizacion_Controller::service_host_to_string( $servicio ) );
                        $datas_of_mongo = $data1->data[ $service ][ $index_service ][ $h ];
+
         }
                        $datas_of_mongo = array_merge( $datas_of_mongo, $data1->data[ $service ][ $index_service ][ ++$h ] );
+
                        $datas_of_mongo = array_merge( $datas_of_mongo, $data1->data[ $service ][ $index_service ][ ++$h ] );
+
                        break;
+
                    case 1:
+
                        $h = 22;
+
                        //Primer array de documentos
+
                        $datas_of_mongo = $data1->data[ $service ][ $index_service ][ $h ];
+
                        $datas_of_mongo = array_merge( $datas_of_mongo, $data1->data[ $service ][ $index_service ][ $h + 1 ] );
+
                        $datas_of_mongo = array_merge( $datas_of_mongo, $data2->data[ $service ][ $index_service ][ 0 ] );
+
                        break;
+
 
+
                    case 2:
+
                        $h = 23;
+
                        //Primer array de documentos
+
                        $datas_of_mongo = $data1->data[ $service ][ $index_service ][ $h ];
+
                        $datas_of_mongo = array_merge( $datas_of_mongo, $data2->data[ $service ][ $index_service ][ 0 ] );
+
                        $datas_of_mongo = array_merge( $datas_of_mongo, $data2->data[ $service ][ $index_service ][ 1 ] );
+
                        break;
+
                    default:
+
                        Logs_Controller::vardump( $index_service );
+
 
+
                        //Primer array de documentos
+
                        $h = $hour - 2;
+
                        $datas_of_mongo = $data1->data[ $service ][ $index_service ][ $h ];
+
                        $datas_of_mongo = array_merge( $datas_of_mongo, $data1->data[ $service ][ $index_service ][ ++$h ] );
+
                        $datas_of_mongo = array_merge( $datas_of_mongo, $data1->data[ $service ][ $index_service ][ ++$h ] );
+
                }
+
                $matrix[ 'services' ][ $service ][ $index_service ] = $datas_of_mongo;
+
            }//End while index (indices de los servicios
+
            //                echo "FECHA      -      VALOR SERVICIO<br/>";
+
        }//End foreach $services
+
        //ver matriz
+
        Logs_Controller::vardump( $matrix );
+
 
+
         return ($matrix);
+
  
 
     }
 
     }
 
</source>
 
</source>

Última revisión de 10:21 8 sep 2017

 /**
     * @covers Monitorizacion_Controller_Servoces::get_value_of_performance_data
     * @group production
     * @runInSeparateProcess
     */
    public function testGet_value_of_performance_data() {
 
        $array = array(
            array( 'expected' => 0.013585, 'input' => "time=0.013585s;;;0.000000;10.000000", 'type' => 'float' ),
            array( 'expected' => null, 'input' => "time=;;;0.000000;10.000000", 'type' => 'null' ),
        );
        foreach ( $array as $index => $data ) {
//            echo PHP_EOL;
            $value_returned = Monitorizacion_Controller_Services::get_value_of_performance_data( $data[ 'input' ] );
//            echo ">>>" . $data['input'] . PHP_EOL;
//            echo ">>>" . $data['expected'] . PHP_EOL;
//            echo ">>>" . $value_returned . PHP_EOL;
            $this->assertEquals( $data[ 'expected' ], $value_returned, "ERROR: " . $data[ 'expected' ] . " != " . $value_returned, 0.001 );
            $this->assertInternalType( $data[ 'type' ], $value_returned );
        }
 
    }
 
    /**
     * @covers Monitorizacion_Controller::service_host_to_string
     * @group production
     * @runInSeparateProcess
     */
    public function testService_host_to_string() {
// Comparacion de fechas
        $array = array(
            Monitorizacion_Constants::SERVICIO_SSH => 'SSH',
            Monitorizacion_Constants::SERVICIO_HTTP => 'HTTP',
            Monitorizacion_Constants::SERVICIO_MYSQL => 'MYSQL',
            Monitorizacion_Constants::SERVICIO_DISCOS => 'DISK',
            Monitorizacion_Constants::SERVICIO_CPU => 'CPU',
            Monitorizacion_Constants::SERVICIO_PING => 'PING',
            -1 => null
        );
        foreach ( $array as $servicio => $value_expected ) {
            $this->assertEquals( $value_expected, Monitorizacion_Controller::service_host_to_string( $servicio ), "ERROR: $value_expected != " . Monitorizacion_Controller::service_host_to_string( $servicio ) );
        }
 
    }