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

De WikiEducator
Saltar a: navegación, buscar
 
(4 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_days( $data, $interval, $list_services ) {
+
/**
        //En este caso queremos sacar un valor por día que sea la media de de ese día
+
    * @covers Monitorizacion_Controller_Servoces::get_value_of_performance_data
 +
    * @group production
 +
    * @runInSeparateProcess
 +
    */
 +
    public function testGet_value_of_performance_data() {
  
         echo "<h2>MRM ---DEBUGANDO ... en matrices day (media por día)</h2>";
+
         $array = array(
        $matrix = [];
+
            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
        //Inicializo el primer nivel del array
+
    * @group production
        $matrix[ 'host' ] = array_values( $data )[ 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 testService_host_to_string() {
 
+
// Comparacion de fechas
 
+
         $array = array(
 
+
             Monitorizacion_Constants::SERVICIO_SSH => 'SSH',
 
+
             Monitorizacion_Constants::SERVICIO_HTTP => 'HTTP',
        foreach ( $data as $data_host_day ) { //cada día registrado a un host concreto
+
             Monitorizacion_Constants::SERVICIO_MYSQL => 'MYSQL',
//            //  //Ahora recorremos para cada documento  (host - día)
+
             Monitorizacion_Constants::SERVICIO_DISCOS => 'DISK',
//            //primero inicializamos las fechas
+
            Monitorizacion_Constants::SERVICIO_CPU => 'CPU',
//
+
            Monitorizacion_Constants::SERVICIO_PING => 'PING',
//
+
            -1 => null
//
+
        );
////
+
        foreach ( $array as $servicio => $value_expected ) {
             $s = substr( $data_host_day->timestamp, 0, 10 );
+
            $this->assertEquals( $value_expected, Monitorizacion_Controller::service_host_to_string( $servicio ), "ERROR: $value_expected != " . Monitorizacion_Controller::service_host_to_string( $servicio ) );
             $f_d = date( 'd-m-Y', strtotime( $s ) );
+
         }
 
+
             $matrix[ 'date' ][] = $f_d;
+
 
+
 
+
             foreach ( $list_services as $service ) {
+
//                //inicializo el array
+
//
+
              $indexes_service = array_keys( $data_host_day->data[ $service ] );
+
//                //inicializo la fecha
+
 
+
//
+
                foreach ( $indexes_service as $index_service ) {
+
//                    //primer inicializo la matriz
+
//                    //me interesan solo los múltiplos de 30
+
//                    //Calculamos la media de cada hora
+
                    for ( $h = 0; $h <= 23; $h++ ) {
+
//                        Logs_Controller::vardump( $h );
+
//                        Logs_Controller::vardump( $index_service );
+
//                        Logs_Controller::vardump( $service );
+
 
+
                        $data_min_avg[] = Monitorizacion_Controller_Services::array_avg( $data_host_day->data[ $service ][ $index_service ][ $h ] );
+
                    }//end while $hour
+
 
+
 
+
 
+
                        $matrix[ 'services' ][ $service ][ $index_service ][] = Monitorizacion_Controller_Services::array_avg( $data_min_avg );
+
 
+
 
+
                    //                    Logs_Controller::vardump( $data_min_avg );
+
//                    Logs_Controller::vardump( $matrix );
+
              }//End foreach index (indices de los servicios
+
//                //                echo "FECHA      -      VALOR SERVICIO<br/>";
+
////                foreach ( $matrix as $f => $v ) {
+
////                    echo "$- $v<br />";
+
            }//End foreach $services
+
        }//end foreach $data
+
//        //ver matriz
+
//        echo "<h2>MRM ---DEBUGANDO ...  matriz con medias por día </h2>";
+
      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 ) );
        }
 
    }