Ejemplo n.º 1
0
function Correlation($array1, $array2)
{
    $avg_array1 = average($array1);
    $avg_array2 = average($array2);
    #print "$avg_array1----- $avg_array2<br>";
    $sum_correlation_up = 0;
    for ($i = 0; $i < count($array1); $i++) {
        $sum_correlation_up = $sum_correlation_up + ($array1[$i] - $avg_array1) * ($array2[$i] - $avg_array2);
    }
    #print $sum_correlation_up."<br>";
    $sum_array1_sumpow2 = 0;
    for ($i = 0; $i < count($array1); $i++) {
        $sum_array1_sumpow2 = $sum_array1_sumpow2 + pow($array1[$i] - $avg_array1, 2);
    }
    $sum_array1_sumpow2_sqrt = sqrt($sum_array1_sumpow2);
    #rint $sum_array1_sumpow2_sqrt."<br>";
    $sum_array2_sumpow2 = 0;
    for ($i = 0; $i < count($array1); $i++) {
        $sum_array2_sumpow2 = $sum_array2_sumpow2 + pow($array2[$i] - $avg_array2, 2);
    }
    $sum_array2_sumpow2_sqrt = sqrt($sum_array2_sumpow2);
    #print $sum_array2_sumpow2_sqrt."<br>";
    $correlation = $sum_correlation_up / ($sum_array1_sumpow2_sqrt * $sum_array2_sumpow2_sqrt);
    return $correlation;
}
Ejemplo n.º 2
0
function variance($nums)
{
    $v = 0;
    $average = average($nums);
    $len = count($nums);
    for ($i = 0; $i < $len; $i++) {
        $v += pow($nums[$i] - $average, 2);
    }
    return $v / $len;
}
function variance($tabval) {
$nbval=count($tabval);
$total=0;
$moy=average($tabval);
foreach ($tabval as $val)
	{
	$total=$total+(($val-$moy)*($val-$moy));
	}
return(($nbval!=0 ? $total/$nbval :0));
}
 public function calculate_hw()
 {
     $conn = connect_db();
     $sql = "SELECT score FROM `homework_score` WHERE cwid=" . $this->cwid;
     $result = $conn->query($sql);
     disconnect_db($conn);
     if ($result->num_rows > 0) {
         $i = 0;
         while ($row = $result->fetch_assoc()) {
             $hwscores[$i] = $row["score"];
             $i += 1;
         }
     }
     return average($hwscores);
 }
Ejemplo n.º 5
0
function get_demand($vals)
{
    $new_curve = array();
    $dt = 15;
    $size = count($vals);
    for ($i = 0; $i < $size; $i += $dt) {
        $period = array_slice($vals, $i, $dt);
        $avg = average($period);
        $new_curve[] = $avg;
        //		print "$i: $avg " . ($avg * $charge_fact) . "\n";
    }
    //	foreach ($vals as $key => $val) {
    //		$new_curve[$key] = $val * $val;
    //	}
    return $new_curve;
}
Ejemplo n.º 6
0
/**
 * BenchMark
 *
 * @param int   $count
 * @param array $functions
 * @return void
 */
