Blame view

view/din_fft_detail.html 13 KB
cf76164e6   Ting Chan   20190709
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
  <link rel="stylesheet" href="css/setting-panel.css">
  <link href="js/datatables/css/jquery.dataTables.css" rel="stylesheet">
  <link rel="stylesheet" type="text/css" href="css/select.dataTables.min.css" rel="stylesheet">
  
      <!--[if IE]><script lang="javascript" type="text/javascript" src="../../js/excanvas.js"></script><![endif]-->  				
  <style>
  	tr, td {
  		border: solid 1px #CCC
  	}
  	.chart{
  		
  		
  		width:25%;
  		padding:1px; 
  		margin-right:5px;
  	    margin-top:5%;
  		float:right;
  		margin-bottom:30%;
  	}
  	.chart h1{
  		font-size:16px;
  		font-weight: bold;
  		font-family: monospace;
  	}
  	.fft{
  		width:70%;
  		margin-top:10%;
  		margin-bottom:50%;
  		margin-left:200px;
  		margin-right: 50px;
  		padding: 1px;
  		float: right;
  	}
  	.fft h1{
  		font-size:16px;
  		font-weight: bold;
  		font-family: monospace;
  	}
  	.canvasjs-chart-credit {
     display: none;
  }
  .hidden{
  	display:none;
  }
  
  
  
  </style>
  
  <?php
  $path = "/home/pi/Desktop/vAlert/rec/".$_GET['file'];
  $serial_number=substr($_GET['file'],25,4);
  $datetime=substr($_GET['file'],9,4)."-".substr($_GET['file'],13,2)."-".substr($_GET['file'],15,2)." ".substr($_GET['file'],18,2).":".substr($_GET['file'],20,2).":".substr($_GET['file'],22,2);
  $data_x=array();
  $data_y=array();
  $data_z=array();
  $fft_x=array();
  $fft_y=array();
  $fft_z=array();
  $hold_array=array();
  $sample_rate_array=array();
  $sample_rate=0;
  error_reporting(E_ALL);
  ini_set('display_errors', 1);
  $line=1;
  	if (($handle = fopen($path, "r")) !== FALSE) {
  		$i = 0;
  		 $row=1;
  		  
  		while (($data = fgetcsv($handle, 10000, ",")) !== FALSE) {
  			   $num = $row % 60;
                 if($line>1&& $line<=7)
                 {
                    $fft_z[]=substr($data[0],31,-1);
                    $fft_x[]=$data[1];
                    $fft_y[]=$data[2];
                 }
                 else if($line>7)
                 {
                     
  			    
  			     $sample_rate_array[]=$data[0]; 
  				$data_x[] = $data[2];
  				$data_y[] = $data[3];
  				$data_z[] = $data[1];
  				
  				$i++;
  				
  			       
                 }
  			    
  			
  			$line++;
  			
  		}
  		fclose($handle);
  	}
  
  
  
  $radial=array();
  foreach($data_x as $key=>$value)
  {
  $radial[]="{x:".$key.",y:".$value."}";
  } 
  $vertical=array();
  foreach($data_z as $key=>$value)
  {
  $vertical[]="{x:".$key.",y:".$value."}";
  }
  $transverse=array();
  
  foreach($data_y as $key=>$value)
  {
  $transverse[]="{x:".$key.",y:".$value."}";
  }
  $sample_rate=1/$sample_rate_array[1];
  $total_sample=$line-6;
  $fft_vertical="{x:".$fft_z[4].",y:".$fft_z[3]."}";
  $fft_radial="{x:".$fft_x[4].",y:".$fft_x[3].",markerType:\"triangle\"}";
  $fft_transverse="{x:".$fft_y[4].",y:".$fft_y[3].",markerType:\"square\"}";	
  $logpath="/home/pi/Desktop/vAlert/log/info.txt";
  
  $fp=fopen($logpath,"r");
  $mygps=array();
  while(($buf=stream_get_line($fp,40,"
  "))!==false)
  {
      $mygps[]=$buf;
  }
  
  $location=(isset($mygps[1]))?$mygps[1]:'';
  $displacement_z="{x:".$fft_z[1]." ,y:".$fft_z[2]."}";
  $displacementt_x="{x:".$fft_x[1]." ,y:".$fft_x[2].",markerType:\"triangle\"}";
  $displacement_y="{x:".$fft_y[1]." ,y:".$fft_y[2].",markerType:\"square\"}";
  
  $displacement_max=max($fft_z[2],$fft_x[2],$fft_y[2]);
  
  ?>
  
  <form class="main-form" id="my_query_form">
  
  <h3>DIN EVENT Report <?php echo $datetime; ?>  </h3>
  <button class=" btn btn-primary" style="float: right;padding-top:5px;" id="print_din_fft">Print</button>	
  <fieldset>
  	<div>
  		<font style="font-weight: bold;">Serial Number</font><br>
  		<b><?php echo  $serial_number;?></b><br>
  		<font style="font-weight: bold;">Total samples</font><br>
  		<b><?php echo $total_sample ;?></b>
  		<?php for($i=0;$i<count($mygps)-3;$i++){?>
  		<br>
  		<?php }?>
  
  	</div>          
  </fieldset>
  <fieldset>
  	<div>
  		<font style="font-weight: bold;">Sampling Rate</font><br>
  		<b><?php echo $sample_rate;?></b><br>
  		<font style="font-weight: bold;">Number of channels</font><br>
  		<b>3</b><br>
  		<?php for($i=0;$i<count($mygps)-4;$i++){?>
  		<br>
  		<?php }?>
  	</div>          
  </fieldset>
  <fieldset>
  	<div>
  		<?php
              $size=max(count($mygps),4);
  		 for($i=0;$i<count($mygps);$i++){?>
  		<font style="font-weight: bold;"><?= $mygps[$i]?></font><br>
  		<?php } for($i=0;$i<$size-count($mygps);$i++){?>
  		    <br>
  		    <?php }?>
  	</div>          
  </fieldset>
  
  	<table border="1" id="example" width="100%" class="display" style="text-align:center; border:3px #CCC solid;padding:5px">
  
                     <thead>
  					<tr>
  						<th></th>
  						<th>Channel </th>
  						<th>Vertical</th>
  						<th>Radial</th>
  						<th>Transverse </th>
  						
  					</tr>
  					</thead>
  					<tfoot>
  						<th></th>
  						<th>Channel </th>
  						<th>Vertical</th>
  						<th>Radial</th>
  						<th>Transverse </th>
  						
  					</tr>
  					</tfoot>
  					<tbody>
  					<tr>
  						<td></td>
  						<th>Acceleration(gal)</th>
  						<td><?php echo $fft_z[0];?></td>
  						<td><?php echo $fft_x[0];?></td>
  						<td><?php echo $fft_y[0];?> </td>
  						
  					</tr>
  					<tr>
  						<td></td>
  						<th>Velocity(mm/s) </th>
  						<td><?php echo $fft_z[1];?></td>
  						<td><?php echo $fft_x[1];?> </td>
  						<td><?php echo $fft_y[1];?></td>
  						
  					</tr>
  					<tr><td></td>
  						<th>Displacement(mm)</th>
  						<td><?php echo $fft_z[2]; ?></td>
  						<td><?php echo $fft_x[2];?></td>						
  						<td><?php echo $fft_y[2];?></td>
  					</tr>
  					<tr>
  						<td></td>
  						<th>Frequency(Hz) </th>
  						<td><?php  echo $fft_z[4];?></td>
  						<td><?php echo $fft_x[4];?></td>						
  						<td><?php echo $fft_y[4];?></td>
  						
  					</tr>
  					
  					<tr>
  						<td></td>
  						<th>PPV(mm/s)  </th>
  						<td><?php echo $fft_z[3];?></td>
  						<td><?php echo $fft_x[3];?></td>						
  						<td><?php echo $fft_y[3];?></td>
  						
  					</tr>
  
  			     </tbody>
  		</table>
  
  </form>
  		
        <div class="col s3">
  						
  						<label class="" for="r1"></label>
  					</div>
              
      <div class="chart">
  		<h1>Transverse</h1>
  		
          <div id="chartContainer1"  style="width:90%;"></div>
      </div>
  	<div class="chart">
  		<h1>Radial (<img src="images/arrow.png" width="13px" height="13px">N)</h1>
  		
          <div id="chartContainer2"  style="width:90%;"></div>
      </div>
  
  	<div class="chart" style="margin-left:203px;">
  		<h1>Vertical</h1>
  		
          <div id="chartContainer3"  style="width:90%;"></div>
      </div>
  	<div style="clear:both;"></div>
  	<div class="fft">
          <h1></h1>
          
  		<div id="chartContainer4"  style="width:102%;"></div>
      </div>
  </div>
  <script src="js/canvasjs.min.js"></script>
  	<script src="js/dataTables.bootstrap.min.js"></script>
          <script src="js/jquery-1.12.4.js"></script>
          <script src="assets/plugins/materialize/js/materialize.min.js"></script>
          <script src="assets/plugins/material-preloader/js/materialPreloader.min.js"></script>
  		<script src="assets/js/pages/form_elements.js"></script>
          <script src="assets/js/alpha.js"></script>
  <script src="js/datatables/js/jquery.dataTables.min.js"></script>
  <script type="text/javascript" src="js/dataTables.select.min.js"></script>
    <script type="text/javascript">
  
   $(document).ready(function() {
     var table=$('#example').DataTable( {
      	colReorder: true,
          columnDefs: [ {
              orderable: false,
              className: 'select-checkbox',
              targets:   0,
              checkboxes: {
                 selectRow: true
              },
             
          } ],
  
          select: {
              style:    'multi',
              selector: 'td:first-child'
          },
          order: [[ 1, 'desc' ]]
      } );
     $('.dataTables_length label').addClass('hidden');
       $('#example tbody').on('click', 'tr', function () {
          if ( $(this).hasClass('selected') ) {
              $(this).removeClass('selected');
          }
         
      } );
  
      $("#print_din_fft").click(function(e){
      
      e.preventDefault();
     var rows = table.rows( '.selected' ).indexes();
     var data = table.rows( rows ).data();
  
      var str="";
      for (var i = 0; i < data.length; i++) {
      	str+=data[i].toString();
      }
     window.open("print_din_fft.php?item=din&file=<?php echo $_GET['file'];?>&table="+str,'_blank');
    
  });
  
  } );
  
  	window.onload = function () {
  
  		 setTimeout(function(){
  					$('body').addClass('loaded');
  				}, 1000);
  				setTimeout(function(){
  					$('.loader').fadeOut('400');
  				}, 600);
  
     $(".odd").addClass('selected');
     $(".even").addClass('selected');
  
  	
   
  
  
  		
  		var chart = new CanvasJS.Chart("chartContainer1", {
  			theme: "theme2",//theme1
  			animationEnabled: false,
  			zoomEnabled:true,
  			axisY:{
  				includeZero: false,
  				title: "mm/s"
  			},
  			legend:{
  				verticalAlign: "top",
  				horizontalAlign: "left"
  
  				
  			},
  			data: [              
  			{
  				type: "line",
  				toolTipContent: "YAxis: {y}", 
  				legendMarkerType: "square",
  				showInLegend: true,
  				lineThickness: 2,
  				name: "Y-Axis",
  				markerType: "square",
  				color: "blue",
  				dataPoints: [
  					<?php print_r(implode(",",$transverse)); ?>       
  				]
  			}
  			]
  		});
  		chart.render();
  		
  		var chart2 = new CanvasJS.Chart("chartContainer2", {
  			theme: "theme2",//theme1
  			animationEnabled: false,
  			zoomEnabled:true,
  			axisY:{
  				includeZero: false,
  				title: "mm/s"
  			},
  			legend:{
  				verticalAlign: "top",
  				horizontalAlign: "left"
  			},
  			data: [              
  			{
  				type: "line",
  				showInLegend: true,
  				toolTipContent: "X Axis: {y}",
  				legendMarkerType: "triangle",
  				lineThickness: 2,
  				name: "X-Axis",
  				markerType: "square",
  				color: "red",
  				dataPoints: [<?php print_r(implode(",",$radial)); ?> ]
  			}
  			]
  		});
  		chart2.render();
  		
  		var chart3 = new CanvasJS.Chart("chartContainer3", {
  			theme: "theme2",//theme1
  			animationEnabled: false,
  			zoomEnabled:true,
  			axisY:{
  				includeZero: false,
  				title: "mm/s"
  			},
  			legend:{
  				verticalAlign: "top",
  				horizontalAlign: "left"
  			},
  			data: [              
  			{
  				type: "line",
  				showInLegend: true,
  				toolTipContent: "Z Axis: {y}",
  				lineThickness: 2,
  				name: "Z-Axis",
  				markerType: "square",
  				color: "green",
  				dataPoints: [
  					<?php print_r(implode(",",$vertical)); ?>      
  				]
  			}
  			]
  		});
  		chart3.render();
  
  		var chart4 = new CanvasJS.Chart("chartContainer4", {
  			animationEnabled: false,
  			axisY:{
  				includeZero: false,
  				title: "PPV(mm/s)"
  			},
  			axisY2:{
  				includeZero:false,
  				title:"Displacement(mm)",
  				color:"purple"
  				
  			},
  			axisX:{
  				includeZero: false,
  				title: "Hz"
  			},
  			
  			legend:{
  				verticalAlign: "bottom",
  				horizontalAlign: "center"
  			},
  			data: [              
  			{
  				type: "scatter",
  				showInLegend: true,
  				axisYIndex: 0,
  				color: "green",
  				name:"Vertical PPV",
  				toolTipContent: "Vertical PPV: {y}",
  				dataPoints: [
  					<?php echo $fft_vertical; ?>       
  				]
  			},
  			{
  				type: "scatter",
  				showInLegend: true,
  				axisYIndex: 0,
  				legendMarkerType: "triangle",
  				color: "red",
  				name:"Radial PPV",
  				toolTipContent: "Radial PPV: {y}",
  				dataPoints: [
  					<?php echo $fft_radial; ?>       
  				]
  			},
  			{
  				type: "scatter",
  				showInLegend: true,
  				axisYIndex: 0,
  				color: "blue",
  				legendMarkerType: "square",
  				name:"Transverse PPV",
  				toolTipContent: "Transverse PPV: {y}",
  				dataPoints: [
  					<?php echo $fft_transverse; ?>       
  				]
  			},
  			{
  				type: "scatter",
  				showInLegend: true,
  				axisYType: "secondary",
  				color: "orange",
  				legendMarkerType: "circle",
  				name:"Z-Displacement",
  				toolTipContent: "Z-Displacement: {y},Frequency:{x}",
  				dataPoints: [
  					<?php echo $displacement_z; ?>       
  				]
  			},
  			{
  				type: "scatter",
  				showInLegend: true,
  				
  				color: "black",
  				axisYType: "secondary",
  				legendMarkerType: "triangle",
  				toolTipContent: "X-Displacement: {y},Frequency:{x}",
  				name:"X-Displacement",
  				dataPoints: [
  					<?php echo $displacementt_x; ?>       
  				]
  			},
  			{
  				type: "scatter",
  				showInLegend: true,
  				axisYType: "secondary",
  				color: "purple",
  				legendMarkerType: "square",
  				toolTipContent: "Y-Displacement: {y},Frequency:{x}",
  				name:"Y-Displacement",
  				dataPoints: [
  					<?php echo $displacement_y; ?>       
  				]
  			},
  			
  			{type: "line", 
                   showInLegend: true,
                   color:"black",
                   name: 'Bulding & Commercials',
                   markerSize: 0, 
                   dataPoints: [{x:1,y:20},
                                {x:10,y:20},
                                {x:50,y:40},
                                {x:100,y:50},
                                {x:110,y:50}]},
                   
                   {type: "line", 
                   showInLegend: true,
                   color:"orange",
                   name: 'Dwellings',
                   markerSize: 0, 
                   dataPoints: [{x:1,y:5},
                                {x:10,y:5},
                                {x:50,y:15},
                                {x:100,y:20},
                                {x:110,y:20}]},
                   {type: "line", 
                   showInLegend: true,
                   color:"red",
                   name: 'Preserved Bulding',
                   markerSize: 0, 
                   dataPoints: [{x:1,y:3},
                                {x:10,y:3},
                                {x:50,y:8},
                                {x:100,y:10},
                                {x:110,y:10}]}
  			
  			]
  		});
  		chart4.render();
  
  		
  		
  		
  	}
  </script>
    
      </body>
      </html>