<?php

include_once 'View.php';

class TestViewSequenz {

    private $viewList = array();
    public $runTime;
    public $lockTime;
    public $msgCount;
    public $name;
    public $path;
    public $lockRunTime;
    public $lockTimeMsgCount;

    public function __construct($testFile = null) {
        if (!$testFile) {
            return;
        }
        $this->path = $testFile;
        $sourceString = file_get_contents($testFile);

        $source = json_decode($sourceString, true);

        foreach ($source as $key => $view) {
            if ($key != "-1" && is_numeric($key) == TRUE) {
                $viewObj = new View($view, $key);
                array_push($this->viewList, $viewObj);
            }
        }

        if (array_key_exists("runtime", $source)) {
            $this->runTime = $source["runtime"];
        }

        if (array_key_exists("locktime", $source)) {
            $this->lockTime = $source["locktime"];
        }

        if (array_key_exists("msgcount", $source)) {
            $this->msgCount = $source["msgcount"];
        }
        
        $this->name = str_replace(".json", "", basename($testFile));
        $this->lockRunTime = $this->lockTime / $this->runTime;
        $this->lockTimeMsgCount = $this->lockTime / $this->msgCount;
    }

    public function toHTML() {
        $result = "<table border=\"1\" width=\"100%\"><tr><td>Runtitme:</td><td>$this->runTime</td><td>LockTime</td><td>$this->lockTime</td><td>MsgCount:</td><td>$this->msgCount</td></tr></table>";
        foreach ($this->viewList as $value) {
            $result .= $value->toHTML();
        }
        return $result;
    }

}

?>
