<?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;
    public $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;
    }

}
?>
