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

152 lines
4.4 KiB
PHP

<?php
// Load the polynomial regression class.
require_once('./polynomial/PolynomialRegression.php' );
date_default_timezone_set('Europe/Warsaw');
require_once("func.php");
require_once("dbaccess.php");
$polacz = mysql_connect($db_host, $db_user, $db_user_pass) or die ('cannot connect to db');
mysql_select_db($db_name);
mysql_query("SET NAMES utf8");
mysql_query("SET CHARACTER_SET utf8_general_ci");
mysql_query("truncate table seg_pumps_xy_formula");
$wynik = mysql_query("select distinct PEP_PUP_ID from seg_pump_eng_param order by PEP_PUP_ID");
if($wynik)while ($r = mysql_fetch_array($wynik))
{
$pupID[] = $r["PEP_PUP_ID"];
}
foreach ( $pupID as $value )
{
// 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=".$value." 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=$value,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=".$value." 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=$value,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);
}
echo"Funkcje dla poszczególnych pomp przeliczone, dane zaczytane do tabeli <b>seg_pumps_xy_formula</b> <br/>";
mysql_close($polacz);
?>