function b($count, $functions)
{
    $times = array();
    for ($trial = TRIAL_LIMIT; $trial--;) {
        foreach ($functions as $key => $func) {
            $t = microtime(true);
            for ($i = $count; $i--;) {
                $func();
            }
            $times[$key][] = microtime(true) - $t;
        }
    }
    foreach ($times as $key => $val) {
        error_log('BenchMark ' . ($key + 1) . "\t" . 'average:' . average($val));
    }
}
Ejemplo n.º 7
0
function median($collection)
{
    $size = size($collection);
    if ($size === 0) {
        $median = null;
    } else {
        $sorted = values(sort($collection));
        if ($size % 2 === 0) {
            // For an even number of values,
            // the median is the average of the middle two values
            $start = $size / 2 - 1;
            $end = $start + 1;
            $median = average(array(at($sorted, $start), at($sorted, $end)));
        } else {
            // For an odd number of values,
            // the median is the middle value
            $index = floor($size / 2);
            $median = at($sorted, $index);
        }
    }
    return $median;
}
Ejemplo n.º 8
0
function improve($guess, $x)
{
    return average($guess, $x / $guess);
}
Ejemplo n.º 9
0
 public static function getResultHistoricalValue($data, $obj)
 {
     $value = 0;
     if (count($data) <= 1) {
         return $value;
         //TODO: Handle cases where amount of data returned is less than expected
     }
     $historical_data = array_slice($data, 0, count($data) - 1);
     if ($obj->getBaseline() == 'average') {
         $value = average($historical_data);
     } elseif ($obj->getBaseline() == 'median') {
         $value = median($historical_data);
     }
     return $value;
 }
 $rating_score = getRatingScore($rating);
 if ($rating != "") {
     $ratings[] = getRatingScore($rating);
 }
 echo $compare_user->name . ": " . $rating;
 $group_rating = getGroupRating(getStDev($ratings));
 if (average($ratings) == 0) {
     $unanimous_score = "N";
     $this_rating_style = "neutral";
     //HAVE TO ADD THAT STYLE
 } else {
     if (average($ratings) <= -1.5) {
         $unanimous_score = "I";
         $this_rating_style = "inconsistent";
     } else {
         if (average($ratings) >= 1.5) {
             $unanimous_score = "C";
             $this_rating_style = "consistent";
         }
     }
 }
 if ($group_rating <= 1) {
     echo "', CAPTION, 'Consensus');\" onmouseout=\"return nd();\" <div class=\"unanimity\"><a href='" . $base_URL . "project/" . $active_project->id . "/cell/" . $this_evidence->id . "/" . $active_project->hypotheses[$j] . "'>Consensus</a><span class=\"" . $this_rating_style . "\">&nbsp {$unanimous_score} &nbsp</span></div>";
 }
 if ($group_rating == 2) {
     echo "', CAPTION, 'Mild Dispute');\" onmouseout=\"return nd();\"><div class=\"mildDisagreement\"><a href='" . $base_URL . "project/" . $active_project->id . "/cell/" . $this_evidence->id . "/" . $active_project->hypotheses[$j] . "'>Mild Dispute</a></div>";
 }
 if ($group_rating == 3) {
     echo "', CAPTION, 'Large Dispute');\" onmouseout=\"return nd();\"><div class=\"starkDisagreement\"><a href='" . $base_URL . "project/" . $active_project->id . "/cell/" . $this_evidence->id . "/" . $active_project->hypotheses[$j] . "'>Large Dispute</a></div>";
 }
 if ($group_rating == 4) {
Ejemplo n.º 11
0
function module_out($modul)
{
    global $list_modules_limit, $list_modules_diagram, $config_stat_max_style, $config_stat_limit, $config_stat_pie_colors, $config_stat_referer_ignore, $config_stat_long_bars, $config_stat_scroll_middle, $config_stat_scroll_right, $config_stat_files_maxlength, $config_stat_bar_length, $config_stat_pie_size, $config_stat_files_hide_dir, $config_stat_ext_lytebox, $ajaxRefresh, $config_stat_files_link, $config_stat_weekdays_sunday_first;
    $module_werte = $_SESSION['module_' . $modul . '_data'];
    $gesamt = $_SESSION['module_' . $modul . '_total'];
    $max = $_SESSION['module_' . $modul . '_max'];
    $max_name = $_SESSION['module_' . $modul . '_max_name'];
    $name = constant('L_MODULES_' . strtoupper($modul) . '_S');
    $name_p = constant('L_MODULES_' . strtoupper($modul) . '_P');
    echo '   <!-- Start Modul ' . ucfirst($modul) . ' -->' . "\n";
    if (!isset($_GET['modul'])) {
        echo '   <div id="module_' . $modul . '">';
    }
    if ($modul == 'hit') {
        ?>
    <table class="modul">
     <thead>
      <tr><th colspan="2" class="modul"><a href="show_stat.php?<?php 
        echo SIDX;
        ?>
&amp;changed=hit" onclick="return refresh('hit','mode=refresh');"><img src="img/refresh.png" align="right" title="<?php 
        echo L_REFRESH;
        ?>
" alt="<?php 
        echo L_REFRESH;
        ?>
" width="16" height="16" /></a><?php 
        echo L_MODULES_HIT_P;
        ?>
</th></tr>
     </thead>
     <tbody>
      <tr><td><?php 
        echo L_MODULEOUT_HITS_PI;
        ?>
:</td><td><?php 
        echo $module_werte['gesamt'];
        ?>
</td></tr>
      <tr><td><?php 
        echo L_MODULEOUT_HITS_VISITS;
        ?>
:</td><td><?php 
        echo $module_werte['gesamt_ip'];
        ?>
</td></tr>
      <tr><td><?php 
        echo L_MODULEOUT_HITS_THIS_MONTH;
        ?>
:</td><td><?php 
        echo $module_werte['diesen_monat'];
        ?>
</td></tr>
      <tr><td><?php 
        echo L_MODULEOUT_HITS_LAST_MONTH;
        ?>
:</td><td><?php 
        echo $module_werte['letzten_monat'];
        ?>
</td></tr>
      <tr><td><?php 
        echo L_MODULEOUT_HITS_USER_ONLINE;
        ?>
:</td><td><?php 
        echo $module_werte['user_online'];
        ?>
</td></tr>
      <tr><td><?php 
        echo L_MODULEOUT_HITS_MAX_DAY;
        ?>
 <?php 
        echo @$module_werte['max_tag'];
        ?>
:</td><td><?php 
        echo $module_werte['max'];
        ?>
</td></tr>
      <tr><td><?php 
        echo L_MODULEOUT_HITS_AV_PER_DAY;
        ?>
</td><td>
	      <?php 
        echo number_format($module_werte['durchschnitt'], 2, L_DECIMAL_SEPARATOR, L_THOUSANDS_SEPARATOR);
        ?>
</td></tr>
      <tr>
       <td><?php 
        echo L_MODULEOUT_HITS_HITS_PER_USER;
        ?>
</td>
       <td>
<?php 
        echo number_format($module_werte['proUser'], 2, L_DECIMAL_SEPARATOR, L_THOUSANDS_SEPARATOR);
        ?>
	   </td>
	  </tr>
      <tr>
       <td><?php 
        echo L_MODULEOUT_HITS_VISIT_TIME_AVG;
        ?>
</td>
       <td><?php 
        echo floor($module_werte['visit_time_avg']) . L_MINUTES_ABR . ' ' . round(($module_werte['visit_time_avg'] - floor($module_werte['visit_time_avg'])) * 60) . L_SECONDS_ABR;
        ?>
	   </td>
	  </tr>
      <tr><td><?php 
        echo L_MODULEOUT_HITS_VISIT_TIME_TOTAL;
        ?>
</td><td>
<?php 
        echo number_format($module_werte['visit_time_total'] / 60 / 60 / 24, 2, L_DECIMAL_SEPARATOR, L_THOUSANDS_SEPARATOR) . ' ' . L_DAYS;
        ?>
</td></tr>
     </tbody>
    </table>
<?php 
    } else {
        if (!isset($config_stat_limit[$modul]) || $config_stat_limit[$modul] != 0) {
            if (in_array($modul, $list_modules_limit)) {
                if (!isset($module_werte) || !is_array($module_werte) || count($module_werte) < 1) {
                    $module_werte = array(L_MODULEOUT_NO_DATA => 0);
                } else {
                    arsort($module_werte);
                }
            }
            if ($_SESSION['set_' . $modul . '_time_span']) {
                if (!empty($_SESSION['set_' . $modul . '_time_name'])) {
                    $zeitabschnitt = $_SESSION['set_' . $modul . '_time_name'];
                } else {
                    $zeitabschnitt_start = date(L_DATE_FORMAT, $_SESSION['set_' . $modul . '_time_start']);
                    $zeitabschnitt_ende = date(L_DATE_FORMAT, $_SESSION['set_' . $modul . '_time_end']);
                    $zeitabschnitt = $zeitabschnitt_start . '-' . $zeitabschnitt_ende;
                }
            } else {
                $zeitabschnitt = L_MODULEOUT_TOTAL_TIME;
            }
            echo '   <table class="modul">';
            echo "\n" . '    <tr><th colspan="2" class="modul">' . konsole($modul) . ($_SESSION['set_' . $modul . '_ip'] ? L_VISITS : L_PAGEIMPRESSIONS) . '/' . $name . ' <span class="spanne">(' . $zeitabschnitt . ")</span></th></tr>\n   ";
            // ______________________Pie Chart______________________
            if (in_array($modul, $list_modules_diagram) && $_SESSION['set_' . $modul . '_piechart']) {
                $link = 'href="pie_zoom.php?' . SIDX . '&amp;modul=' . $modul . '&amp;" ' . ($config_stat_ext_lytebox ? 'rel="lyteframe" rev="width: 700px; height: 420px; scrolling: no;"' : "onclick=\"kreis_zoom=window.open('pie_zoom.php?" . SIDX . "&amp;modul=" . $modul . "','kreis_zoom','height=420, width=700'); kreis_zoom.focus(); return false;\"") . ' target="_blank"';
                $link_map = 'href="pie_zoom.php?' . SIDX . '&amp;modul=' . $modul . '&amp;" ' . ($config_stat_ext_lytebox ? 'target="lyteframe" ' : "onclick=\"kreis_zoom=window.open('pie_zoom.php?" . SIDX . "&amp;modul=" . $modul . "','kreis_zoom','height=420, width=700'); kreis_zoom.focus(); return false;\"");
                ?>
    <tr>
     <td>
<?php 
                echo '<a ' . $link . 'title="' . L_MODULEOUT_PIE_CHART . ' ' . $name_p . '"><img
				src="piechart.php?' . SIDX . '&amp;modul=' . $modul . '"
				id="kreisdiagramm_' . $modul . '"
				alt="' . L_MODULEOUT_PIE_CHART . ' ' . $name . '"
				width="' . $config_stat_pie_size . '"
				height="' . $config_stat_pie_size . '"
				usemap="#map_' . $modul . '" /></a>';
                ?>
	 </td>
     <td>
<?php 
                echo pie_map($modul, $link_map, $config_stat_pie_size);
                if ($_SESSION['scroll'] && in_array($modul, $list_modules_limit)) {
                    echo '<div style="width:180px; height:1px;"></div>';
                    // Minwidth-ersatz
                    if ($modul == 'browser') {
                        $h = 113;
                        $w = $config_stat_scroll_middle - 100;
                    } else {
                        $h = 113;
                        $w = $config_stat_scroll_right - 100;
                    }
                    echo '<div class="daten" ' . ($_SESSION['set_' . $modul . '_all'] ? 'style="height:' . $h . 'px;"' : '') . '>';
                }
                ?>
      <table class="daten" id="daten_<?php 
                echo $modul;
                ?>
">
       <thead>
        <tr>
         <th title="<?php 
                echo L_MODULEOUT_SORT_BY . ' ' . $name;
                ?>
"><?php 
                echo $name;
                ?>
</th>
         <th title="<?php 
                echo L_MODULEOUT_SORT_BY_NUM;
                ?>
"><?php 
                echo L_MODULEOUT_NUM;
                ?>
</th>
         <th title="<?php 
                echo L_MODULEOUT_SORT_BY_PER;
                ?>
"><?php 
                echo L_MODULEOUT_PER;
                ?>
</th>
        </tr>
       </thead>
       <tfoot>
        <tr class="gesamt">
         <td><?php 
                echo L_MODULEOUT_TOTAL;
                ?>
</td>
         <td><?php 
                echo $gesamt;
                ?>
</td>
         <td>
<?php 
                echo '(' . L_AVG_SYMBOL . ' ' . average($gesamt, $module_werte) . ')';
                ?>
		 </td>
        </tr>
       </tfoot>  
       <tbody>
<?php 
                $farben = $config_stat_pie_colors;
                $grauton = 0;
                $i = 0;
                foreach ($module_werte as $eintrag => $anzahl) {
                    $prozent = prozent($anzahl, $gesamt);
                    if ($_SESSION['set_' . $modul . '_all'] || $i < $config_stat_limit[$modul]) {
                        if (!isset($farben[$i])) {
                            $grauton += 20;
                            if ($grauton > 255) {
                                $grauton = 0;
                            }
                            $farben[$i] = 'rgb(' . $grauton . ',' . $grauton . ',' . $grauton . ')';
                        }
                        if ($modul == 'resolution') {
                            if (empty($eintrag)) {
                                $eintrag = L_ANALYZE_UNSAVED;
                            } elseif ($eintrag == '?') {
                                $eintrag = L_ANALYZE_UNKNOWN_RESOLUTION;
                            }
                        }
                        echo '<tr><td><span style="background-color:' . $farben[$i] . ';">&nbsp;&nbsp;</span>&nbsp;' . htmlentities($eintrag, ENT_COMPAT, "UTF-8") . '</td><td>' . $anzahl . '</td><td>' . $prozent . ' %</td></tr>';
                        $i++;
                    } elseif ($prozent < 2) {
                        break;
                    }
                }
                ?>
       </tbody>
      </table>
<?php 
                if ($_SESSION['scroll'] && in_array($modul, $list_modules_limit)) {
                    echo '</div>';
                }
                ?>
 
     </td>
    </tr>
<?php 
            } elseif ($modul == 'referer' && $_SESSION['tree'] !== false) {
                // Referer zusammenfassen
                $referer2 = $module_werte;
                unset($module_werte);
                foreach ($referer2 as $referer => $anzahl) {
                    $url_info = parse_url($referer);
                    if (!isset($url_info['host'])) {
                        $url_info['host'] = '';
                    }
                    $referer = str_replace(empty($url_info['scheme']) ? '' : $url_info['scheme'] . '://' . $url_info['host'], '', $referer);
                    $module_werte[$url_info['host']][$referer] = $anzahl;
                }
                // Array mit Anzahl hits pro Host erstellen
                $gesamt_hosts = 0;
                $max_referer_hosts = 0;
                if (isset($module_werte)) {
                    foreach ($module_werte as $eintrag => $wert) {
                        if (is_array($wert)) {
                            $hostanz_array[$eintrag] = 0;
                            foreach ($wert as $wert2) {
                                $hostanz_array[$eintrag] += $wert2;
                            }
                            @($gesamt_hosts += $hostanz_array[$eintrag]);
                            if ($config_stat_long_bars && $hostanz_array[$eintrag] > $max_referer_hosts) {
                                $max_referer_hosts = $hostanz_array[$eintrag];
                            }
                        }
                    }
                }
                @arsort($hostanz_array);
                if ($_SESSION['tree'] == 'mk') {
                    //  use plugin mktree
                    echo ' <tr><th colspan="2">' . $name . '<span class="ref130">' . L_MODULEOUT_NUM . '</span><span style="position:absolute; right:510px">' . L_MODULEOUT_RATIO . '</span></th></tr><tr><td colspan="2"><ul class="mktree" id="tree1">';
                    // Hosts durchgehen
                    $i = 0;
                    if (isset($hostanz_array)) {
                        foreach ($hostanz_array as $eintrag => $hostanz) {
                            $wert = $module_werte;
                            $wert = $wert[$eintrag];
                            // Ausgabe
                            if (!isset($config_stat_limit[$modul]) || (!$_SESSION['set_' . $modul . '_all'] && $i < $config_stat_limit[$modul] || $_SESSION['set_' . $modul . '_all'])) {
                                echo '<li>';
                                $prozent = prozent($hostanz, $gesamt_hosts);
                                if ($config_stat_long_bars && isset($max_referer_hosts)) {
                                    $prozent2 = round(prozent($hostanz, $max_referer_hosts) / 100 * $config_stat_bar_length);
                                } else {
                                    $prozent2 = round($prozent / 100 * $config_stat_bar_length);
                                }
                                $rest = $config_stat_bar_length - $prozent2;
                                if (is_string($eintrag)) {
                                    echo $eintrag;
                                }
                                // Hostname ausgeben
                                if (is_array($wert)) {
                                    // einzelne Referer durchgehen
                                    echo '<span class="ref130">' . $hostanz . '</span><span class="ref20"><img src="img/bar1.gif" height="10" width="' . $prozent2 . '" title="' . $prozent . '%" alt="' . $prozent . '%" /><img src="img/bar0.gif" height="10" width="' . $rest . '" title="' . $prozent . '%" alt="" /></span>';
                                    // Anzahl Hits  und Balken des Host
                                    echo '<ul>';
                                    arsort($wert);
                                    foreach ($wert as $eintrag2 => $wert2) {
                                        // Einzelne Referer des hosts durchgehen
                                        if (strlen($eintrag2) > 100) {
                                            // kuerzen?
                                            $eintrag2_ungekuertzt = $eintrag2;
                                            $eintrag2 = substr($eintrag2, 0, 100) . "[...]";
                                        } else {
                                            $eintrag2_ungekuertzt = $eintrag2;
                                        }
                                        $eintrag2 = '<a href=\'' . linkprep('http://' . $eintrag . $eintrag2_ungekuertzt) . '\' class="referer" target="_blank">' . htmlentities($eintrag2, ENT_COMPAT, "UTF-8") . '</a>' . "\n";
                                        echo '<li>' . $eintrag2;
                                        // einzelnen referer ausgeben
                                        if (is_int($wert2)) {
                                            $prozent = prozent($wert2, $gesamt_hosts);
                                            if ($config_stat_long_bars && isset($max)) {
                                                $prozent2 = round(prozent($wert2, $max) / 100 * $config_stat_bar_length);
                                            } else {
                                                $prozent2 = round($prozent / 100 * $config_stat_bar_length);
                                            }
                                            $rest = $config_stat_bar_length - $prozent2;
                                            echo '<span class="ref130">' . $wert2 . '</span><span class="ref20"><img src="extensions/lightblue.gif" height="10" width="' . $prozent2 . '" title="' . $prozent . '%" alt="' . $prozent . '%" /><img src="img/bar0.gif" height="10" width="' . $rest . '" title="' . $prozent . '%" alt="" /></span>';
                                        }
                                        echo '</li>';
                                    }
                                    echo '</ul>';
                                }
                                echo '</li>';
                            } else {
                                break;
                            }
                            $i++;
                        }
                    }
                    echo '</ul>';
                    if (!$ajaxRefresh) {
                        echo '<script type="text/javascript">mk=true; ajaxTree=false;</script>';
                    }
                    echo '<div style="border-top: 1px solid #CACACA;"><span style="margin-left: 20px">' . L_MODULEOUT_TOTAL . '</span><span class="ref130">' . $gesamt . ' (&#248; ' . average($gesamt, $module_werte) . ')</span></div>';
                } elseif ($_SESSION['tree'] == 'ajax') {
                    //mit plugin ajaxTree
                    echo ' <tr><td colspan="2">';
                    // Speichere Baum-Daten in Session fuer ref_pages.php
                    $anz_hosts = count($hostanz_array);
                    if (isset($config_stat_limit[$modul]) && $anz_hosts > $config_stat_limit[$modul] && !$_SESSION['set_' . $modul . '_all']) {
                        $_SESSION['module_referer_hosts'] = array();
                        reset($hostanz_array);
                        for ($i = 0; $i < $config_stat_limit[$modul]; $i++) {
                            $_SESSION['module_referer_hosts'][key($hostanz_array)] = $module_werte[key($hostanz_array)];
                            next($hostanz_array);
                        }
                    } else {
                        $_SESSION['module_referer_hosts'] = $module_werte;
                    }
                    // save keys for refpages.php
                    @($_SESSION['module_referer_keys'] = array_keys($hostanz_array));
                    if (isset($config_stat_limit[$modul]) && $anz_hosts > $config_stat_limit[$modul] && !$_SESSION['set_' . $modul . '_all']) {
                        $anz_hosts = $config_stat_limit[$modul];
                    }
                    // pass data to JavaScript (using JSON)
                    $js_data = array();
                    $js_data['parents'] = array();
                    $js_data['laenge'] = $config_stat_bar_length;
                    $js_data['gesamt'] = $gesamt_hosts;
                    $js_data['gesamt2'] = $config_stat_long_bars && isset($max) ? $max : $gesamt;
                    $js_data['host_anz'] = $anz_hosts;
                    $js_data['childs'] = array(0);
                    $js_data['sid'] = SIDX;
                    ?>
     <table style="width:100%" cellpadding="0" cellspacing="0" id="daten_referer">
      <colgroup>
       <col width="10" />
       <col width="*" />
       <col width="50" />
       <col width="110" />
      </colgroup>
      <thead>
       <tr>
        <th colspan="2"><?php 
                    echo $name;
                    ?>
</th>
        <th><?php 
                    echo L_MODULEOUT_NUM;
                    ?>
</th>
        <th><?php 
                    echo L_MODULEOUT_RATIO;
                    ?>
</th>
       </tr>
      </thead>
      <tfoot>
<?php 
                    echo '<tr class="gesamt"><td></td><td>' . L_MODULEOUT_TOTAL . ' ' . L_MODULEOUT_PAGES . '/' . L_MODULEOUT_DOMAINS . '</td><td>' . $gesamt . '/' . count($hostanz_array) . '</td><td>' . '(' . L_AVG_SYMBOL . ' ' . average($gesamt, $module_werte) . ')' . '</td></tr>';
                    ?>
      </tfoot>
      <tbody id="tabelle">
<?php 
                    // Hosts durchgehen
                    $id = 0;
                    $js_data['hosts'] = array("");
                    if (isset($hostanz_array)) {
                        foreach ($hostanz_array as $eintrag => $hostanz) {
                            $id++;
                            // Ausgabe
                            if (!isset($config_stat_limit[$modul]) || (!$_SESSION['set_' . $modul . '_all'] && $id <= $config_stat_limit[$modul] || $_SESSION['set_' . $modul . '_all'])) {
                                $prozent = prozent($hostanz, $gesamt_hosts);
                                if ($config_stat_long_bars && isset($max_referer_hosts)) {
                                    $prozent2 = round(prozent($hostanz, $max_referer_hosts) / 100 * $config_stat_bar_length);
                                } else {
                                    $prozent2 = round($prozent / 100 * $config_stat_bar_length);
                                }
                                $rest = $config_stat_bar_length - $prozent2;
                                $handle = 'onclick="menuclick(' . $id . '); return false;"';
                                $js_data['childs'][] = count($module_werte[$eintrag]);
                                $js_data['hosts'][] = $eintrag;
                                echo '<tr id="row' . $id . '" class="ajaxTreeZeile' . $id % 2 . '"><td><img src="extensions/ajaxTree/plus';
                                if ($anz_hosts == 1) {
                                    echo '5';
                                } elseif ($id == 1) {
                                    echo '1';
                                } elseif ($id == $anz_hosts) {
                                    echo '3';
                                } else {
                                    echo '2';
                                }
                                echo '.gif" alt="+" title="" id="pic' . $id . '" ' . $handle . ' class="ajaxTreeHand" /></td>';
                                echo '<td><a href="nojs.php" ' . $handle . ' class="ajaxTreeDomain">' . $eintrag . '</a></td>
								<td>' . $hostanz . '</td>
								<td><img src="img/bar1.gif" height="10" width="' . $prozent2 . '" title="' . $prozent . '%" alt="' . $prozent . '%" /><img src="img/bar0.gif" height="10" width="' . $rest . '" title="' . $prozent . '%" alt="" /></td>
       </tr>';
                            } else {
                                break;
                            }
                        }
                    }
                    ?>
     </tbody>
     </table>
     <script type="text/javascript" language="javascript">
     var js_data = <?php 
                    echo json_encode($js_data);
                    ?>
;
     </script>
     <?php 
                    $_SESSION['ajax_tree_js_data'] = $js_data;
                }
                echo '</td></tr>';
            } else {
                echo ' <tr><td colspan="2">';
                if ($_SESSION['scroll'] && in_array($modul, $list_modules_limit) && $modul != 'referer' && $modul != 'keyword') {
                    echo '<div style="width:' . ($modul == 'browser' ? 240 : 300) . 'px; height:1px"></div>';
                    // replacement of minwidth
                    if ($modul == 'browser') {
                        $h = 113;
                    } elseif ($modul == 'file') {
                        $h = 220;
                    } elseif ($modul == 'colordepth') {
                        $h = 95;
                    } else {
                        $h = 102;
                    }
                    echo '<div style="' . ($_SESSION['set_' . $modul . '_all'] ? 'height:' . $h . 'px; overflow:auto; ' : '') . 'width:100%;">';
                }
                echo '<table class="daten" id="daten_' . $modul . '"><thead><tr><th title="' . L_MODULEOUT_SORT_BY . ' ' . $name . '">' . $name . '</th><th title="' . L_MODULEOUT_SORT_BY_NUM . '">' . ($modul == 'day' ? L_MODULEOUT_NUM_ABR : L_MODULEOUT_NUM) . '</th><th title="' . L_MODULEOUT_SORT_BY_RATIO . '">' . L_MODULEOUT_RATIO . '</th></tr></thead>
          <tfoot><tr class="gesamt"><td>' . L_MODULEOUT_TOTAL . '</td><td>' . $gesamt . '</td><td>' . '(' . L_AVG_SYMBOL . ' ' . average($gesamt, $module_werte) . ')</td></tr></tfoot>
          <tbody>';
                if ($modul == 'weekday') {
                    if (!$config_stat_weekdays_sunday_first && isset($module_werte[0])) {
                        $module_werte[7] = $module_werte[0];
                        unset($module_werte[0]);
                    }
                    $tag_namen = explode(' ', L_CALENDAR_WEEKDAYS);
                    $tag_namen[] = $tag_namen[0];
                }
                $i = 0;
                if (isset($module_werte)) {
                    reset($module_werte);
                    if (isset($_SESSION['set_' . $modul . '_time_rel_startid'])) {
                        $startid = calc_start_id($_SESSION['set_' . $modul . '_time_rel_startid']);
                        for ($goid = 1; $goid < $startid; $goid++) {
                            next($module_werte);
                        }
                    }
                    for ($togo = count($module_werte); $togo > 0; $togo--) {
                        if (current($module_werte) === false) {
                            reset($module_werte);
                            // start from the beginning
                            $separate = true;
                        } else {
                            $separate = false;
                        }
                        list($eintrag, $anzahl) = each($module_werte);
                        if (!isset($config_stat_limit[$modul]) || ($_SESSION['set_' . $modul . '_all'] || $i < $config_stat_limit[$modul])) {
                            $prozent = prozent($anzahl, $gesamt);
                            if ($config_stat_long_bars && isset($max)) {
                                $prozent2 = round(prozent($anzahl, $max) / 100 * $config_stat_bar_length);
                            } else {
                                $prozent2 = round($prozent / 100 * $config_stat_bar_length);
                            }
                            $rest = $config_stat_bar_length - $prozent2;
                            if (isset($max_name) && $eintrag == $max_name && !in_array($modul, $list_modules_limit)) {
                                $markiere = " class='max'";
                            } else {
                                $markiere = '';
                            }
                            if ($modul == 'file') {
                                $eintrag = urldecode($eintrag);
                                $eintrag_ungekuertzt = $eintrag;
                                if (!isset($config_stat_files_hide_dir) || $config_stat_files_hide_dir) {
                                    $eintrag = basename($eintrag);
                                }
                                if ($eintrag_ungekuertzt[strlen($eintrag_ungekuertzt) - 1] == '/') {
                                    $eintrag .= '/';
                                }
                                if (strlen($eintrag) > $config_stat_files_maxlength) {
                                    $eintrag = substr($eintrag, 0, $config_stat_files_maxlength - 2) . '[...]';
                                }
                                $eintrag = htmlentities($eintrag, ENT_COMPAT, "UTF-8");
                                if (is_string($config_stat_files_link)) {
                                    $eintrag = '<a href=\'' . linkprep($config_stat_files_link . $eintrag_ungekuertzt) . '\' target="_blank">' . $eintrag . '</a>';
                                }
                            } elseif ($modul == 'colordepth') {
                                $eintrag = '<span title="' . pow(2, $eintrag) . ' ' . L_MODULEOUT_COLORS . '">' . prettyInt(pow(2, $eintrag)) . ' ' . L_MODULEOUT_COLORS . ' (' . $eintrag . ' ' . L_BIT . ')</span>';
                            } elseif ($modul == 'keyword' && isset($_SESSION['module_keyword_orig'][$eintrag])) {
                                $eintrag = $_SESSION['module_keyword_orig'][$eintrag];
                            }
                            if ($modul == 'referer') {
                                $eintrag_ungekuertzt = $eintrag;
                                $eintrag = htmlentities(substr($eintrag, 0, 100), ENT_COMPAT, "UTF-8") . ' ' . htmlentities(substr($eintrag, 100, 100), ENT_COMPAT, "UTF-8");
                            } elseif (!isset($eintrag_ungekuertzt)) {
                                $eintrag_ungekuertzt = $eintrag;
                            }
                            if ($modul == 'weekday' && isset($tag_namen[$eintrag])) {
                                $eintrag = $tag_namen[$eintrag];
                            } elseif ($modul == 'referer') {
                                $eintrag = '<a href=\'' . linkprep($eintrag_ungekuertzt) . '\' class="referer" target="_blank">' . $eintrag . '</a>';
                            }
                            if ($modul == 'file') {
                                echo "<tr><td title='" . str_replace("'", '&#39;', htmlentities($eintrag_ungekuertzt, ENT_COMPAT, "UTF-8")) . "' style='cursor:help'>" . $eintrag . "</td>";
                            } else {
                                echo '<tr' . ($separate ? ' class="separate"' : '') . '><td' . $markiere . '>' . $eintrag . '</td>';
                            }
                            echo '<td' . $markiere . '>' . $anzahl . '</td><td' . $markiere . '><img src="img/bar1.gif" height="10" width="' . $prozent2 . '" title="' . $prozent . '%" alt="' . $prozent . '%" /><img src="img/bar0.gif" height="10" width="' . $rest . '" title="' . $prozent . '%" alt="" /></td></tr>' . "\n    ";
                            unset($eintrag_ungekuertzt);
                            $i++;
                        } else {
                            break;
                        }
                    }
                }
                echo '</tbody>';
                echo '</table>';
                if ($_SESSION['scroll'] && in_array($modul, $list_modules_limit) && $modul != 'referer' && $modul != 'keyword') {
                    echo '</div>';
                }
                echo '</td></tr>';
            }
            echo "\n" . '   </table>';
        }
    }
    if (!isset($_GET['modul'])) {
        echo "\n" . '   </div>';
        if (is_file('extensions/sortabletable.js') && $modul != 'hit' && ($modul != 'referer' || $_SESSION['tree'] === false)) {
            ?>
   <script type="text/javascript">
   t=new SortableTable(document.getElementById('daten_<?php 
            echo $modul;
            ?>
'), 100);
   </script>
   <?php 
        }
    }
    echo "\n" . '   <!-- Ende Modul ' . ucfirst($modul) . ' -->' . "\n";
}
Ejemplo n.º 12
0
function variance($arr)
{
    if (count($arr) < 2) {
        return 0;
    }
    $mean = average($arr);
    $sos = 0;
    // Sum of squares
    for ($i = 0; $i < count($arr); $i++) {
        $sos += ($arr[$i] - $mean) * ($arr[$i] - $mean);
    }
    return $sos / (count($arr) - 1);
}
Ejemplo n.º 13
0
<?php

/**
 * Created by PhpStorm.
 * User: Kramok
 * Date: 29/9/2015
 * Time: 12:04 PM
 */
function average($a, $b)
{
    return ($a + $b) / 2;
}
print average(6, 7);
Ejemplo n.º 14
0
function stats_summary($array)
{
    $stats = array();
    $stats['min'] = min($array);
    $stats['max'] = max($array);
    $stats['avg'] = round(average($array), 2);
    $stats['median'] = median($array);
    $stats['Q1'] = array_firstQuartile($array);
    $stats['Q3'] = array_thirdQuartile($array);
    $stats['truncatedMean'] = array_truncatedMean($array);
    return $stats;
}
<?php

function average($numbers)
{
    $a = explode(' ', $numbers);
    $d = count($a);
    for ($i = $d; $i; $i--) {
        $c = $c + $a[$i];
    }
    return number_format($c / $d, 0);
}
$numbers = "1 4 9 10 4 8";
print average($numbers);
print "\n";
Ejemplo n.º 16
0
$labels = array_map(function ($a, $b) {
    $dateString = $a . ' ' . $b . ' UTC';
    return strtotime($dateString) * 1000;
}, $result[1], $result[2]);
// Create Points for Flot charting library
$points = array_map(function ($a, $b) {
    return array($a, $b);
}, $labels, $floatValues);
// Calculate average and min/max values
$average = average($floatValues);
$lowest = getMin($floatValues);
$highest = getMax($floatValues);
$average24Hours = average($valuesLast24Hours);
$lowest24Hours = getMin($valuesLast24Hours);
$highest24Hours = getMax($valuesLast24Hours);
$averageWeek = average($valuesLastWeek);
$lowestWeek = getMin($valuesLastWeek);
$highestWeek = getMax($valuesLastWeek);
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Raspberry Pi Monitor</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <meta http-equiv="refresh" content="900">

    <!-- Le styles -->
    <link href="css/bootstrap.css" rel="stylesheet">
Ejemplo n.º 17
0
<?php

/**
 * Created by PhpStorm.
 * User: Nomad_Mystic
 * Date: 11/3/2015
 * Time: 1:22 AM
 */
function average(...$args)
{
    return array_sum($args) / count($args);
}
echo 'average of 3, 4, 5, 6, 10 is: ' . average(3, 4, 5, 6, 10) . '<br>';
echo 'average of 90, 3, 77, 6, 10 is: ' . average(90, 3, 77, 6, 10) . '<br>';
function ave2()
{
    $args = func_get_args();
    return array_sum($args) / count($args);
}
echo 'average of 3, 4, 5, 6, 10 is: ' . ave2(3, 4, 5, 6, 10) . '<br>';
echo 'average of 90, 3, 77, 6, 10 is: ' . ave2(90, 3, 77, 6, 10) . '<br>';
Ejemplo n.º 18
0
function sn_imperator_view($template = null)
{
    global $template_result, $config, $lang, $user;
    $stat_fields = array('stat_date' => 'STAT_DATE', 'total_rank' => 'TOTAL_RANK', 'total_points' => 'TOTAL_POINTS', 'tech_rank' => 'TECH_RANK', 'tech_points' => 'TECH_POINTS', 'build_rank' => 'BUILD_RANK', 'build_points' => 'BUILD_POINTS', 'defs_rank' => 'DEFS_RANK', 'defs_points' => 'DEFS_POINTS', 'fleet_rank' => 'FLEET_RANK', 'fleet_points' => 'FLEET_POINTS', 'res_rank' => 'RES_RANK', 'res_points' => 'RES_POINTS');
    $user_id = sys_get_param_id('int_user_id', $user['id']);
    $user_data = ($same_user = $user_id == $user['id']) ? $user : db_user_by_id($user_id);
    //  if($user_id == $user['id']) {
    //    $user_data = &$user;
    //    $same_user = true;
    //  } else {
    //    $user_data = db_user_by_id($user_id);
    //    $same_user = false;
    //  }
    if (!$user_data) {
        message($lang['imp_imperator_none'], $lang['sys_error'], 'index.php', 10);
        die;
    }
    $template = gettemplate('imperator', $template);
    $StatRecord = doquery("SELECT * FROM {{statpoints}} WHERE `stat_type` = 1 AND `stat_code` = 1 AND `id_owner` = {$user_id};", true);
    $stat_array = array();
    $query = doquery("SELECT * FROM {{statpoints}} WHERE `stat_type` = 1 AND `id_owner` = {$user_id} ORDER BY `stat_code` DESC;");
    global $link;
    $stat_count = db_affected_rows($link);
    while ($row = db_fetch($query)) {
        foreach ($stat_fields as $field_db_name => $field_template_name) {
            // $stat_count - $row['stat_code'] - для реверсирования ID статы в JS
            $stat_array[$field_template_name]['DATA'][$stat_count - $row['stat_code']] = $row[$field_db_name];
        }
    }
    $stat_array_date = $stat_array['STAT_DATE'];
    foreach ($stat_array_date['DATA'] as $key => $value) {
        $template->assign_block_vars('stat_date', array('ID' => $key, 'VALUE' => $value, 'TEXT' => date(FMT_DATE_TIME, $value)));
    }
    // $stat_count = count($stat_array_date['DATA']);
    // pdump($stat_array_date);
    unset($stat_array['STAT_DATE']);
    $template_data = array();
    foreach ($stat_array as $stat_type => &$stat_type_data) {
        $reverse_min_max = strpos($stat_type, '_RANK') !== false;
        $stat_type_data['MIN'] = $reverse_min_max ? max($stat_type_data['DATA']) : min($stat_type_data['DATA']);
        $stat_type_data['MAX'] = $reverse_min_max ? min($stat_type_data['DATA']) : max($stat_type_data['DATA']);
        $stat_type_data['AVG'] = average($stat_type_data['DATA']);
        foreach ($stat_type_data['DATA'] as $key => $value) {
            // $stat_type_data['PERCENT'][$key] = $stat_type_data['MAX'] - $value ? ($stat_type_data['MAX'] - $stat_type_data['MIN']) / ($stat_type_data['MAX'] - $value) : 100;
            $stat_type_data['PERCENT'][$key] = ($stat_type_data['MAX'] - $value ? ($value - $stat_type_data['MIN']) / ($stat_type_data['MAX'] - $stat_type_data['MIN']) : 1) * 100;
            $template_data[$stat_type][$key]['ID'] = $key;
            $template_data[$stat_type][$key]['VALUE'] = $value;
            $template_data[$stat_type][$key]['DELTA'] = $reverse_min_max ? $stat_type_data['MIN'] - $value : $value - $stat_type_data['MAX'];
            $template_data[$stat_type][$key]['PERCENT'] = $stat_type_data['PERCENT'][$key];
            //$template_data[$stat_type][$key]['PERCENT'] = $key ? $stat_type_data['PERCENT'][$key] : 50; // TODO DEBUG
        }
    }
    // pdump($stat_array['RES_POINTS']);
    foreach ($template_data as $stat_type => $stat_type_data) {
        $template->assign_block_vars('stat', array('TYPE' => $stat_type, 'TEXT' => $lang['imp_stat_types'][$stat_type], 'MIN' => $stat_array[$stat_type]['MIN'], 'MAX' => $stat_array[$stat_type]['MAX'], 'AVG' => $stat_array[$stat_type]['AVG']));
        foreach ($stat_type_data as $stat_entry) {
            $template->assign_block_vars('stat.entry', $stat_entry);
        }
    }
    // pdump($template_data);
    if ($same_user) {
        rpg_level_up($user, RPG_STRUCTURE);
        rpg_level_up($user, RPG_RAID);
        rpg_level_up($user, RPG_TECH);
        rpg_level_up($user, RPG_EXPLORE);
        /*
        // -----------------------------------------------------------------------------------------------
        // News Frame ...
        if ($config->game_news_overview)
        {
          nws_render($template, "WHERE UNIX_TIMESTAMP(`tsTimeStamp`)<=" . SN_TIME_NOW . "", $config->game_news_overview);
        }
        */
    }
    $template->assign_vars(array('USERS_TOTAL' => $config->users_amount, 'USER_ID' => $user_id, 'user_username' => player_nick_render_to_html($user_data, true), 'USER_AVATAR' => $user_data['avatar'], 'VACATION' => $user_data['vacation'], 'GENDER_TEXT' => $lang['sys_gender_list'][$user_data['gender']], 'NEW_MESSAGES' => $user_data['new_message'], 'REGISTRATION_DATE' => date(FMT_DATE_TIME, $user_data['register_time']), 'builder_xp' => pretty_number($user_data['xpminier']), 'builder_lvl' => pretty_number($user_data['lvl_minier']), 'builder_lvl_st' => pretty_number(rpg_get_miner_xp($user_data['lvl_minier'])), 'builder_lvl_up' => pretty_number(rpg_get_miner_xp($user_data['lvl_minier'] + 1)), 'raid_xp' => pretty_number($user_data['xpraid']), 'raid_lvl' => pretty_number($user_data['lvl_raid']), 'raid_lvl_up' => pretty_number(rpg_get_raider_xp($user_data['lvl_raid'] + 1)), 'raids' => pretty_number($user_data['raids']), 'raidswin' => pretty_number($user_data['raidswin']), 'raidsloose' => pretty_number($user_data['raidsloose']), 'tech_xp' => pretty_number($user_data['player_rpg_tech_xp']), 'tech_lvl' => pretty_number($user_data['player_rpg_tech_level']), 'tech_lvl_st' => pretty_number(rpg_get_tech_xp($user_data['player_rpg_tech_level'])), 'tech_lvl_up' => pretty_number(rpg_get_tech_xp($user_data['player_rpg_tech_level'] + 1)), 'explore_xp' => pretty_number($user_data['player_rpg_explore_xp']), 'explore_lvl' => pretty_number($user_data['player_rpg_explore_level']), 'explore_lvl_st' => pretty_number(rpg_get_explore_xp($user_data['player_rpg_explore_level'])), 'explore_lvl_up' => pretty_number(rpg_get_explore_xp($user_data['player_rpg_explore_level'] + 1)), 'build_points' => pretty_number($StatRecord['build_points']), 'tech_points' => pretty_number($StatRecord['tech_points']), 'fleet_points' => pretty_number($StatRecord['fleet_points']), 'defs_points' => pretty_number($StatRecord['defs_points']), 'res_points' => pretty_number($StatRecord['res_points']), 'total_points' => pretty_number($StatRecord['total_points']), 'user_rank' => $StatRecord['total_rank'], 'RANK_DIFF' => $StatRecord['total_old_rank'] - $StatRecord['total_rank'], 'STAT_COUNT' => $stat_count, 'STAT_SPAN' => $stat_count + 1, 'SAME_USER' => $same_user));
    return parsetemplate($template);
}
Ejemplo n.º 19
0
function total_number($array)
{
    $total_number_employees = count($array);
    return $total_number_employees;
}
$total_number_employees = total_number($new);
function get_sum($array)
{
    $total_units = 0;
    foreach ($array as $person) {
        $total_units = $total_units + $person['units'];
    }
    return $total_units;
}
$total_units_sold = get_sum($new);
function average($total, $sum)
{
    $average_units_sold = $total / $sum;
    return $average_units_sold;
}
$average_units_array = average($total_units_sold, $total_number_employees);
// echo "Total number of employees is {$total_number_employees}\n";
// echo "Total units sold is {$total_units_sold}\n";
// echo "Average units is {$average_units_array}\n";
// print_r($new);
// echo "===================================================\n";
// echo "Employee Number, First Name, Last Name, Sales Units\n";
// echo "***************************************************\n";
foreach ($array as $person) {
    echo $person['units'];
}
Ejemplo n.º 20
0
    $sessionqry = mysql_query("SELECT {$selectstring} FROM {$db_table} WHERE session={$session_id} ORDER BY time DESC;") or die(mysql_error());
    while ($row = mysql_fetch_assoc($sessionqry)) {
        $i = 1;
        while (isset(${'v' . $i})) {
            if (substri_count($keyarr[${'v' . $i}][0], "Speed") > 0) {
                $x = intval($row[${'v' . $i}]) * $speed_factor;
                ${'v' . $i . '_measurand'} = $speed_measurand;
            } elseif (substri_count($keyarr[${'v' . $i}][0], "Temp") > 0) {
                $x = $temp_func(floatval($row[${'v' . $i}]));
                ${'v' . $i . '_measurand'} = $temp_measurand;
            } else {
                $x = intval($row[${'v' . $i}]);
                ${'v' . $i . '_measurand'} = ' (' . $keyarr[${'v' . $i}][1] . ')';
            }
            ${'d' . $i}[] = array($row['time'], $x);
            ${'spark' . $i}[] = $x;
            $i = $i + 1;
        }
    }
    $i = 1;
    while (isset(${'v' . $i})) {
        ${'v' . $i . '_label'} = '"' . $keyarr[${'v' . $i}][0] . ${'v' . $i . '_measurand'} . '"';
        ${'sparkdata' . $i} = implode(",", array_reverse(${'spark' . $i}));
        ${'max' . $i} = round(max(${'spark' . $i}), 1);
        ${'min' . $i} = round(min(${'spark' . $i}), 1);
        ${'avg' . $i} = round(average(${'spark' . $i}), 1);
        ${'pcnt25data' . $i} = round(calc_percentile(${'spark' . $i}, 25), 1);
        ${'pcnt75data' . $i} = round(calc_percentile(${'spark' . $i}, 75), 1);
        $i = $i + 1;
    }
}
     $memory = [];
     $time = [];
     $files = [];
     $output = [];
     for ($i = 0; $i < $runs; $i++) {
         cliPrint($container . ' test' . $test . ' : ' . ($i + 1) . '/' . $runs);
         $output = runScript('./' . $container . '/test' . $test . '.php', $inis[$container]);
         $result = json_decode($output[0]);
         if (!is_object($result)) {
             echo $container . $test . '<br />';
         }
         $time[] = $result->time;
         $memory[] = $result->memory;
         $files[] = $result->files;
     }
     $containerInfo[] = ['name' => $container, 'time' => average($time), 'memory' => average($memory), 'files' => average($files)];
 }
 //Sort the results by time
 usort($containerInfo, function ($a, $b) {
     if ($a['time'] == $b['time']) {
         return $a['memory'] < $b['memory'] ? -1 : 1;
     }
     return $a['time'] < $b['time'] ? -1 : 1;
 });
 foreach ($containerInfo as $containerDetail) {
     $html .= '<tr>';
     $html .= '<td>' . $containerDetail['name'] . '</td>';
     $html .= '<td>' . $containerDetail['time'] * 1000 . '</td>';
     $html .= '<td>' . $containerDetail['memory'] * 100 . '</td>';
     $html .= '<td>' . $containerDetail['files'] . '</td>';
     $html .= '</tr>';
 public function showCellCompare($evidence, $sort, $display, $user_1, $user_2)
 {
     // $sort can be "least_likely", "most_likely", "alpha", and "added".
     global $base_URL;
     //THIS FUNCTION IS JUST FOR CONSENSUS RATINGS ON THE MATRIX THAT COMPARES TWO USERS
     $this->sortHCompare($sort, $user_1->id, $user_2->id);
     for ($j = 0; $j < count($this->hypotheses); $j++) {
         echo "<td ";
         if (!$display) {
             echo 'style="display: none;" ';
         }
         echo "onmouseover=\"return overlib('";
         $ratings = array();
         $rating = $this->ratings[$evidence->id][$this->hypotheses[$j]][$user_1->id];
         $rating_score = getRatingScore($rating);
         if ($rating != "") {
             $ratings[] = getRatingScore($rating);
         }
         echo $user_1->name . ": " . $rating;
         echo '&lt;br&gt;';
         $rating = $this->ratings[$evidence->id][$this->hypotheses[$j]][$user_2->id];
         $rating_score = getRatingScore($rating);
         if ($rating != "") {
             $ratings[] = getRatingScore($rating);
         }
         echo $user_2->name . ": " . $rating;
         $group_rating = getGroupRating(getStDev($ratings));
         if (average($ratings) == 0) {
             $unanimous_score = "N";
             $this_rating_style = "neutral";
             //HAVE TO ADD THAT STYLE
         } else {
             if (average($ratings) <= -1.5) {
                 $unanimous_score = "I";
                 $this_rating_style = "inconsistent";
             } else {
                 if (average($ratings) >= 1.5) {
                     $unanimous_score = "C";
                     $this_rating_style = "consistent";
                 }
             }
         }
         if ($group_rating <= 1) {
             echo "', CAPTION, 'Consensus');\" onmouseout=\"return nd();\" class=\"colgroup_" . $sort . "\"><div class=\"unanimity\"><a href='" . $base_URL . "project/" . $this->id . "/cell/" . $evidence->id . "/" . $this->hypotheses[$j] . "'>Consensus</a> <span class=\"" . $this_rating_style . "\">&nbsp {$unanimous_score} &nbsp</span></div>";
         }
         if ($group_rating == 2) {
             echo "', CAPTION, 'Mild Dispute');\" onmouseout=\"return nd();\" class=\"colgroup_" . $sort . "\"><div class=\"mildDisagreement\"><a href='" . $base_URL . "project/" . $this->id . "/cell/" . $evidence->id . "/" . $this->hypotheses[$j] . "'>Mild Dispute</a></div>";
         }
         if ($group_rating == 3) {
             echo "', CAPTION, 'Large Dispute');\" onmouseout=\"return nd();\" class=\"colgroup_" . $sort . "\"><div class=\"starkDisagreement\"><a href='" . $base_URL . "project/" . $this->id . "/cell/" . $evidence->id . "/" . $this->hypotheses[$j] . "'>Large Dispute</a></div>";
         }
         if ($group_rating == 4) {
             echo "', CAPTION, 'Extreme Dispute');\" onmouseout=\"return nd();\" class=\"colgroup_" . $sort . "\"><div class=\"extremeDisagreement\"><a href='" . $base_URL . "project/" . $this->id . "/cell/" . $evidence->id . "/" . $this->hypotheses[$j] . "'>Extreme Dispute</a></div>";
         }
         /*if( count($ratings) > 1 ) {
         			echo("<br /><small>StDev: " . getStDev($ratings) . "</small>");
         		} else {
         			echo("<br /><small>StDev: N/A</small>");
         		}*/
         echo "</td>";
     }
 }
Ejemplo n.º 23
0
function standardDeviation($samples)
{
    $sample_count = count($samples);
    if ($sample_count == 0) {
        return 0;
    }
    $sampleDeviationSum = 0;
    $average = average($samples);
    for ($i = 0; $i < $sample_count; $i++) {
        $sampleDeviationSum += pow($average - $samples[$i], 2);
    }
    $standard_deviation = sqrt($sampleDeviationSum / $sample_count);
    return $standard_deviation;
}
 private function getSummaryTimes($prof)
 {
     $diffValues = array_map(array($this, 'mapDiffTime'), array_filter($prof, array($this, 'filterEndMarker')));
     $times = array();
     $times['times'] = $this->runCount;
     $times['median'] = median($diffValues) * 1000;
     $times['average'] = average($diffValues) * 1000;
     $times['max'] = max($diffValues) * 1000;
     return $times;
 }
Ejemplo n.º 25
0
            $x = floatval($row[$v1]) * 9 / 5 + 32;
        } else {
            $x = intval($row[$v1]);
        }
        $d1[] = array($row['time'], $x);
        $spark1[] = $x;
        // data column #2
        if (substri_count($jsarr[$v2], "Speed") > 0) {
            $x = intval($row[$v2]) * 0.621371;
        } elseif (substri_count($jsarr[$v2], "Temp") > 0) {
            $x = floatval($row[$v2]) * 9 / 5 + 32;
        } else {
            $x = intval($row[$v2]);
        }
        $d2[] = array($row['time'], $x);
        $spark2[] = $x;
    }
    $sparkdata1 = implode(",", array_reverse($spark1));
    $sparkdata2 = implode(",", array_reverse($spark2));
    $max1 = round(max($spark1), 1);
    $max2 = round(max($spark2), 1);
    $min1 = round(min($spark1), 1);
    $min2 = round(min($spark2), 1);
    $avg1 = round(average($spark1), 1);
    $avg2 = round(average($spark2), 1);
    $pcnt25data1 = round(calc_percentile($spark1, 25), 1);
    $pcnt25data2 = round(calc_percentile($spark2, 25), 1);
    $pcnt75data1 = round(calc_percentile($spark1, 75), 1);
    $pcnt75data2 = round(calc_percentile($spark2, 75), 1);
} else {
}
Ejemplo n.º 26
0
/**
 * 将数组b和a做均衡运算,使b最大值和最小值按一并比例缩小到a的最大值和最小值范围内,最后返回均衡之后的数组
 *
 * @param mixed $a
 * @param mixed $b
 * @param mixed $out 传址进来,返回间距和调整的值
 * @return mixed
 */
