TimingStatistics: Scanning timing and statistics.
This commit is contained in:
@@ -9,6 +9,8 @@ include_once "scanner.php";
|
|||||||
include_once "multilang.php";
|
include_once "multilang.php";
|
||||||
MultiLang::LoadFile("ui");
|
MultiLang::LoadFile("ui");
|
||||||
|
|
||||||
|
include_once "timingStatistics.php";
|
||||||
|
$timings=new TimingStatistics();
|
||||||
|
|
||||||
function RenderDocument($filePath){
|
function RenderDocument($filePath){
|
||||||
$render="";
|
$render="";
|
||||||
@@ -45,9 +47,12 @@ $Size=RequestParm("ddlSize",$Size);
|
|||||||
$Crop=RequestParm("chkCrop",$Crop)!=false;
|
$Crop=RequestParm("chkCrop",$Crop)!=false;
|
||||||
$CropFuzz=RequestParm("txtCropFuzz",$CropFuzz);
|
$CropFuzz=RequestParm("txtCropFuzz",$CropFuzz);
|
||||||
|
|
||||||
|
$CurrentKey=$Scanner["ScanDevice"]."_".$Resolution."_".$Format."_".$Size;
|
||||||
|
|
||||||
// Preprocess
|
// Preprocess
|
||||||
$DestFile=null;
|
$DestFile=null;
|
||||||
if(RequestParm("btnScan",false)){
|
if(RequestParm("btnScan",false)){
|
||||||
|
$timeThen=time()+microtime();
|
||||||
CleanUp();
|
CleanUp();
|
||||||
$baseName="Scan-".date("Y-m-d_H_i_s");
|
$baseName="Scan-".date("Y-m-d_H_i_s");
|
||||||
$DestFile=Scan($Scanner["ScanDevice"],$Resolution,$Format,$Size,$baseName);
|
$DestFile=Scan($Scanner["ScanDevice"],$Resolution,$Format,$Size,$baseName);
|
||||||
@@ -55,8 +60,17 @@ if(RequestParm("btnScan",false)){
|
|||||||
CropImage($DestFile);
|
CropImage($DestFile);
|
||||||
}
|
}
|
||||||
MoveToDest($DestFile);
|
MoveToDest($DestFile);
|
||||||
|
$timeNow=time()+microtime();
|
||||||
|
$timings->RegisterTiming($CurrentKey,$timeNow-$timeThen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pass the JSON object of timings to client
|
||||||
|
echo "<script>\n";
|
||||||
|
echo "var timings=";
|
||||||
|
echo json_encode($timings->GetTimingsAverage(),JSON_PRETTY_PRINT);
|
||||||
|
echo ";\n";
|
||||||
|
echo "</script>\n";
|
||||||
|
|
||||||
// Render Form
|
// Render Form
|
||||||
$formFields="";
|
$formFields="";
|
||||||
$formFields.=RenderFieldInfo(MultiLang::GetString("Scanner"),$Scanner["ScanModel"]);
|
$formFields.=RenderFieldInfo(MultiLang::GetString("Scanner"),$Scanner["ScanModel"]);
|
||||||
|
|||||||
62
code/timingStatistics.php
Normal file
62
code/timingStatistics.php
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class TimingStatistics{
|
||||||
|
private $filename="temp/timingStatistics.json";
|
||||||
|
private $values=null;
|
||||||
|
|
||||||
|
private function InitValues(){
|
||||||
|
$this->values=array();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function LoadValues(){
|
||||||
|
if($this->values!=null){return;}
|
||||||
|
if(!is_file($this->filename)){
|
||||||
|
$this->InitValues();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$overviewContents=@file_get_contents($this->filename);
|
||||||
|
if($overviewContents===false){
|
||||||
|
$this->InitValues();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->values=json_decode($overviewContents,true);
|
||||||
|
if($this->values==null){
|
||||||
|
$this->InitValues();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function SaveValues(){
|
||||||
|
if($this->values==null){return;}
|
||||||
|
|
||||||
|
$valuesContent=json_encode($this->values,JSON_PRETTY_PRINT);
|
||||||
|
file_put_contents($this->filename,$valuesContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function RegisterTiming($keyName,$time){
|
||||||
|
$this->LoadValues();
|
||||||
|
if(isset($this->values[$keyName])==false){
|
||||||
|
$this->values[$keyName]=array();
|
||||||
|
}
|
||||||
|
$this->values[$keyName][]=$time;
|
||||||
|
if(count($this->values[$keyName])>5){
|
||||||
|
unset($this->values[$keyName][0]);
|
||||||
|
}
|
||||||
|
$this->SaveValues();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function GetTimingsAverage(){
|
||||||
|
$this->LoadValues();
|
||||||
|
$result=array();
|
||||||
|
foreach ($this->values as $key => $value) {
|
||||||
|
$totalTime=0;
|
||||||
|
$totalCount=0;
|
||||||
|
foreach ($value as $time) {
|
||||||
|
$totalTime=$totalTime+$time;
|
||||||
|
$totalCount=$totalCount+1;
|
||||||
|
}
|
||||||
|
$result[$key]=($totalTime/$totalCount);
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user