/
getClusterModel.php
121 lines (110 loc) · 3.09 KB
/
getClusterModel.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
function __autoload($class_name)
{
include $class_name . ".php";
}
class getClusterModel
{
private $getCluster;
private $data;
private $userid;
private $part;
function __construct()
{
$this->getCluster = filter_input(INPUT_POST, "getParam");
$this->userid = filter_input(INPUT_POST, "userid");
$this->part = 'modelfile/' . $this->userid . '/';
$this->getContent();
}
function loadDataByParam()
{
if ($this->getCluster == "head") {
$this->getHead();
} else if ($this->getCluster == "body") {
$this->getBody();
} else if ($this->getCluster == "footer") {
$this->getFooter();
} else if ($this->getCluster == "full_data") {
echo json_encode($this->data);
}
}
private function getContent()
{
$hfile = fopen($this->part . "temp_model.txt", "r");
while (!feof($hfile)) {
$this->data [] = fgets($hfile);
}
fclose($hfile);
}
private function getHead()
{
$json = array();
$fLine = $this->getFirstLine(20, "Number of iterations");
$endLine = ($this->getEndLine($fLine) - 1);
for ($i = $fLine; $i <= $endLine; $i++) {
$json [] = $this->data [$i];
}
echo json_encode($json);
}
private function getBody()
{
$fLine = ($this->getFirstLine(5, "=====") + 1);
echo "[";
foreach ($this->data as $key => $value) {
if ($key >= $fLine) {
if (strlen($value) <= 1) break;
else {
if ($key < count($this->data) - 1 && $key > $fLine) {
echo ",";
}
}
$mexp = explode(" ", $value);
echo "[";
foreach ($mexp as $k => $v) {
if ($v != "") {
echo json_encode($v);
if ($k < count($mexp) - 1) echo ",";
}
}
echo "]";
}
}
echo "]";
}
private function getFirstLine($glenght, $text)
{
$keyLine = 0;
foreach ($this->data as $key => $value) {
if (trim(substr($value, 0, $glenght)) == $text) {
$keyLine = $key;
}
}
return $keyLine;
}
private function getEndLine($fLine)
{
$keyLine = 0;
foreach ($this->data as $key => $value) {
if ($key >= $fLine && (trim(substr($value, 0, 1)) == "")) {
$keyLine = $key;
break;
}
}
return $keyLine;
}
private function getFooter()
{
$json = array();
foreach ($this->data as $key => $value) {
if ($key >= $this->getFirstLine(19, "Clustered Instances")) {
if (strlen($value) <= 1) {
break;
}
$json[] = $value;
}
}
echo json_encode($json);
}
}
$g = new getClusterModel ();
$g->loadDataByParam();