Files
kopalnia_2014/sites/site203inf_xy_formula.php
2026-09-03 11:24:19 +02:00

127 lines
3.8 KiB
PHP

<?php
mysql_query("DELETE FROM seg_pumps_xy_formula WHERE PUF_PUP_ID=".$_GET['pup']);
// dla H
$i=0; $j=0;
$wynik = mysql_query("select PEP_X_PARAM,PEP_Y_PARAM from seg_pump_eng_param where PEP_TYPE='H' and PEP_PUP_ID=".$_GET['pup']." order by PEP_X_PARAM");
if($wynik)while ($r = mysql_fetch_array($wynik))
{
$newParam[$i][$j] = $r["PEP_X_PARAM"];
$j++;
$newParam[$i][$j] = $r["PEP_Y_PARAM"];
$i++; $j=0;
}
$data = $newParam;
bcscale( 10 );
$polynomialRegression = new PolynomialRegression( 4 );
foreach ( $data as $dataPoint )
$polynomialRegression->addData( $dataPoint[ 0 ], $dataPoint[ 1 ] );
$coefficients = $polynomialRegression->getCoefficients();
$functionText = "";
foreach ( $coefficients as $power => $coefficient )
{
if ( $power > 0 )
$functionText .= "#+";
$functionText .= round( $coefficient, 20 );
if ( $power > 0 )
{
$functionText .= "x";
if ( $power > 1 )
$functionText .= "^" . $power;
}
}
$functionText = str_replace('+-', '-', $functionText);
$fx_parameters= $functionText;
$functionText = str_replace('#', '', $functionText);
$d = strtok($fx_parameters, '#');
$c = strtok('#');
$b = strtok('#');
$a = strtok('#');
$a = str_replace('x^3','',$a); $a = str_replace('+','',$a);
$b = str_replace('x^2','',$b); $b = str_replace('+','',$b);
$c = str_replace('x','',$c); $c = str_replace('+','',$c);
$d = str_replace('+','',$d);
mysql_query("INSERT INTO seg_pumps_xy_formula SET PUF_PUP_ID=".$_GET['pup'].",PUF_XY_FORMULA='y = $functionText',PUF_A='$a',PUF_B='$b',PUF_C='$c',PUF_D='$d',PUF_TYPE='H'");
// Place text
unset($data);
unset($newParam);
unset($dataPoint);
unset($power);
unset($coefficients);
unset($functionText);
unset($fx_parameters);
unset($polynomialRegression);
// dla ETA
$i=0; $j=0;
$wynik = mysql_query("select PEP_X_PARAM,PEP_Y_PARAM from seg_pump_eng_param where PEP_TYPE='ETA' and PEP_PUP_ID=".$_GET['pup']." order by PEP_X_PARAM");
if($wynik)while ($r = mysql_fetch_array($wynik))
{
$newParam[$i][$j] = $r["PEP_X_PARAM"];
$j++;
$newParam[$i][$j] = $r["PEP_Y_PARAM"];
$i++; $j=0;
}
$data = $newParam;
bcscale( 10 );
// Symulacja żeby sprawność wykreślała parabole x^2
// $polynomialRegression = new PolynomialRegression( 3 );
$polynomialRegression = new PolynomialRegression( 4 );
foreach ( $data as $dataPoint )
$polynomialRegression->addData( $dataPoint[ 0 ], $dataPoint[ 1 ] );
$coefficients = $polynomialRegression->getCoefficients();
$functionText = "";
foreach ( $coefficients as $power => $coefficient )
{
if ( $power > 0 )
$functionText .= "#+";
$functionText .= round( $coefficient, 20 );
if ( $power > 0 )
{
$functionText .= "x";
if ( $power > 1 )
$functionText .= "^" . $power;
}
}
$functionText = str_replace('+-', '-', $functionText);
$fx_parameters= $functionText;
$functionText = str_replace('#', '', $functionText);
$d = strtok($fx_parameters, '#');
$c = strtok('#');
$b = strtok('#');
$a = strtok('#');
$a = str_replace('x^3','',$a); $a = str_replace('+','',$a);
$b = str_replace('x^2','',$b); $b = str_replace('+','',$b);
$c = str_replace('x','',$c); $c = str_replace('+','',$c);
$d = str_replace('+','',$d);
mysql_query("INSERT INTO seg_pumps_xy_formula SET PUF_PUP_ID=".$_GET['pup'].",PUF_XY_FORMULA='y = $functionText',PUF_A='$a',PUF_B='$b',PUF_C='$c',PUF_D='$d',PUF_TYPE='ETA'");
// Place text
unset($data);
unset($newParam);
unset($dataPoint);
unset($power);
unset($coefficients);
unset($functionText);
unset($fx_parameters);
unset($polynomialRegression);
?>