Example #1
0
 public function testLogin()
 {
     $cnx = new Rserve_Connection(RSERVE_HOST, RSERVE_PORT, array('username' => RSERVE_USER, 'password' => RSERVE_PASS));
     // random id
     $random = '';
     for ($i = 0; $i < 10; ++$i) {
         $random .= dechex(mt_rand());
     }
     $random_id = uniqid($random, TRUE);
     $r = $cnx->evalString('x="' . $random_id . '"');
     $this->assertEquals($r, $random_id);
     $session = $cnx->detachSession();
 }
Example #2
0
 public function testSession()
 {
     $cnx = new Rserve_Connection(RSERVE_HOST);
     // random id
     $random = '';
     for ($i = 0; $i < 10; ++$i) {
         $random .= dechex(mt_rand());
     }
     $random_id = uniqid($random, TRUE);
     $r = $cnx->evalString('x="' . $random_id . '"');
     $this->assertEquals($r, $random_id);
     $session = $cnx->detachSession();
     $cnx = new Rserve_Connection($session);
     $x = $cnx->evalString('x');
     $this->assertEquals($x, $random_id);
 }
Example #3
0
     echo "<li>O arquivo &eacute; grande demais? (m&aacute;ximo aceito: 15 mil caracteres)</li>";
     echo "<li>Voc&ecirc; salvou o arquivo usando algum processador de texto, como o Word?</li>";
     echo "</ul>";
 } else {
     $uploadfile = $BASEDIR . "/tmp/" . basename($_FILES['rfile']['tmp_name']);
     move_uploaded_file($_FILES['rfile']['tmp_name'], $uploadfile);
     ### Correcao de bug! O R trava se o editor de texto não encerrou
     #   a ultima linha
     system("echo ' ' >> {$uploadfile}");
     $conts = file_get_contents($uploadfile);
     $probs = new Proibidos();
     $teste = $probs->pass($conts, $X->getId());
     if ($teste === FALSE) {
         # Verifica se existe alguma palavra proibida na resposta
         try {
             $r = new Rserve_Connection(RSERVE_HOST);
         } catch (Exception $e) {
             echo 'Erro interno ao conectar no servidor. Notifique os administradores do sistema!<br>';
             if (error_reporting() & E_ERROR) {
                 echo $e;
             }
         }
         try {
             $text = 'source("' . $BASEDIR . '/corretor.R");';
             $text .= 'con <- connect("' . $DBUSER . '","' . $DBPASS . '","' . $DBNAME . '");';
             $text .= 'PATH <- "' . $BASEDIR . '";';
             $text .= 'notaR("' . $USER->getNome() . '", ' . $X->getId() . ', "' . $uploadfile . '")';
             $x = $r->evalString($text);
             if (is_null($x)) {
                 echo "<font color='#8c2618'>Aviso: seu c&oacute;digo cont&eacute;m alguma " . "funcionalidade do R n&atilde;o suportada pelo notaR. Remova as fun&ccedil;&otilde;es " . "gr&aacute;ficas (como <i>plot</i> ou <i>hist</i>) do seu c&oacute;digo e tente novamente.</font>";
             }
Example #4
0
 /**
  * initialization of the library
  */
 public static function init()
 {
     if (self::$init) {
         return;
     }
     $m = pack('s', 1);
     self::$machine_is_bigendian = $m[0] == 0;
     spl_autoload_register('Rserve_Connection::autoload');
     self::$init = TRUE;
 }
Example #5
0
<?php

/**
* Rserve-php example
*/
require_once 'config.php';
require '../Connection.php';
try {
    echo 'Connecting to Rserve ' . RSERVE_HOST;
    $r = new Rserve_Connection(RSERVE_HOST);
    $x = $r->evalString('a=rpois(100,100); b=rpois(100,100)');
    var_dump($x);
    $x = $r->evalString('chisq.test(table(a,b))', Rserve_Connection::PARSER_REXP);
    echo '<style>' . file_get_contents('rexp.css') . '</style>';
    echo $x->toHTML();
    $r->close();
} catch (Exception $e) {
    echo $e;
}
Example #6
0
require 'Definition.php';
$test_cases = Rserve_Tests_Definition::$native_tests;
require 'example/head.php';
function mydump($x, $title = NULL)
{
    if ($title) {
        echo '<h4>' . $title . '</h4>';
    }
    echo '<pre>';
    var_dump($x);
    echo '</pre>';
}
try {
    echo '<div id="tab_0" class="tab">';
    echo '<p>Connecting to Rserve ' . RSERVE_HOST;
    $r = new Rserve_Connection(RSERVE_HOST);
    echo ' OK</p>';
    echo '<p>Use the above menu to see results for various results using each kind of parser</p>';
    echo '</div>';
    echo '<div id="tab_1" class="tab">';
    echo '<h2>Chi2</h2>';
    $x = $r->evalString('a=rpois(100,100); b=rpois(100,100); list(a,b)');
    //mydump($x);
    $x = $r->evalString('chisq.test(table(a,b))', Rserve_Connection::PARSER_REXP);
    echo $x->toHTML();
    echo '</div>';
    $parsers = array(Rserve_Connection::PARSER_NATIVE => 'native ', Rserve_Connection::PARSER_NATIVE_WRAPPED => ' wrapped native (RNative)', Rserve_Connection::PARSER_DEBUG => 'Parser Debug', Rserve_Connection::PARSER_REXP => 'REXP');
    $i = 1;
    foreach ($parsers as $parser => $title) {
        ++$i;
        echo '<div id="tab_' . $i . '" class="tab">';