-
Notifications
You must be signed in to change notification settings - Fork 0
/
voltagecharts.php
201 lines (140 loc) · 4.69 KB
/
voltagecharts.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<html>
<head>
<style type="text/css">
th,td {
border: 1px solid #000;
}
</style>
</head>
<body>
<?php
$dg = $_GET['dg']; $case = $_GET['case'];
$title = $dg;
//testCases
//14
$InterestBuses14 = array(6,7,8,9,10,11,12,13,14);
//33
$InterestBuses33 = array(6,18,33);
//folders
//pv
$foldersPV = array("0.5MW PV", "1MW PV", "2MW PV", "4MW PV");
//wind
$foldersWind = array("1.65MW WIND", "2MW WIND", "3MW WIND");
$InterestBuses = ($case == 14) ? $InterestBuses14 : $InterestBuses33;
$folders = ($dg == "PV") ? $foldersPV : $foldersWind;
$output = array();
foreach ($folders as $k=>$folder){
$output[$folder] = array();
}
//ARRAY KEYS ARE FOLDER NAMES
//FOLDER NAMES ARE COLUMN HEADERS
//INTEREST BUSES ARE ROW LEADERS
//file names
//each file contains all the bus voltages of all buses when the DG is connected to that bus
function fillData($f, $startRow, $endRow){
$row = 1; global $InterestBuses; global $case; $dgref = array();
//$datafile =
if (($handle = fopen($f, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE ) {
//only row 2-17 for 14 bus
$row++;
if(($row > $startRow && $row < $endRow) && $data[9] != ""){
$nodename = substr($data[1], 0, strpos($data[1]," "));
if($case == 33 && (substr($data[1], 0, strpos($data[1]," ")) == "BUS") ){
$nodename = "B" . substr($data[1], 4, 1); // convert BUS 2 .. to B2
}
$nodeNum = ($case == 14) ? (substr($nodename, 4)) : (substr($nodename, 1)); //BUS_X for 14, BX FOR 33
$nodeNum = $nodeNum + 0;
$nodeVoltagePU = $data[10];
$nodeVoltageKV = $data[11];
if(in_array($nodeNum, $InterestBuses) && $case == 14){
//only store data for buses we are interested in
$dgref[ $nodeNum ] = array($nodeVoltagePU + 0, $nodeVoltageKV + 0); // +0 to make float
}else{
//read all for 33 bus
$dgref[ $nodeNum ] = array($nodeVoltagePU + 0, $nodeVoltageKV + 0); // +0 to make float
}
}// if row > start row
}
fclose($handle);
}
ksort($dgref);
return $dgref;
} //fill data
?>
<?php
foreach($output as $folder=>$fdata){
//$fdata is an array to hold
//scan through each file and read its data using buses
foreach($InterestBuses as $k=>$bus){
$path = "data/". $case . "/" . $folder . "/" . $bus . ".rlf";
if($case == 33){
$upperlimit = $case + 4;
}else{
$upperlimit = $case + (($dg == "PV") ? 3 : 4); //wind 14 has a small glitch: an element in the middle of the list
}
$fdata[$bus] = fillData($path, 2, $upperlimit); // replace 6.rlf with file full ref
}//scan through files
$output[$folder] = $fdata;
}// scan through folders
//var_dump($output);
?>
<?php
//create tables
function display(){
global $InterestBuses;
global $folders;
global $output;
global $case;
foreach($InterestBuses as $k=>$bus){
echo "<h2>DG at Bus " . $bus . "</h2>";
//build table
$html = '';
$html .= '<table>'
. '<thead>'
. '<tr>'
. '<th></th>';//spacer
//headers
//PU headers
foreach($folders as $fk => $dg){
$html .= '<th>' . $dg . '(u%)</th>';
}
// KV headers
foreach($folders as $fk => $dg){
$html .= '<th>' . $dg . '(kV)</th>';
}
$html .= '</tr>'
. '</thead>'
. '<tbody>';
//
if($case == 14){
$loopBuses = $InterestBuses;
}elseif($case == 33){
//
$loopBuses = array();
for($i = 1; $i<34; $i++){
array_push($loopBuses, $i);
}
}
foreach($loopBuses as $kk => $bb){
$html .= '<tr>';
$html .= '<td>' . $bb . '</td>'; //bus number as row leader
foreach($folders as $fk => $dg){
$html .= '<td>' . $output[$dg][$bus][$bb][0] . '</td>'; // key 0 is the voltagePU
}
//repeat for voltage KV
foreach($folders as $fk => $dg){
$html .= '<td>' . $output[$dg][$bus][$bb][1] . '</td>'; // key 1 is the voltageKV
}
$html .= '</tr>';
}
$html .= '</tbody>'
. '</table>';
echo $html;
}
}
?>
<h1><?php echo $title;?></h1>
<?php display(); ?>
</body>
</html>