-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestReportSheet.php
executable file
·278 lines (245 loc) · 10.8 KB
/
TestReportSheet.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<?php
require __DIR__.'/vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
// Open the test report spreadsheet and write mpdURL and all error logs.
function string_operations($locate, $mpdURL)
{
global $line_count, $MPD_wrote;
$MPD_wrote = false;
//get all the files wich end as described below
$RepLogFiles=glob($locate."/Period0/*logfull.txt");
$CrossValidDVB=glob($locate."/Period0/*compInfofull.txt");
$CrossRepDASH=glob($locate."/Period0/*CrossInfofilefull.txt");
$all_report_files = array_merge($RepLogFiles, $CrossValidDVB, $CrossRepDASH); // put all the filepaths in a single array
$segment_errors = array();
$xlsx_file = 'TestReport.xlsx'; // the location and name of the report file
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($xlsx_file); //since we create it before hand we read it first and then we write on it
$sheet = $spreadsheet->getActiveSheet();
$highCell= $sheet->getHighestDataRow();
$line_count = 2;//Leave one empty line after each mpd log.
//
//
//
//Start logging with mpd errors, open mpdreport.txt as a file
$mpdReport_temp = file($locate.'/mpdreport.txt', FILE_IGNORE_NEW_LINES); //since with the flag FILE_IGNORE_NEW_LINES we strip all \n from strings the whole string will be in one line
$mpdReport = array();
$mpdReport_errors = array();// this will contain only the errors, wornings or informations
$HbbTV_DVB_info = array(); // this will contain the report on the HbbTV-DVB part
if($mpdReport_temp !== false)
{
for($i = 0; $i < count($mpdReport_temp); $i++)//lets strip unuseful lines from the array
{
if(($mpdReport_temp[$i] != "") && ($mpdReport_temp[$i][0] != "="))
{
$mpdReport[] = $mpdReport_temp[$i];
}
}
for($i = 0; $i < count($mpdReport); $i+=2) //iterate over the lines to do the checking
{
$j = $i + 1;
// processing the line
if($mpdReport[$i] == "Start XLink resolving")
{
if($mpdReport[$j] != "XLink resolving successful")
{
while($j<count($mpdReport)&&($mpdReport[$j] != "Start MPD validation") && ($mpdReport[$j] != "HbbTV-DVB Validation "))
{
$mpdReport_errors[] = $mpdReport[$j];
$j++;
}
}
}
elseif($mpdReport[$i] == "Start MPD validation")
{
if($mpdReport[$j] != "MPD validation successful - DASH is valid!")
{
while($j<count($mpdReport)&&($mpdReport[$j] != "Start Schematron validation") && ($mpdReport[$j] != "HbbTV-DVB Validation "))
{
$mpdReport_errors[] = $mpdReport[$j];
$j++;
}
}
}
elseif($mpdReport[$i] == "Start Schematron validation")
{
if($mpdReport[$j] != "Schematron validation successful - DASH is valid!")
{
while($j<count($mpdReport)&&$mpdReport[$j] != "HbbTV-DVB Validation ")
{
$mpdReport_errors[] = $mpdReport[$j];
$j++;
}
}
}
elseif($mpdReport[$i] == "HbbTV-DVB Validation ")
{
while($j < count($mpdReport))
{
$HbbTV_DVB_info[] = $mpdReport[$j];
$j++;
}
$HbbTV_DVB_info = remove_duplicate_err($HbbTV_DVB_info);
break; // no need to check the rest
}
}
$mpdReport_errors = remove_duplicate_err($mpdReport_errors);
$mpdReport_errors = array_merge( $mpdReport_errors, $HbbTV_DVB_info);
WriteLineToSheet($mpdReport_errors, $sheet, $highCell, 'MPD Report', $mpdURL);
}
else
{
echo "Error opening mpdreport.txt";
}
$currently=file($all_report_files[0],FILE_IGNORE_NEW_LINES);
foreach ($all_report_files as $file_location)
{
$segment_report = file($file_location, FILE_IGNORE_NEW_LINES);
$segment_errors = array_merge($segment_errors, $segment_report);
}
if(!empty($segment_errors)){
WriteLineToSheet($segment_errors, $sheet, $highCell, 'Segment Report', $mpdURL);
}
if($line_count>3){
$sheet->mergeCells('A'.($highCell + 2). ':A'.($highCell+$line_count-1));
$sheet->getColumnDimension('B')->setWidth(200);
$sheet->getColumnDimension('A')->setWidth(80);
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save($xlsx_file);
}else{
$sheet->getColumnDimension('B')->setWidth(200);
$sheet->getColumnDimension('A')->setWidth(80);
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save($xlsx_file);
}
}
function remove_duplicate_err($error_array)
{
$new_array = array();
//since we don't have any \n chars in the str we have the whole error string in one line
for($i = 0; $i < count($error_array); $i++)
{
$new_array[$i] = str_word_count($error_array[$i],1);
$new_array[$i] = implode(" ",$new_array[$i]);
}
//add feature to tell how many times an error was repeated
$count_instances = array_count_values($new_array);
$new_array = array_unique($new_array);
foreach ($new_array as $key => $value)//removing some lines that are not necessary
{
$repetitions = $count_instances[$value];
if((strlen($value) <= 3) || ($value == "Checks completed") || ($value == 'error'))
{
unset($new_array[$key]);
}
else
{
$new_array[$key] = "(".$repetitions.' repetition\s) '.$error_array[$key];
}
}
$last_el = end($new_array);
if(strpos($last_el, 'Cross representation checks for adaptation set with id') !== false)
{
unset($new_array[array_search($last_el,$new_array)]);
}
return $new_array;
}
function WriteLineToSheet($contents,$sheet,$highCell, $type, $mpdURL)
{
global $line_count, $MPD_wrote,$error_counter;
$next = false;
if(count($contents)!=0){
foreach($contents as $line)
{
$sheet->setCellValue('B'.($highCell + $line_count), $line);
$stripped_line = str_word_count($line,1);
if(!$MPD_wrote)
{
$sheet->setCellValue('A'.($highCell + $line_count), $mpdURL);
$sheet->getCell('A'.($highCell + $line_count))->getHyperlink()->setUrl($mpdURL);
$sheet->getStyle('A'.($highCell + $line_count))->getFont()->getColor()->setARGB('FF000000');
$sheet->getStyle('A'.($highCell + $line_count))->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER);
$sheet->getStyle('A'.($highCell + $line_count))->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
!$MPD_wrote = true;
}
if($type == 'MPD Report')//mpd errors will be displayed with a different color from the one of segment errors
{
if($stripped_line!=null){
if(($stripped_line[0] == 'Info') || ($stripped_line[0] =='Information'))
{
$sheet->getStyle('B'.($highCell + $line_count))->getFont()->getColor()->setRGB('0000FF');
}
elseif (($stripped_line[0] == 'Warning') || ($stripped_line[0] =='WARNING'))
{
//$sheet->getStyle('B'.($highCell + $line_count))->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_DARKYELLOW);
$sheet->getStyle('B'.($highCell + $line_count))->getFont()->getColor()->setRGB('FF7F50');
}
else
{
$sheet->getStyle('B'.($highCell + $line_count))->getFont()->getColor()->setRGB('FF0000');
}
}
}
else
{
if($stripped_line!=null){
if(($stripped_line[0] == 'Info') || ($stripped_line[0] =='Information')|| ($next == true))
{
$sheet->getStyle('B'.($highCell + $line_count))->getFont()->getColor()->setRGB('0000FF');
$next = false;
if((substr($line, -1)==":") || (end($stripped_line)== 'with'))
{
$next = true;
}
}
elseif (($stripped_line[0] == 'Warning') || ($stripped_line[0] =='WARNING'))
{
//$sheet->getStyle('B'.($highCell + $line_count))->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_DARKYELLOW);
$sheet->getStyle('B'.($highCell + $line_count))->getFont()->getColor()->setRGB('FF7F50');
}
else
{
foreach($stripped_line as $word){
if($word=="error"){
$error_counter+=1;
}
}
if($error_counter!=0){
$sheet->getStyle('B'.($highCell + $line_count))->getFont()->getColor()->setRGB('DC143C');
}
else{
$sheet->getStyle('B'.($highCell + $line_count))->getFont()->getColor()->setRGB('0000FF');
}
}
}
}
$line_count++;
}
} else{
if(!$MPD_wrote)
{
$sheet->setCellValue('A'.($highCell + $line_count), $mpdURL);
$sheet->setCellValue('B'.($highCell + $line_count), " ");
$sheet->getCell('A'.($highCell + $line_count))->getHyperlink()->setUrl($mpdURL);
$sheet->getStyle('A'.($highCell + $line_count))->getFont()->getColor()->setARGB('FF0000FF');
$sheet->getStyle('A'.($highCell + $line_count))->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER);
$sheet->getStyle('A'.($highCell + $line_count))->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
!$MPD_wrote = true;
}
}
}
function create_initial_spreadsheet() // create an initial spreadsheet and then read from it and write the data
{
if(!file_exists('TestReport.xlsx'))
{
$spreadsheet = new Spreadsheet();
$spreadsheet->setActiveSheetIndex(0)
->setCellValue('B1', 'MPD + Segment Report')
->setCellValue('A1', 'MPD');
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$file_name = 'TestReport.xlsx';
$writer->save($file_name);
}
}
?>