Files
Mranalysis/View.php
stubbfel f1dc9a54c8 init
2013-07-10 00:29:59 +02:00

104 lines
3.6 KiB
PHP

<?php
include_once 'Cluster.php';
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of View
*
* @author stubbfel
*/
class View {
private $viewArray;
private $clusterCount;
private $peerCount;
private $viewId;
private $peerClusterRatioRef;
private $peerClusterRatioNormVar;
private $peerClusterRatioNormStDev;
private $peerClusterRatioNormMed;
private $clusterList;
public function __construct($viewArray = array(), $viewId) {
$this->viewArray = $viewArray;
$this->clusterCount = $this->viewArray["cn"];
$this->peerCount = $this->viewArray["pn"];
$this->viewId = $viewId;
$this->createClusterList();
$this->calcPeerClusterRatio();
}
private function createClusterList() {
$clusterArray = $this->viewArray["clusters"];
$this->clusterList = array();
foreach ($clusterArray as $key => $value) {
$cluster = new Cluster($value, $key);
array_push($this->clusterList, $cluster);
}
}
private function clusterListToHTML() {
$result = "<table width=\"100%\">";
foreach ($this->clusterList as $value) {
$result .= "<tr><td>";
$result .= $value->toHTML();
$result .= "</td></tr>";
}
return $result . "</table>";
}
private function calcPeerClusterRatio() {
$this->peerClusterRatioRef = round($this->peerCount / $this->clusterCount,5);
$variance = 0.0;
$medianArray = array();
foreach ($this->clusterList as $value) {
$value->calcPeerClusterRatioNorm($this->peerClusterRatioRef);
$variance += pow($value->clusterSize - $this->peerClusterRatioRef, 2);
array_push($medianArray, $value->clusterSize);
}
$variance /= $this->peerCount;
$this->peerClusterRatioNormVar = round($variance,5);
$this->peerClusterRatioNormStDev = round(sqrt($variance),5);
asort($medianArray);
$medianArraySize = count($medianArray);
$medianMidIndex = round(($medianArraySize - 1) / 2,0,PHP_ROUND_HALF_DOWN);
if ($medianArraySize % 2 == 0) {
$this->peerClusterRatioNormMed = ($medianArray[$medianMidIndex] + $medianArray[$medianMidIndex + 1]) / 2;
} else {
$this->peerClusterRatioNormMed = $medianArray[$medianMidIndex];
}
}
public function toHTML() {
$table = "<table border=\"1\"><colgroup width=\"100\" span=\"8\"></colgroup>";
$table .= "<tr>";
$table .= "<th colspan=\"4\">ViewId:</th><th colspan=\"4\">$this->viewId</th>";
$table .= "</tr>";
$table .= "<tr>";
$table .= "<td colspan=\"2\">ClusterCount:</td><td colspan=\"2\" align=\"center\" >$this->clusterCount</td>";
$table .= "<td colspan=\"2\">PeerCount:</td><td colspan=\"2\" align=\"center\" >$this->peerCount</td>";
$table .= "</tr>";
$table .= "<tr>";
$table .= "<td>PeerClusterRatioRef:</td><td align=\"center\" >$this->peerClusterRatioRef </td>";
$table .= "<td>PeerClusterRatioNormVar:</td><td align=\"center\" >$this->peerClusterRatioNormVar</td>";
$table .= "<td>PeerClusterRatioNormStDev:</td><td align=\"center\" >$this->peerClusterRatioNormStDev</td>";
$table .= "<td>PeerClusterRatioNormMed:</td><td align=\"center\" >$this->peerClusterRatioNormMed</td>";
$table .= "</tr>";
$table .= "<tr><td>ClusterListe:</td> <td colspan=\"7\">";
$table .= $this->clusterListToHTML();
$table .= "</td></tr>";
$table .= "</table>";
return $table;
}
}
?>