function equilibria(array $a, array $b, &$out = NULL)
{
    $out = array('difference' => 0, 'adjust' => 0);
    if (empty($a) || empty($b)) {
        return FALSE;
    }
    $max = $min = array();
    $max['a'] = max($a);
    $min['a'] = min($a);
    $max['b'] = max($b);
    $min['b'] = min($b);
    if ($max['a'] == 0 && $min['a'] == 0) {
        return $b;
    }
    if ($max['b'] == 0 && $min['b'] == 0) {
        return FALSE;
    }
    decimal_compare($max['a'], $min['a'], 9) == 0 && ($max['a'] *= 2);
    decimal_compare($max['b'], $min['b'], 9) == 0 && ($max['b'] *= 2);
    $c = array();
    $out['difference'] = ($max['a'] - $min['a']) / ($max['b'] - $min['b']);
    foreach ($b as $key => $value) {
        $c[$key] = $value * $out['difference'];
    }
    $out['adjust'] = average($c) - average($a);
    //需要调整的值
    foreach ($c as $key => $value) {
        $c[$key] = $value - $out['adjust'];
    }
    return $c;
}
Ejemplo n.º 27
0
Archivo: pr1.php Proyecto: k-nish/train
}
echo multiplication(2, 3);
echo '</br>';
//演習問題2
function average($a, $b)
{
    $c = ($a + $b) / 2;
    if ($c >= 10) {
        return $c;
    } else {
        return 0;
    }
}
echo average(16, 10);
echo '</br>';
echo average(2, 4);
echo '</br>';
//演習問題3
function shopping($a, $b)
{
    if ($a < $b) {
        return "お金が足りてません";
    }
    $c = $a - $b;
    return $c;
}
echo shopping(100, 80);
echo '</br>';
echo shopping(40, 60);
echo '</br>';
//演習問題4
$html .= '</thead>';
cliPrint('Starting benchmark');
foreach ($containers as $container) {
    cliPrint('Benchmarking container: ' . $container);
    $html .= '<tr>';
    $html .= '<td>' . $container . '</td>';
    foreach ($objects as $objectcount) {
        $results = [];
        for ($i = 0; $i < $runs; $i++) {
            cliPrint('Benchmarking container: ' . $container . ' with ' . $objectcount * 10 . ' objects run ' . $i . '/' . $runs);
            $t1 = microtime(true);
            for ($j = 0; $j < $iterations; $j++) {
                $output = runScript($container . '/test6a.php', $inis[$container], [$objectcount]);
            }
            $t2 = microtime(true);
            $test = json_decode($output[0]);
            if (!is_object($test)) {
                print_r($output);
            }
            $results[] = $t2 - $t1;
        }
        $result = average($results);
        $html .= '<td>' . ($result - $overhead) . '</td>';
    }
    $html .= '</tr>';
}
if (!$isCli) {
    echo $html;
} else {
    file_put_contents('test6_results.html', $html);
}
Ejemplo n.º 29
0
printPhrase("Silly cat!");
echo "</p><p>";
function greeting($name)
{
    print "Hello, {$name}!";
}
greeting("Scott");
echo "</p><p>";
function average($num1, $num2)
{
    $avg = ($num1 + $num2) / 2;
    return $avg;
}
$a = 5;
$b = 3;
print "The average of {$a} and {$b} is " . average($a, $b);
echo "</p><p>";
function largest($num1, $num2)
{
    if ($num1 > $num2) {
        return $num1;
    } else {
        return $num2;
    }
}
$a = 5;
$b = 3;
print "The largest of {$a} and {$b} is " . largest($a, $b);
echo "</p><p>";
function circumference($radius)
{
Ejemplo n.º 30
0
<?php

$person = ["name" => "Konstantin", "age" => 33, "student" => true, "city" => "Sofia", "grades" => ["Hello", 6, 4, 5, 6, -3]];
//$person['grades'] = implode(', ',$person['grades']);
//foreach ($person as $key => $value) {
//    if (is_string($key)) {
//        echo $key." -> ".$value."\n";
//    }
//}
echo json_encode($person) . "\n";
echo "<pre>", print_r($person, true), "</pre>\n";
arsort($person['grades']);
foreach ($person['grades'] as $key => $value) {
    echo $key . " -> " . $value . "<br/>\n";
}
$str = "How many words do I have?";
echo str_word_count($str);
echo highlight_string('<?php phpinfo(); ?>') . "<br/>";
$str1 = "carrot";
$str2 = "carrrott";
echo levenshtein($str1, $str2);
echo strstr('Hi What!', 'Hi') . "<br/>\n";
$str = "Check the example: Supercalifragulistic";
var_dump(wordwrap($str, 9));
function average()
{
    return array_sum(func_get_args()) / func_num_args();
}
print average(10, 15, 20, 25);
// 17.5