File: C:/xampp/htdocs/FograCT1/ParseSSI.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Gray finder Check</title>
<style type="text/css">
<!--
body {
font: 100% Verdana, Arial, Helvetica, sans-serif;
background: #ffffff;
margin: 0; /* 比較好的做法是將 Body 元素的邊界與欄位間隔調整為零,以處理不同的瀏覽器預設值 */
padding: 0;
text-align: center; /* 這樣會讓容器在 IE 5* 瀏覽器內置中對齊。然後,文字會在 #container 選取器中設定為靠左對齊預設值 */
color: #000000;
}
.oneColElsCtr #container {
width: 46em;
background: #FFFFFF;
margin: 0 auto; /* 自動邊界 (搭配寬度) 會讓頁面置中對齊 */
border: 0px solid #000000;
text-align: left; /* 這樣做會覆寫 Body 元素上的 text-align: center。 */
}
.oneColElsCtr #mainContent {
padding: 0 20px; /* 請記住,欄位間隔就是 Div 方塊內部的空間,而邊界就是 Div 方塊外部的空間 */
}
-->
</style></head>
<body class="oneColElsCtr">
<?php
$servername = "127.0.0.1";
$username = "root";
$password = "fredsql";
$DBNAME = "tvicheck-st";
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//echo "Connected successfully";
if( !mysqli_select_db($conn, $DBNAME)) {
die ("無法選擇資料庫");
}
mysqli_query( $conn, "SET NAMES 'utf8'");
//error_reporting(0);
$company=$_GET['company'];
$light=$_GET["fileLT"];
echo "Light:".$light;
$contents = file("upload/".$light);
$string = implode($contents);
$dot = explode("\t", $string);
//print_r($dot);
$snstring=$dot[0];
echo "sn:".$snstring;
//echo "<br>xy:".$dot[1].",".$dot[2];
$n=($dot[1]-0.332)/($dot[2]-0.1858);
$Lux=$dot[3];
$cct= (-449*pow($n,3)) + (3525*pow($n,2)) - 6823.3*$n + 5520.33;
$cct=round($cct,0);
echo "<br>CCT:".$cct.",__Lux=".$Lux;
$dtime=time();
$dStr=substr($dtime,7,9);
$myFile ="data.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
//fwrite($fh, $p);
$viHead=$dot[4]." ".$dot[5]." ".$dot[6]." ".$dot[7]." ".$dot[8]." ".$dot[9]." ".$dot[10]." ".$dot[11]." ".$dot[12]." ".$dot[13]." ".$dot[14]." ".$dot[15]." ".$dot[16]." ".$dot[17]." ".$dot[18]." ".$dot[19]." ".$dot[20]." ".$dot[21]." ".$dot[22]." ".$dot[23]." ".$dot[24]." ".$dot[25]." ".$dot[26]." ".$dot[27]." ".$dot[28]." ".$dot[29]." ".$dot[30]." ".$dot[31]." ".$dot[32]." ".$dot[33]." ".$dot[34]." ".$dot[35]." ".$dot[36]." ".$dot[37]." ".$dot[38]." ".$dot[39];
fwrite($fh, $viHead);
fclose($fh);
//sleep(0.5);
exec('echo . | "C:\Program Files\R\R-4.4.0\bin\Rscript" appi1MxNoUi.R');
//sleep(1);
$ssiFile = file("output.txt");
$SSI = implode($ssiFile);
echo $SSI;
?>
<table width="300" border="1" align="center">
<tr>
<td bgcolor="#cccccc"> CCT:</td><td><?php echo $cct;?></td><td bgcolor="#cccccc">Lux</td><td><?php echo $Lux;?></td></td></td>
</tr>
<tr>
<td bgcolor="#cccccc"> SSI:</td><td><?php echo $SSI;?></td>
</tr>
</table>
<?php
$contentD = file("D50data.txt");
$stringD = implode($contentD);
$dotT = explode("\t", $stringD);
//print_r($dot);
unlink('splineL.png');
require_once ('../jpgraph/jpgraph.php');
require_once ('../jpgraph/jpgraph_line.php');
require_once ('../jpgraph/jpgraph_scatter.php');
require_once ('../jpgraph/jpgraph_mgraph.php');
require_once ('../jpgraph/jpgraph_regstat.php');
//echo "dot39:". floatval($dot[39]);
//print_r($dotT);
$xdata = array(380,390,400,410,420,430,440,450,460,470,480,490,500,510,520,530,540,550,560,570,580,590,600,610,620,630,640,650,660,670,680,690,700,710,720,730);
$ydata = array($dot[4]/$dot[22],$dot[5]/$dot[22],$dot[6]/$dot[22],$dot[7]/$dot[22],$dot[8]/$dot[22],$dot[9]/$dot[22],$dot[10]/$dot[22],$dot[11]/$dot[22],$dot[12]/$dot[22],$dot[13]/$dot[22],$dot[14]/$dot[22],$dot[15]/$dot[22],$dot[16]/$dot[22],$dot[17]/$dot[22],$dot[18]/$dot[22],$dot[19]/$dot[22],$dot[20]/$dot[22],$dot[21]/$dot[22],$dot[22]/$dot[22],$dot[23]/$dot[22],$dot[24]/$dot[22],$dot[25]/$dot[22],$dot[26]/$dot[22],$dot[27]/$dot[22],$dot[28]/$dot[22],$dot[29]/$dot[22],$dot[30]/$dot[22],$dot[31]/$dot[22],$dot[32]/$dot[22],$dot[33]/$dot[22],$dot[34]/$dot[22],$dot[35]/$dot[22],$dot[36]/$dot[22],$dot[37]/$dot[22],$dot[38]/$dot[22], floatval($dot[39])/$dot[22]);
$xdata2 = array(380,390,400,410,420,430,440,450,460,470,480,490,500,510,520,530,540,550,560,570,580,590,600,610,620,630,640,650,660,670,680,690,700,710,720,730);
$ydata2 = array($dotT[0],$dotT[1],$dotT[2], floatval($dotT[3]),$dotT[4],$dotT[5],$dotT[6],$dotT[7],$dotT[8],$dotT[9],$dotT[10],$dotT[11],$dotT[12],$dotT[13],$dotT[14],$dotT[15],$dotT[16],$dotT[17],$dotT[18],$dotT[19],$dotT[20],$dotT[21],$dotT[22],$dotT[23],$dotT[24],$dotT[25],$dotT[26],$dotT[27],$dotT[28],$dotT[29],$dotT[30],$dotT[31],$dotT[32],$dotT[33],$dotT[34],floatval($dotT[35]));
// Get the interpolated values by creating
// a new Spline object.
$spline = new Spline($xdata,$ydata);
$spline2 = new Spline($xdata2,$ydata2);
// For the new data set we want 40 points to
// get a smooth curve.
list($newx,$newy) = $spline->Get(50);
list($newx2,$newy2) = $spline2->Get(50);
//echo "<br>nex2:".$newx2;
//print_r($newx2);
// Create the graph
$g = new Graph(380,250);
$g->SetMargin(30,20,40,30);
//$g->title->Set("Curve C");
$g->title->SetFont(FF_ARIAL,FS_NORMAL,12);
$g->subtitle->Set('Test in Green (D50 in Blue)');
//$g->subtitle->SetColor('darkred');
$g->SetMarginColor('lightgreen');
//$g->img->SetAntiAliasing();
// We need a linlin scale since we provide both
// x and y coordinates for the data points.
$g->SetScale('linlin');
// We want 1 decimal for the X-label
$g->xaxis->SetLabelFormat('%1.1f');
// We use a scatterplot to illustrate the original
// contro points.
$splot = new ScatterPlot($ydata,$xdata);
$splot2 = new ScatterPlot($ydata2,$xdata2);
//
$splot->mark->SetFillColor('[email protected]');
$splot->mark->SetColor('[email protected]');
$splot2->mark->SetFillColor('[email protected]');
$splot2->mark->SetColor('[email protected]');
// And a line plot to stroke the smooth curve we got
// from the original control points
$lplot = new LinePlot($newy,$newx);
$g->Add($lplot);
$lplot->SetColor('darkgreen');
$lplot2 = new LinePlot($newy2,$newx2);
$g->Add($lplot2);
$lplot2->SetColor('[email protected]');
$g->Add($splot);
$g->Add($splot2);
$g->Stroke('splineL.png');
?>
<table border="1" align='center'>
<tr>
<td><img src="splineL.png?nocache=<?php echo time(); ?>"></td>
</tr>
</table>
<?php
//$filedb=substr($light,7,60);
$dbstr=explode("-", $light);
//echo $dbstr[0]."XX".$dbstr[1];
$filename=$light;
//echo "file:".$filename;
$po=$dbstr[0];
//echo "po:".$po;
$sqName="";
$querys = "select po, filename from lightDB where po='$po' and company='$company' ORDER BY id DESC LIMIT 1 ";
//echo "sql:".$querys;
$results = mysqli_query($conn, $querys);
$num = mysqli_num_rows( $results);
//$obj = mysqli_fetch_object($results);
if ($num > 0)
{
$row = mysqli_fetch_object($results);
$sqName=$row->filename;}
//echo "sqName:".$sqName;
if ($sqName<>$filename) {
echo "data insterted!";
// generate and execute query
$query = "INSERT INTO lightDB (company, po, sn, filename, CCT, Lux, SSI, ddate) VALUES('$company', '$po','$snstring', '$filename','$cct','$Lux', '$SSI', NOW())";
//echo $query;
//$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
$results = mysqli_query($conn, $query);
}
mysqli_close($conn);
?>
<br>
<tr><td>
<a href="rankLight.php?company=<?php echo $company;?>">List.</a>
</td></tr>
<br>
<tr>
<td align="center"><font size="-2"> © <a href="mailto:[email protected]">Fred Kuo</a>, 2024. All rights reserved.<br><a href="http://www.pbn.com.tw/wordpress">Read more.</a><br>
</td>
</tr>
</body>
</html>