예제 #1
0
 /**
  * Get all stats by user
  * @param int $user_id
  * @return mixed|bool
  */
 static function GetByUser($user_id)
 {
     $stats = new Stats();
     $stats->total_bets_placed = 0;
     $stats->total_bets_won = 0;
     $stats->total_bets_lost = 0;
     $stats->total_points_won = 0;
     $stats->total_points_lost = 0;
     $stats->avg_bet_value = 0;
     $bets = Bet::GetAll();
     $totals = [];
     foreach ($bets as $bet) {
         if ($user_id == $bet->user_id) {
             $stats->total_bets_placed++;
             if ($bet->result == 1) {
                 $stats->total_bets_won++;
                 $stats->total_points_won += $bet->points_total;
             }
             if ($bet->result == 0) {
                 $stats->total_bets_lost++;
                 $stats->total_points_lost += $bet->points_total;
             }
             $totals[] = $bet->points_total;
         }
     }
     $stats->avg_bet_value = mmmr($totals, 'median');
     $stats->wealth_gap = wealthGap();
     return $stats;
 }
예제 #2
0
function basicstats($jobname, $currun, $refid)
{
    $checkvar = $currun . $jobname . $type;
    //echo $type . "\n";
    $checkrunning = $currun . $jobname . $type . "status";
    global $memcache;
    global $mindb_connection;
    global $reflength;
    //$jsonstring = $memcache->get("$checkvar");
    $checkingrunning = $memcache->get("{$checkrunning}");
    if ($checkingrunning === "No" || $checkingrunning === FALSE) {
        //$memcache->set("$checkrunning", "YES", 0, 0);
        $checkrow = "select name,json from jsonstore where name = '" . $jobname . "' ;";
        $checking = $mindb_connection->query($checkrow);
        if ($checking->num_rows == 1) {
            //echo "We have already run this!";
            foreach ($checking as $row) {
                $jsonstring = $row['json'];
            }
        } else {
            $jsonstring = $jsonstring . "[\n";
            ### We will recover an array of sequence lengths for the template, complement and 2d sequences
            $sql_template_lengths = 'select length(sequence) as len from basecalled_template order by length(sequence);';
            $sql_complement_lengths = 'select length(sequence) as len from basecalled_complement order by length(sequence);';
            $sql_2d_lengths = 'select length(sequence) as len from basecalled_2d order by length(sequence);';
            $sql_template_lengths_result = $mindb_connection->query($sql_template_lengths);
            $sql_complement_lengths_result = $mindb_connection->query($sql_complement_lengths);
            $sql_2d_lengths_result = $mindb_connection->query($sql_2d_lengths);
            $template_lengths = [];
            $complement_lengths = [];
            $twod_lengths = [];
            if ($sql_template_lengths_result->num_rows >= 1) {
                foreach ($sql_template_lengths_result as $row) {
                    $template_lengths[] = $row['len'];
                }
            }
            if ($sql_complement_lengths_result->num_rows >= 1) {
                foreach ($sql_complement_lengths_result as $row) {
                    $complement_lengths[] = $row['len'];
                }
            }
            if ($sql_2d_lengths_result->num_rows >= 1) {
                foreach ($sql_2d_lengths_result as $row) {
                    $twod_lengths[] = $row['len'];
                }
            }
            $jsonstring = $jsonstring . "{\n";
            $jsonstring = $jsonstring . "\"name\" : \"template\",\n";
            $jsonstring = $jsonstring . "\"data\" : [\n";
            $jsonstring = $jsonstring . "\"median\" : " . mmmr($template_lengths, median) . ",\n";
            $jsonstring = $jsonstring . "\"percentile90\" : " . $template_lengths[round(90 / 100 * count($complement_lengths))] . ",\n";
            #echo "Template median is : " . mmmr($template_lengths,median) . "\n";
            #echo "Template array length is: " . count($template_lengths). "\n";
            #echo "90 percentile is value: " . round( 90/100 * count($template_lengths)) . "\n";
            #echo "90 percentile length is: " . $template_lengths[round( 90/100 * count($template_lengths))] . "\n";
            #echo "Template length is: " .array_sum($template_lengths) . "\n";
            $cumulen = 0;
            foreach ($template_lengths as $row) {
                $cumulen = $cumulen + $row;
                if ($cumulen >= array_sum($template_lengths)) {
                    #echo "N50 length is: " . $row . "\n";
                    $jsonstring = $jsonstring . "\"N50\" : " . $row . ",\n";
                    last;
                }
            }
            $jsonstring = $jsonstring . "]\n";
            $jsonstring = $jsonstring . "},\n";
            $jsonstring = $jsonstring . "{\n";
            $jsonstring = $jsonstring . "\"name\" : \"complement\",\n";
            $jsonstring = $jsonstring . "\"data\" : [\n";
            $jsonstring = $jsonstring . "\"median\" : " . mmmr($complement_lengths, median) . ",\n";
            $jsonstring = $jsonstring . "\"percentile90\" : " . $complement_lengths[round(90 / 100 * count($complement_lengths))] . ",\n";
            #echo "Complement median is : " . mmmr($complement_lengths,median) . "\n";
            #echo "Complement array length is: " . count($complement_lengths). "\n";
            #echo "90 percentile is value: " . round( 90/100 * count($complement_lengths)) . "\n";
            #echo "90 percentile length is: " . $complement_lengths[round( 90/100 * count($complement_lengths))] . "\n";
            #echo "Complement length is: " .array_sum($complement_lengths) . "\n";
            $cumulen = 0;
            foreach ($complement_lengths as $row) {
                $cumulen = $cumulen + $row;
                if ($cumulen >= array_sum($complement_lengths)) {
                    #echo "N50 length is: " . $row . "\n";
                    $jsonstring = $jsonstring . "\"N50\" : " . $row . ",\n";
                    last;
                }
            }
            $jsonstring = $jsonstring . "]\n";
            $jsonstring = $jsonstring . "},\n";
            $jsonstring = $jsonstring . "{\n";
            $jsonstring = $jsonstring . "\"name\" : \"2d\",\n";
            $jsonstring = $jsonstring . "\"data\" : [\n";
            $jsonstring = $jsonstring . "\"median\" : " . mmmr($twod_lengths, median) . ",\n";
            $jsonstring = $jsonstring . "\"percentile90\" : " . $twod_lengths[round(90 / 100 * count($complement_lengths))] . ",\n";
            #echo "2d median is : " . mmmr($twod_lengths,median) . "\n";
            #echo "2d array length is: " . count($twod_lengths). "\n";
            #echo "90 percentile is value: " . round( 90/100 * count($twod_lengths)) . "\n";
            #echo "90 percentile length is: " . $twod_lengths[round( 90/100 * count($twod_lengths))] . "\n";
            #echo "2d length is: " .array_sum($twod_lengths) . "\n";
            $cumulen = 0;
            foreach ($twod_lengths as $row) {
                $cumulen = $cumulen + $row;
                if ($cumulen >= array_sum($twod_lengths)) {
                    #echo "N50 length is: " . $row . "\n";
                    $jsonstring = $jsonstring . "\"N50\" : " . $row . ",\n";
                    last;
                }
            }
            $jsonstring = $jsonstring . "]\n";
            $jsonstring = $jsonstring . "},\n";
        }
        $jsonstring = $jsonstring . "]\n";
        if ($_GET["prev"] == 1) {
            include 'savejson.php';
        }
        $memcache->set("{$checkvar}", $jsonstring);
    } else {
        $jsonstring = $memcache->get("{$checkvar}");
    }
    // cache for 2 minute as we want yield to update semi-regularly...
    $memcache->delete("{$checkrunning}");
    return $jsonstring;
}