This commit is contained in:
stubbfel
2013-07-10 00:29:59 +02:00
commit f1dc9a54c8
8 changed files with 7947 additions and 0 deletions

54
Cluster.php Normal file
View File

@@ -0,0 +1,54 @@
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of Cluster
*
* @author stubbfel
*/
class Cluster {
private $clusterId;
public $clusterSize;
public $peerClusterRatioNorm;
private $bgColor = "white";
private $range = 0.20;
public function __construct($clusterArray = array(), $clusterId) {
$this->clusterId = $clusterId;
$this->clusterSize = $clusterArray["size"];
}
public function calcPeerClusterRatioNorm($referencePoint) {
$this->peerClusterRatioNorm = $this->clusterSize / $referencePoint;
if ($this->peerClusterRatioNorm - $this->range > 1) {
$this->bgColor = "red";
} elseif ($this->peerClusterRatioNorm + $this->range < 1) {
$this->bgColor = "blue";
} elseif ($this->peerClusterRatioNorm == 1) {
$this->bgColor = "green";
}
}
public function toHTML() {
$table = "<table border=\"1\" width=\"100%\" bgcolor=\"$this->bgColor\"><colgroup width=\"100\" span=\"2\"></colgroup>";
$table .= "<tr>";
$table .= "<td colspan=\"1\">ClusterId:</td><td colspan=\"1\" align=\"center\" >$this->clusterId</td>";
$table .= "</tr>";
$table .= "<tr>";
$table .= "<td>ClusterSize:</td><td align=\"center\" >$this->clusterSize</td>";
$table .= "</tr>";
$table .= "<tr>";
$table .= "<td>PeerClusterRatioNorm:</td><td align=\"center\" >$this->peerClusterRatioNorm</td>";
$table .= "</tr>";
$table .= "</table>";
return $table;
}
}
?>

103
View.php Normal file
View File

@@ -0,0 +1,103 @@
<?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;
}
}
?>

16
index.php Normal file
View File

@@ -0,0 +1,16 @@
<?php
include_once 'View.php';
$sourceString = file_get_contents("mr.json");
//echo $sourceString;
$source = json_decode($sourceString, true);
foreach ($source as $key => $view) {
if ($key != "-1") {
$viewObj = new View($view, $key);
echo $viewObj->toHTML();
echo "<br>";
}
}
?>

7747
mr.json Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
copy.src.files=false
copy.src.on.open=false
copy.src.target=
hostname=localhost
port=8000
run.as=INTERNAL
url=http://localhost:8000/

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
</project-private>

View File

@@ -0,0 +1,7 @@
include.path=${php.global.include.path}
php.version=PHP_54
source.encoding=UTF-8
src.dir=.
tags.asp=false
tags.short=true
web.root=.

9
nbproject/project.xml Normal file
View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.php.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/php-project/1">
<name>MRanalysis</name>
</data>
</configuration>
</project>