fixes, spline interpolation added

This commit is contained in:
Dennis Eichhorn 2019-10-16 17:35:10 +02:00
parent 479facee52
commit 7c71b023c7
421 changed files with 1157 additions and 591 deletions

View File

@ -268,7 +268,7 @@ class Builder extends BuilderAbstract
$this->type = QueryType::SELECT; $this->type = QueryType::SELECT;
foreach ($columns as $key => $column) { foreach ($columns as $key => $column) {
if (\is_string($column) || $column instanceof \Closure) { if (\is_string($column) || $column instanceof self || $column instanceof \Closure) {
$this->selects[] = $column; $this->selects[] = $column;
} else { } else {
throw new \InvalidArgumentException(); throw new \InvalidArgumentException();
@ -395,12 +395,14 @@ class Builder extends BuilderAbstract
* *
* @since 1.0.0 * @since 1.0.0
*/ */
private function isValidReadOnly($raw) : bool private function isValidReadOnly(string $raw) : bool
{ {
if (!$this->isReadOnly) { if (!$this->isReadOnly) {
return true; return true;
} }
$raw = \strtolower($raw);
if (\stripos($raw, 'insert') !== false if (\stripos($raw, 'insert') !== false
|| \stripos($raw, 'update') !== false || \stripos($raw, 'update') !== false
|| \stripos($raw, 'drop') !== false || \stripos($raw, 'drop') !== false
@ -414,22 +416,6 @@ class Builder extends BuilderAbstract
return true; return true;
} }
/**
* Make raw column selection.
*
* @param \Closure|string $expression Raw expression
*
* @return Builder
*
* @since 1.0.0
*/
public function selectRaw($expression) : self
{
$this->selects[null][] = $expression;
return $this;
}
/** /**
* Is distinct. * Is distinct.
* *
@ -456,7 +442,7 @@ class Builder extends BuilderAbstract
public function from(...$tables) : self public function from(...$tables) : self
{ {
foreach ($tables as $key => $table) { foreach ($tables as $key => $table) {
if (\is_string($table) || $table instanceof \Closure) { if (\is_string($table) || $table instanceof self || $table instanceof \Closure) {
$this->from[] = $table; $this->from[] = $table;
} else { } else {
throw new \InvalidArgumentException(); throw new \InvalidArgumentException();
@ -483,22 +469,6 @@ class Builder extends BuilderAbstract
return $this; return $this;
} }
/**
* Make raw from.
*
* @param array|\Closure|string $expression Expression
*
* @return Builder
*
* @since 1.0.0
*/
public function fromRaw($expression) : self
{
$this->from[null][] = $expression;
return $this;
}
/** /**
* Where. * Where.
* *
@ -654,7 +624,7 @@ class Builder extends BuilderAbstract
public function groupBy(...$columns) : self public function groupBy(...$columns) : self
{ {
foreach ($columns as $key => $column) { foreach ($columns as $key => $column) {
if (\is_string($column) || $column instanceof \Closure) { if (\is_string($column) || $column instanceof self || $column instanceof \Closure) {
$this->groups[] = $column; $this->groups[] = $column;
} else { } else {
throw new \InvalidArgumentException(); throw new \InvalidArgumentException();
@ -1032,7 +1002,7 @@ class Builder extends BuilderAbstract
$this->type = QueryType::UPDATE; $this->type = QueryType::UPDATE;
foreach ($tables as $key => $table) { foreach ($tables as $key => $table) {
if (\is_string($table) || $table instanceof \Closure) { if (\is_string($table) || $table instanceof self || $table instanceof \Closure) {
$this->updates[] = $table; $this->updates[] = $table;
} else { } else {
throw new \InvalidArgumentException(); throw new \InvalidArgumentException();

View File

@ -260,7 +260,7 @@ class Grammar extends GrammarAbstract
if (isset($element['value'])) { if (isset($element['value'])) {
$expression .= ' ' . \strtoupper($element['operator']) . ' ' . $this->compileValue($query, $element['value'], $query->getPrefix()); $expression .= ' ' . \strtoupper($element['operator']) . ' ' . $this->compileValue($query, $element['value'], $query->getPrefix());
} else { } else {
$operator = \strtoupper($element['operator']) === '=' ? 'IS' : 'IS NOT'; $operator = $element['operator'] === '=' ? 'IS' : 'IS NOT';
$expression .= ' ' . $operator . ' ' . $this->compileValue($query, $element['value'], $query->getPrefix()); $expression .= ' ' . $operator . ' ' . $this->compileValue($query, $element['value'], $query->getPrefix());
} }

View File

@ -112,6 +112,10 @@ class MysqlGrammar extends Grammar
$keys .= ' PRIMARY KEY (' . $this->expressionizeTableColumn([$name], '') . '),'; $keys .= ' PRIMARY KEY (' . $this->expressionizeTableColumn([$name], '') . '),';
} }
if (isset($field['unique']) && $field['unique']) {
$keys .= ' UNIQUE KEY (' . $this->expressionizeTableColumn([$name], '') . '),';
}
if (isset($field['foreignTable'], $field['foreignKey']) if (isset($field['foreignTable'], $field['foreignKey'])
&& !empty($field['foreignTable']) && !empty($field['foreignKey']) && !empty($field['foreignTable']) && !empty($field['foreignKey'])
) { ) {

View File

@ -278,7 +278,7 @@ final class Polygon implements D2ShapeInterface
*/ */
public static function getRegularAreaByLength(float $length, int $sides) : float public static function getRegularAreaByLength(float $length, int $sides) : float
{ {
return $length ** 2 * $sides / (4 * \tan(180 / $sides)); return $length ** 2 * $sides / (4 * \tan(\M_PI / $sides));
} }
/** /**
@ -293,6 +293,6 @@ final class Polygon implements D2ShapeInterface
*/ */
public static function getRegularAreaByRadius(float $r, int $sides) : float public static function getRegularAreaByRadius(float $r, int $sides) : float
{ {
return $r ** 2 * $sides * \sin(360 / $sides) / 2; return $r ** 2 * $sides * \tan(\M_PI / $sides);
} }
} }

View File

@ -26,10 +26,10 @@ final class Quadrilateral implements D2ShapeInterface
/** /**
* Calculate the surface area from the length of all sides and the angle between a and b * Calculate the surface area from the length of all sides and the angle between a and b
* *
* @param float $a Side a length * @param float $a Side a length (DA)
* @param float $b Side b length * @param float $b Side b length (AB)
* @param float $c Side c length * @param float $c Side c length (BC)
* @param float $d Side d length * @param float $d Side d length (CD)
* @param float $alpha Angle between side a and b * @param float $alpha Angle between side a and b
* *
* @return float * @return float
@ -38,7 +38,9 @@ final class Quadrilateral implements D2ShapeInterface
*/ */
public static function getSurfaceFromSidesAndAngle(float $a, float $b, float $c, float $d, float $alpha) : float public static function getSurfaceFromSidesAndAngle(float $a, float $b, float $c, float $d, float $alpha) : float
{ {
return 1 / 2 * $a * $b * \sin($alpha) + 1 / 4 $s = ($a + $b + $c + $d) / 2;
* \sqrt(4 * $c ** 2 * $d ** 2 - ($c ** 2 + $d ** 2 - $a ** 2 - $b ** 2 + 2 * $a * $b * \cos($alpha)) ** 2); $gamma = \acos(($c ** 2 + $d ** 2 - $a ** 2 - $b ** 2 + 2 * $a * $b * \cos(\deg2rad($alpha))) / (2 * $c * $d));
return \sqrt(($s - $a) * ($s - $b) * ($s - $c) * ($s - $d) - $a * $b * $c * $d * \cos((\deg2rad($alpha) + $gamma) / 2) ** 2);
} }
} }

View File

@ -13,6 +13,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\Math\Geometry\Shape\D3; namespace phpOMS\Math\Geometry\Shape\D3;
use phpOMS\Math\Geometry\Shape\D2\Polygon;
/** /**
* Prism shape. * Prism shape.
* *

View File

@ -110,7 +110,7 @@ class Matrix implements \ArrayAccess, \Iterator
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function get(int $m, int $n) public function get(int $m, int $n = 0)
{ {
if (!isset($this->matrix[$m], $this->matrix[$m][$n])) { if (!isset($this->matrix[$m], $this->matrix[$m][$n])) {
throw new InvalidDimensionException($m . 'x' . $n); throw new InvalidDimensionException($m . 'x' . $n);
@ -301,11 +301,10 @@ class Matrix implements \ArrayAccess, \Iterator
$mDim = $this->m; $mDim = $this->m;
$nDim = $this->n; $nDim = $this->n;
$rank = \max($mDim, $nDim); $rank = 0;
$selected = \array_fill(0, $mDim, false); $selected = \array_fill(0, $mDim, false);
for ($i = 0; $i < $nDim; ++$i) { for ($i = 0; $i < $nDim; ++$i) {
$j;
for ($j = 0; $j < $mDim; ++$j) { for ($j = 0; $j < $mDim; ++$j) {
if (!$selected[$j] && \abs($matrix[$j][$i]) > 0.0001) { if (!$selected[$j] && \abs($matrix[$j][$i]) > 0.0001) {
break; break;
@ -313,18 +312,19 @@ class Matrix implements \ArrayAccess, \Iterator
} }
if ($j === $mDim) { if ($j === $mDim) {
--$rank; continue;
} else { }
$selected[$j] = true;
for ($p = $i + 1; $p < $nDim; ++$p) {
$matrix[$j][$p] /= $matrix[$j][$i];
}
for ($k = 0; $k < $mDim; ++$k) { ++$rank;
if ($k !== $j && \abs($matrix[$k][$i]) > 0.0001) { $selected[$j] = true;
for ($p = $i + 1; $p < $nDim; ++$p) { for ($p = $i + 1; $p < $nDim; ++$p) {
$matrix[$k][$p] -= $matrix[$j][$p] * $matrix[$k][$i]; $matrix[$j][$p] /= $matrix[$j][$i];
} }
for ($k = 0; $k < $mDim; ++$k) {
if ($k !== $j && \abs($matrix[$k][$i]) > 0.0001) {
for ($p = $i + 1; $p < $nDim; ++$p) {
$matrix[$k][$p] -= $matrix[$j][$p] * $matrix[$k][$i];
} }
} }
} }
@ -674,7 +674,7 @@ class Matrix implements \ArrayAccess, \Iterator
* *
* @param Matrix $B Matrix/Vector b * @param Matrix $B Matrix/Vector b
* *
* @return Matrix * @return Matrix|Vector
* *
* @since 1.0.0 * @since 1.0.0
*/ */

View File

@ -89,7 +89,7 @@ final class SingularValueDecomposition
for ($k = 0; $k < $maxNctNrt; ++$k) { for ($k = 0; $k < $maxNctNrt; ++$k) {
if ($k < $nct) { if ($k < $nct) {
$this->S[$k] = 0; $this->S[$k] = 0.0;
for ($i = $k; $i < $this->m; ++$i) { for ($i = $k; $i < $this->m; ++$i) {
$this->S[$k] = Triangle::getHypot($this->S[$k], $A[$i][$k]); $this->S[$k] = Triangle::getHypot($this->S[$k], $A[$i][$k]);
} }
@ -273,7 +273,7 @@ final class SingularValueDecomposition
break; break;
} }
$t = ($ks !== $p ? \abs($e[$ks]) : 0) + ($ks !== $k + 1 ? \abs($e[$ks - 1]) : 0); $t = ($ks !== $p ? \abs($e[$ks]) : 0.0) + ($ks !== $k + 1 ? \abs($e[$ks - 1]) : 0.0);
if (\abs($this->S[$ks]) <= $eps * $t) { if (\abs($this->S[$ks]) <= $eps * $t) {
$this->S[$ks] = 0.0; $this->S[$ks] = 0.0;
@ -304,8 +304,8 @@ final class SingularValueDecomposition
$this->S[$j] = $t; $this->S[$j] = $t;
if ($j !== $k) { if ($j !== $k) {
$f = -$sn * $e[$j - 1]; $f = -$sn * $e[$j - 1];
$e[$j - 1] = $cs * $e[$j - 1]; $e[$j - 1] *= $cs;
} }
for ($i = 0; $i < $this->n; ++$i) { for ($i = 0; $i < $this->n; ++$i) {
@ -325,7 +325,7 @@ final class SingularValueDecomposition
$sn = $f / $t; $sn = $f / $t;
$this->S[$j] = $t; $this->S[$j] = $t;
$f = -$sn * $e[$j]; $f = -$sn * $e[$j];
$e[$j] = $cs * $e[$j]; $e[$j] *= $cs;
for ($i = 0; $i < $this->m; ++$i) { for ($i = 0; $i < $this->m; ++$i) {
$t = $cs * $this->U[$i][$j] + $sn * $this->U[$i][$k - 1]; $t = $cs * $this->U[$i][$j] + $sn * $this->U[$i][$k - 1];
@ -397,7 +397,7 @@ final class SingularValueDecomposition
$f = $cs * $e[$j] + $sn * $this->S[$j + 1]; $f = $cs * $e[$j] + $sn * $this->S[$j + 1];
$this->S[$j + 1] = -$sn * $e[$j] + $cs * $this->S[$j + 1]; $this->S[$j + 1] = -$sn * $e[$j] + $cs * $this->S[$j + 1];
$g = $sn * $e[$j + 1]; $g = $sn * $e[$j + 1];
$e[$j + 1] = $cs * $e[$j + 1]; $e[$j + 1] *= $cs;
if ($j < $this->m - 1) { if ($j < $this->m - 1) {
for ($i = 0; $i < $this->m; ++$i) { for ($i = 0; $i < $this->m; ++$i) {
@ -413,7 +413,7 @@ final class SingularValueDecomposition
break; break;
case 4: case 4:
if ($this->S[$k] <= 0.0) { if ($this->S[$k] <= 0.0) {
$this->S[$k] = ($this->S[$k] < 0.0 ? -$this->S[$k] : 0.0); $this->S[$k] = $this->S[$k] < 0.0 ? -$this->S[$k] : 0.0;
for ($i = 0; $i <= $pp; ++$i) { for ($i = 0; $i <= $pp; ++$i) {
$this->V[$i][$k] = -$this->V[$i][$k]; $this->V[$i][$k] = -$this->V[$i][$k];

View File

@ -24,4 +24,62 @@ namespace phpOMS\Math\Matrix;
*/ */
final class Vector extends Matrix final class Vector extends Matrix
{ {
/**
* Create vector
*
* @param int $m Vector length
*
* @since 1.0.0
*/
public function __cosntruct(int $m = 1)
{
parent::__construct($m, 1);
}
/**
* Set vector value
*
* @param int $m Position to set
* @param mixed $value Value to set
*
* @return void
*
* @since 1.0.0
*/
public function setV(int $m, $value) : void
{
parent::set($m , 0, $value);
}
/**
* Get vector value
*
* @param int $m Position to get
*
* @return mixed
*
* @since 1.0.0
*/
public function getV(int $m)
{
return parent::get($m, 0);
}
/**
* Set matrix
*
* @param array $vector 1-Dimensional array
*
* @return Vector
*
* @since 1.0.0
*/
public function setMatrixV(array $vector) : self
{
foreach ($vector as $key => $value) {
$this->setV($key, $value);
}
return $this;
}
} }

View File

@ -14,6 +14,9 @@ declare(strict_types=1);
namespace phpOMS\Math\Numerics\Interpolation; namespace phpOMS\Math\Numerics\Interpolation;
use phpOMS\Math\Matrix\Matrix;
use phpOMS\Math\Matrix\Vector;
/** /**
* Cubic spline interpolation. * Cubic spline interpolation.
* *
@ -22,6 +25,156 @@ namespace phpOMS\Math\Numerics\Interpolation;
* @link https://orange-management.org * @link https://orange-management.org
* @since 1.0.0 * @since 1.0.0
*/ */
class CubicSplineInterpolation class CubicSplineInterpolation implements InterpolationInterface
{ {
/**
* Points for spline interpolation
*
* @var array
* @since 1.0.0
*/
private array $points = [];
/**
* Parameter a of cubic spline
*
* @var Vector
* @since 1.0.0
*/
private Vector $solveA;
/**
* Parameter b of cubic spline
*
* @var Matrix
* @since 1.0.0
*/
private Matrix $solveB;
/**
* Parameter c of cubic spline
*
* @var Vector
* @since 1.0.0
*/
private Vector $solveC;
/**
* Constructor.
*
* @param array $points Points to create the interpolation with
* @param float $leftCurvature Left point curvature
* @param float $leftDerivativeType Derivative type for the left point
* @param float $rightCurvature Right point curvature
* @param float $rightDerivativeType Derivative type for the right point
*
* @since 1.0.0
*/
public function __construct(
array $points,
float $leftCurvature = 0.0,
int $leftDerivativeType = DerivativeType::FIRST,
float $rightCurvature = 0.0,
int $rightDerivativeType = DerivativeType::FIRST
) {
$this->points = $points;
$n = \count($this->points);
$b = [];
$matrix = new Matrix($n, $n);
for($i = 1; $i < $n - 1; ++$i) {
$matrix->set($i, $i - 1, 1.0 / 3.0 * ($this->points[$i]['x'] - $this->points[$i - 1]['x']));
$matrix->set($i, $i, 2.0 / 3.0 * ($this->points[$i + 1]['x'] - $this->points[$i - 1]['x']));
$matrix->set($i, $i + 1, 1.0 / 3.0 * ($this->points[$i + 1]['x'] - $this->points[$i]['x']));
$b[$i] = ($this->points[$i + 1]['y'] - $this->points[$i]['y']) / ($this->points[$i + 1]['x'] - $this->points[$i]['x'])
- ($this->points[$i]['y'] - $this->points[$i - 1]['y']) / ($this->points[$i]['x'] - $this->points[$i - 1]['x']);
}
if ($leftDerivativeType === DerivativeType::FIRST) {
$matrix->set(0, 0, 2.0 * ($this->points[1]['x'] - $this->points[0]['x']));
$matrix->set(0, 1, 1.0 * ($this->points[1]['x'] - $this->points[0]['x']));
$b[0] = 3.0 * (($this->points[1]['y'] - $this->points[0]['y']) / ($this->points[1]['x'] - $this->points[0]['x']) - $rightCurvature);
} else {
$matrix->set(0, 0, 2.0);
$matrix->set(0, 1, 0.0);
$b[0] = $leftCurvature;
}
if ($rightDerivativeType === DerivativeType::FIRST) {
$matrix->set($n - 1, $n - 1, 2.0 * ($this->points[$n - 1]['x'] - $this->points[$n - 2]['x']));
$matrix->set($n - 1, $n - 2, 1.0 * ($this->points[$n - 1]['x'] - $this->points[$n - 2]['x']));
$b[$n - 1] = 3.0 * ($rightCurvature - ($this->points[$n - 1]['y'] - $this->points[$n - 2]['y']) / ($this->points[$n - 1]['x'] - $this->points[$n - 2]['x']));
} else {
$matrix->set($n - 1, $n - 1, 2.0);
$matrix->set($n - 1, $n - 2, 0.0);
$b[$n - 1] = $rightCurvature;
}
$bVector = new Vector($n);
$bVector->setMatrixV($b);
$this->solveB = $matrix->solve($bVector);
$this->solveA = new Vector($n);
$this->solveC = new Vector($n);
for ($i = 0; $i < $n - 1; ++$i) {
$this->solveA->setV($i, 1.0 / 3.0 * ($this->solveB->get($i + 1) - $this->solveB->get($i)) / ($this->points[$i + 1]['x'] - $this->points[$i]['x']));
$this->solveC->setV($i,
($this->points[$i + 1]['y'] - $this->points[$i]['y']) / ($this->points[$i + 1]['x'] - $this->points[$i]['x'])
- 1.0 / 3.0 * (2 * $this->solveB->get($i) + $this->solveB->get($i + 1)) * ($this->points[$i + 1]['x'] - $this->points[$i]['x']));
}
$h = $this->points[$n - 1]['x'] - $this->points[$n - 2]['x'];
$this->solveA->setV($n - 1, 0.0);
$this->solveC->setV($n - 1, 3.0 * $this->solveA->getV($n - 2) * $h ** 2 + 2.0 * $this->solveB->get($n - 2) * $h + $this->solveC->getV($n - 2));
$a = 2;
/**
* @todo: consider linear extrapolation at start and end point
*
* $this->solveB->setV($n - 1, 0.0)
*/
}
/**
* {@inheritdoc}
*/
public function interpolate($x) : float
{
$n = \count($this->points);
$xPos = $n - 1;
foreach ($this->points as $key => $point) {
if ($x <= $point['x']) {
$xPos = $key;
break;
}
}
$xPos = \max($xPos - 1, 0);
$h = $x - $this->points[$xPos]['x'];
if ($x < $this->points[0]['x']) {
return ($this->solveB->get(0) * $h + $this->solveC->getV(0)) * $h + $this->points[0]['y'];
/**
* @todo: consider linear extrapolation at start and end point
*
* ($this->solveC->getV(0)) * $h + $this->points[0]['y'];
*/
} elseif ($x > $this->points[$n - 1]['x']) {
return ($this->solveB->get($n - 1) * $h + $this->solveC->getV($n - 1) * $h + $this->points[$n - 1]['y']);
}
return (($this->solveA->getV($xPos) * $h + $this->solveB->get($xPos)) * $h + $this->solveC->getV($xPos)) * $h + $this->points[$xPos]['y'];
}
} }

View File

@ -14,14 +14,18 @@ declare(strict_types=1);
namespace phpOMS\Math\Numerics\Interpolation; namespace phpOMS\Math\Numerics\Interpolation;
use phpOMS\Stdlib\Base\Enum;
/** /**
* Polynomial spline interpolation. * Derivative type enum.
* *
* @package phpOMS\Math\Numerics\Interpolation * @package phpOMS\Math\Numerics\Interpolation
* @license OMS License 1.0 * @license OMS License 1.0
* @link https://orange-management.org * @link https://orange-management.org
* @since 1.0.0 * @since 1.0.0
*/ */
class PolynomialInterpolation abstract class DerivativeType extends Enum
{ {
public const FIRST = 1;
public const SECOND = 2;
} }

View File

@ -0,0 +1,37 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package phpOMS\Math\Numerics\Interpolation
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace phpOMS\Math\Numerics\Interpolation;
/**
* Interpolation interface.
*
* @package phpOMS\Math\Numerics\Interpolation
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
interface InterpolationInterface
{
/**
* Interpolation at a given point
*
* @param float|int $x X-Coordinate to interpolate at
*
* @return float
*
* @since 1.0.0
*/
public function interpolate($x) : float;
}

View File

@ -0,0 +1,67 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package phpOMS\Math\Numerics\Interpolation
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace phpOMS\Math\Numerics\Interpolation;
/**
* Lagrange spline interpolation.
*
* @package phpOMS\Math\Numerics\Interpolation
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
class LagrangeInterpolation implements InterpolationInterface
{
/**
* Points for spline interpolation
*
* @var array
* @since 1.0.0
*/
private array $points = [];
/**
* Constructor.
*
* @param array $points Points to create the interpolation with
*
* @since 1.0.0
*/
public function __construct(array $points) {
$this->points = $points;
}
/**
* {@inheritdoc}
*/
public function interpolate($x) : float
{
$n = \count($this->points);
$result = 0.0;
for ($i = 0; $i < $n; ++$i) {
$solve = $this->points[$i]['y'];
for ($j = 0; $j < $n; ++$j) {
if ($j !== $i) {
$solve *= ($x - $this->points[$j]['x']) / ($this->points[$i]['x'] - $this->points[$j]['x']);
}
}
$result += $solve;
}
return $result;
}
}

View File

@ -14,6 +14,8 @@ declare(strict_types=1);
namespace phpOMS\Math\Numerics\Interpolation; namespace phpOMS\Math\Numerics\Interpolation;
use phpOMS\Math\Matrix\Vector;
/** /**
* Linear spline interpolation. * Linear spline interpolation.
* *
@ -22,6 +24,100 @@ namespace phpOMS\Math\Numerics\Interpolation;
* @link https://orange-management.org * @link https://orange-management.org
* @since 1.0.0 * @since 1.0.0
*/ */
class LinearInterpolation class LinearInterpolation implements InterpolationInterface
{ {
/**
* Points for spline interpolation
*
* @var array
* @since 1.0.0
*/
private array $points = [];
/**
* Parameter a of cubic spline
*
* @var Vector
* @since 1.0.0
*/
private Vector $solveA;
/**
* Parameter b of cubic spline
*
* @var Vector
* @since 1.0.0
*/
private Vector $solveB;
/**
* Parameter c of cubic spline
*
* @var Vector
* @since 1.0.0
*/
private Vector $solveC;
/**
* Constructor.
*
* @param array $points Points to create the interpolation with
*
* @since 1.0.0
*/
public function __construct(array $points) {
$this->points = $points;
$n = \count($this->points);
$this->solveA = new Vector($n);
$this->solveB = new Vector($n);
$this->solveC = new Vector($n);
for ($i = 0; $i < $n - 1; ++$i) {
$this->solveA->setV($i, 0.0);
$this->solveB->setV($i, 0.0);
$this->solveC->setV($i, ($this->points[$i + 1]['y'] - $this->points[$i]['y']) / ($this->points[$i + 1]['x'] - $this->points[$i]['x']));
}
for ($i = 0; $i < $n - 1; ++$i) {
$this->solveA->setV($i, 1.0 / 3.0 * ($this->solveB->getV($i + 1) - $this->solveB->getV($i)) / ($this->points[$i + 1]['x'] - $this->points[$i]['x']));
$this->solveC->setV($i,
($this->points[$i + 1]['y'] - $this->points[$i]['y']) / ($this->points[$i + 1]['x'] - $this->points[$i]['x'])
- 1.0 / 3.0 * (2 * $this->solveB->getV($i) + $this->solveB->getV($i + 1)) * ($this->points[$i + 1]['x'] - $this->points[$i]['x']));
}
$h = $this->points[$n - 1]['x'] - $this->points[$n - 2]['x'];
$this->solveA->setV($n - 1, 0.0);
$this->solveC->setV($n - 1, 3.0 * $this->solveA->getV($n - 2) * $h ** 2 + 2.0 * $this->solveB->getV($n - 2) * $h + $this->solveC->getV($n - 2));
}
/**
* {@inheritdoc}
*/
public function interpolate($x) : float
{
$n = \count($this->points);
$xPos = $n - 1;
foreach ($this->points as $key => $point) {
if ($x <= $point['x']) {
$xPos = $key;
break;
}
}
$xPos = \max($xPos - 1, 0);
$h = $x - $this->points[$xPos]['x'];
if ($x < $this->points[0]['x']) {
return ($this->solveB->getV(0) * $h + $this->solveC->getV(0)) * $h + $this->points[0]['y'];
} elseif ($x > $this->points[$n - 1]['x']) {
return ($this->solveB->getV($n - 1) * $h + $this->solveC->getV($n - 1) * $h + $this->points[$n - 1]['y']);
}
return (($this->solveA->getV($xPos) * $h + $this->solveB->getV($xPos)) * $h + $this->solveC->getV($xPos)) * $h + $this->points[$xPos]['y'];
}
} }

View File

@ -117,8 +117,6 @@ class NaiveBayesClassifier
++$this->probabilities['criteria'][$criteria]['count']; ++$this->probabilities['criteria'][$criteria]['count'];
++$this->probabilities['count']; ++$this->probabilities['count'];
} }
$this->changed = true;
} }
/** /**
@ -134,11 +132,7 @@ class NaiveBayesClassifier
*/ */
public function match(string $criteria, array $toMatch, int $minimum = 3) : float public function match(string $criteria, array $toMatch, int $minimum = 3) : float
{ {
if ($this->changed) { $this->preCalculateProbabilities($toMatch);
$this->cache();
}
$this->changed = false;
$n = 0.0; $n = 0.0;
foreach ($toMatch as $attr => $value) { foreach ($toMatch as $attr => $value) {
@ -161,10 +155,10 @@ class NaiveBayesClassifier
} }
} else { } else {
// todo: add probability of criteria / total? // todo: add probability of criteria / total?
$p = 1 / \sqrt(2 * \M_PI * $this->probabilities['criteria'][$criteria]['attr'][$attr]['variance']) $p = (1 / \sqrt(2 * \M_PI * $this->probabilities['criteria'][$criteria]['attr'][$attr]['variance'])
* \exp(-($value - $this->probabilities['criteria'][$criteria]['attr'][$attr]['mean']) / (2 * $this->probabilities['criteria'][$criteria]['attr'][$attr]['variance'])); * \exp(-($value - $this->probabilities['criteria'][$criteria]['attr'][$attr]['mean']) ** 2 / (2 * $this->probabilities['criteria'][$criteria]['attr'][$attr]['variance'])))
* ($this->probabilities['criteria'][$criteria]['count'] / $this->probabilities['count'])
//var_dump($p); / $this->probabilities['attr'][$attr]['data'];
$n += \log(1 - $p) - \log($p); $n += \log(1 - $p) - \log($p);
} }
@ -174,13 +168,15 @@ class NaiveBayesClassifier
} }
/** /**
* Cache probabilities for matching function. * Pre-calculate some probabilities used for the matching process
*
* @param array $toMatch Data to match. Some probabilities depend on the passed values.
* *
* @return void * @return void
* *
* @since 1.0.0 * @since 1.0.0
*/ */
private function cache() : void private function preCalculateProbabilities(array $toMatch) : void
{ {
$this->probabilities['attr'] = []; $this->probabilities['attr'] = [];
@ -188,15 +184,18 @@ class NaiveBayesClassifier
foreach ($subDict as $attr => $valueArray) { foreach ($subDict as $attr => $valueArray) {
if ($valueArray['type'] === 2) { if ($valueArray['type'] === 2) {
$this->probabilities['criteria'][$criteria]['attr'][$attr]['mean'] = Average::arithmeticMean($this->dict[$criteria][$attr]['data']); $this->probabilities['criteria'][$criteria]['attr'][$attr]['mean'] = Average::arithmeticMean($this->dict[$criteria][$attr]['data']);
$this->probabilities['criteria'][$criteria]['attr'][$attr]['variance'] = MeasureOfDispersion::empiricalVariance($this->dict[$criteria][$attr]['data'], [], $this->probabilities['criteria'][$criteria]['attr'][$attr]['mean']); $this->probabilities['criteria'][$criteria]['attr'][$attr]['variance'] = MeasureOfDispersion::sampleVariance($this->dict[$criteria][$attr]['data'], $this->probabilities['criteria'][$criteria]['attr'][$attr]['mean']);
// \var_dump($criteria); if (!isset($this->probabilities['attr'][$attr])) {
// \var_dump($attr); $this->probabilities['attr'][$attr] = ['data' => 0.0];
// \var_dump($this->probabilities['criteria'][$criteria]['attr'][$attr]['mean']); // good }
// \var_dump($this->probabilities['criteria'][$criteria]['attr'][$attr]['variance']); // bad
$this->probabilities['attr'][$attr]['data'] += (1 / \sqrt(2 * \M_PI * $this->probabilities['criteria'][$criteria]['attr'][$attr]['variance'])
* \exp(-($toMatch[$attr] - $this->probabilities['criteria'][$criteria]['attr'][$attr]['mean']) ** 2 / (2 * $this->probabilities['criteria'][$criteria]['attr'][$attr]['variance'])))
* ($this->probabilities['criteria'][$criteria]['count'] / $this->probabilities['count']);
} else { } else {
if (!isset( $this->probabilities['attr'][$attr])) { if (!isset( $this->probabilities['attr'][$attr])) {
$this->probabilities['attr'] = [$attr => ['data' => []]]; $this->probabilities['attr'][$attr] = ['data' => []];
} }
foreach ($valueArray['data'] as $word => $count) { foreach ($valueArray['data'] as $word => $count) {

View File

@ -134,9 +134,7 @@ final class Router
) { ) {
// if csrf is required but not set // if csrf is required but not set
if (isset($d['csrf']) && $d['csrf'] && $csrf === null) { if (isset($d['csrf']) && $d['csrf'] && $csrf === null) {
\array_merge($bound, $this->route('/' . $app . '/e403', $csrf, $verb)); return $app !== null ? $this->route('/' . \strtolower($app) . '/e403', $csrf, $verb) : $this->route('/e403', $csrf, $verb);
continue;
} }
// if permission check is invalid // if permission check is invalid
@ -147,9 +145,7 @@ final class Router
) )
) )
) { ) {
\array_merge($bound, $this->route('/' . $app . '/e403', $csrf, $verb)); return $app !== null ? $this->route('/' . \strtolower($app) . '/e403', $csrf, $verb) : $this->route('/e403', $csrf, $verb);
continue;
} }
$bound[] = ['dest' => $d['dest']]; $bound[] = ['dest' => $d['dest']];

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Account; namespace phpOMS\tests\Account;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Account; namespace phpOMS\tests\Account;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Account; namespace phpOMS\tests\Account;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Account; namespace phpOMS\tests\Account;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Account; namespace phpOMS\tests\Account;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Account; namespace phpOMS\tests\Account;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Account; namespace phpOMS\tests\Account;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Account; namespace phpOMS\tests\Account;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Account; namespace phpOMS\tests\Account;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\Algorithm\CoinMatching; namespace phpOMS\Algorithm\CoinMatching;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Algorithm\PathFinding; namespace phpOMS\tests\Algorithm\PathFinding;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Algorithm\Sort; namespace phpOMS\tests\Algorithm\Sort;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Algorithm\Sort; namespace phpOMS\tests\Algorithm\Sort;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Algorithm\Sort; namespace phpOMS\tests\Algorithm\Sort;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Algorithm\Sort; namespace phpOMS\tests\Algorithm\Sort;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Algorithm\Sort; namespace phpOMS\tests\Algorithm\Sort;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Algorithm\Sort; namespace phpOMS\tests\Algorithm\Sort;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Algorithm\Sort; namespace phpOMS\tests\Algorithm\Sort;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Algorithm\Sort; namespace phpOMS\tests\Algorithm\Sort;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Algorithm\Sort; namespace phpOMS\tests\Algorithm\Sort;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Algorithm\Sort; namespace phpOMS\tests\Algorithm\Sort;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Algorithm\Sort; namespace phpOMS\tests\Algorithm\Sort;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Algorithm\Sort; namespace phpOMS\tests\Algorithm\Sort;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Algorithm\Sort; namespace phpOMS\tests\Algorithm\Sort;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Algorithm\Sort; namespace phpOMS\tests\Algorithm\Sort;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Algorithm\Sort; namespace phpOMS\tests\Algorithm\Sort;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Algorithm\Sort; namespace phpOMS\tests\Algorithm\Sort;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Algorithm\Sort; namespace phpOMS\tests\Algorithm\Sort;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Algorithm\Sort; namespace phpOMS\tests\Algorithm\Sort;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Algorithm\Sort; namespace phpOMS\tests\Algorithm\Sort;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests; namespace phpOMS\tests;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Asset; namespace phpOMS\tests\Asset;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Asset; namespace phpOMS\tests\Asset;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Auth; namespace phpOMS\tests\Auth;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Auth; namespace phpOMS\tests\Auth;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests; namespace phpOMS\tests;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests; namespace phpOMS\tests;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Business\Finance; namespace phpOMS\tests\Business\Finance;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Business\Finance; namespace phpOMS\tests\Business\Finance;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Business\Finance; namespace phpOMS\tests\Business\Finance;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Business\Finance; namespace phpOMS\tests\Business\Finance;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Business\Finance; namespace phpOMS\tests\Business\Finance;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Business\Marketing; namespace phpOMS\tests\Business\Marketing;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Business\Marketing; namespace phpOMS\tests\Business\Marketing;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Business\Programming; namespace phpOMS\tests\Business\Programming;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Business\Sales; namespace phpOMS\tests\Business\Sales;
use phpOMS\Business\Sales\MarketShareEstimation; use phpOMS\Business\Sales\MarketShareEstimation;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\Config; namespace phpOMS\tests\Config;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Cache; namespace phpOMS\tests\DataStorage\Cache;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Cache; namespace phpOMS\tests\DataStorage\Cache;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Cache; namespace phpOMS\tests\DataStorage\Cache;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Cache\Connection; namespace phpOMS\tests\DataStorage\Cache\Connection;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Cache\Connection; namespace phpOMS\tests\DataStorage\Cache\Connection;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Cache\Connection; namespace phpOMS\tests\DataStorage\Cache\Connection;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Cache\Connection; namespace phpOMS\tests\DataStorage\Cache\Connection;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Cache\Connection; namespace phpOMS\tests\DataStorage\Cache\Connection;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Cache\Connection; namespace phpOMS\tests\DataStorage\Cache\Connection;
@ -89,13 +89,19 @@ class MemCachedTest extends \PHPUnit\Framework\TestCase
self::assertFalse($cache->delete('keyInvalid')); self::assertFalse($cache->delete('keyInvalid'));
self::assertNull($cache->get('key4')); self::assertNull($cache->get('key4'));
self::assertArraySubset( $arr = [
[ 'status' => CacheStatus::OK,
'status' => CacheStatus::OK, 'count' => 6,
'count' => 6, ];
], $isSubset = true;
$cache->stats() $parent = $cache->stats();
); foreach ($arr as $key => $value) {
if (!isset($parent[$key]) || $parent[$key] !== $value) {
$isSubset = false;
break;
}
}
self::assertTrue($isSubset);
self::assertTrue($cache->flushAll()); self::assertTrue($cache->flushAll());
self::assertTrue($cache->flush()); self::assertTrue($cache->flush());
@ -103,13 +109,19 @@ class MemCachedTest extends \PHPUnit\Framework\TestCase
$cache->flushAll(); $cache->flushAll();
self::assertArraySubset( $arr = [
[ 'status' => CacheStatus::OK,
'status' => CacheStatus::OK, 'count' => 5, // Carefull memcached is dumb and keeps expired elements which were not acessed after flushing in stats
'count' => 5, // Carefull memcached is dumb and keeps expired elements which were not acessed after flushing in stats ];
], $isSubset = true;
$cache->stats() $parent = $cache->stats();
); foreach ($arr as $key => $value) {
if (!isset($parent[$key]) || $parent[$key] !== $value) {
$isSubset = false;
break;
}
}
self::assertTrue($isSubset);
} }
public function testBadCacheStatus() : void public function testBadCacheStatus() : void

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Cache\Connection; namespace phpOMS\tests\DataStorage\Cache\Connection;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Cache\Connection; namespace phpOMS\tests\DataStorage\Cache\Connection;
@ -91,13 +91,19 @@ class RedisCacheTest extends \PHPUnit\Framework\TestCase
self::assertFalse($cache->delete('keyInvalid')); self::assertFalse($cache->delete('keyInvalid'));
self::assertNull($cache->get('key4')); self::assertNull($cache->get('key4'));
self::assertArraySubset( $arr = [
[ 'status' => CacheStatus::OK,
'status' => CacheStatus::OK, 'count' => 6,
'count' => 6, ];
], $isSubset = true;
$cache->stats() $parent = $cache->stats();
); foreach ($arr as $key => $value) {
if (!isset($parent[$key]) || $parent[$key] !== $value) {
$isSubset = false;
break;
}
}
self::assertTrue($isSubset);
self::assertTrue($cache->flushAll()); self::assertTrue($cache->flushAll());
self::assertTrue($cache->flush()); self::assertTrue($cache->flush());
@ -105,13 +111,19 @@ class RedisCacheTest extends \PHPUnit\Framework\TestCase
$cache->flushAll(); $cache->flushAll();
self::assertArraySubset( $arr = [
[ 'status' => CacheStatus::OK,
'status' => CacheStatus::OK, 'count' => 0,
'count' => 0, ];
], $isSubset = true;
$cache->stats() $parent = $cache->stats();
); foreach ($arr as $key => $value) {
if (!isset($parent[$key]) || $parent[$key] !== $value) {
$isSubset = false;
break;
}
}
self::assertTrue($isSubset);
} }
public function testBadCacheStatus() : void public function testBadCacheStatus() : void

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Cache\Exception; namespace phpOMS\tests\DataStorage\Cache\Exception;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Cookie; namespace phpOMS\tests\DataStorage\Cookie;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Database\Connection; namespace phpOMS\tests\DataStorage\Database\Connection;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Database\Connection; namespace phpOMS\tests\DataStorage\Database\Connection;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Database\Connection; namespace phpOMS\tests\DataStorage\Database\Connection;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Database\Connection; namespace phpOMS\tests\DataStorage\Database\Connection;
use phpOMS\DataStorage\Database\Connection\PostgresConnection; use phpOMS\DataStorage\Database\Connection\PostgresConnection;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Database\Connection; namespace phpOMS\tests\DataStorage\Database\Connection;
use phpOMS\DataStorage\Database\Connection\SQLiteConnection; use phpOMS\DataStorage\Database\Connection\SQLiteConnection;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Database\Connection; namespace phpOMS\tests\DataStorage\Database\Connection;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Database; namespace phpOMS\tests\DataStorage\Database;
use phpOMS\tests\DataStorage\Database\TestModel\BaseModel; use phpOMS\tests\DataStorage\Database\TestModel\BaseModel;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Database; namespace phpOMS\tests\DataStorage\Database;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Database; namespace phpOMS\tests\DataStorage\Database;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Database; namespace phpOMS\tests\DataStorage\Database;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Database; namespace phpOMS\tests\DataStorage\Database;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Database\Exception; namespace phpOMS\tests\DataStorage\Database\Exception;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Database\Exception; namespace phpOMS\tests\DataStorage\Database\Exception;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Database\Exception; namespace phpOMS\tests\DataStorage\Database\Exception;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Database\Query; namespace phpOMS\tests\DataStorage\Database\Query;
@ -35,6 +35,10 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
$sql = 'SELECT `a`.`test` FROM `a` WHERE `a`.`test` = 1;'; $sql = 'SELECT `a`.`test` FROM `a` WHERE `a`.`test` = 1;';
self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 1)->toSql()); self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 1)->toSql());
$query = new Builder($this->con);
$sql = 'SELECT `a`.`test` as t FROM `a` as b WHERE `a`.`test` = 1;';
self::assertEquals($sql, $query->selectAs('a.test', 't')->fromAs('a', 'b')->where('a.test', '=', 1)->toSql());
$query = new Builder($this->con); $query = new Builder($this->con);
$sql = 'SELECT DISTINCT `a`.`test` FROM `a` WHERE `a`.`test` = 1;'; $sql = 'SELECT DISTINCT `a`.`test` FROM `a` WHERE `a`.`test` = 1;';
self::assertEquals($sql, $query->select('a.test')->distinct()->from('a')->where('a.test', '=', 1)->toSql()); self::assertEquals($sql, $query->select('a.test')->distinct()->from('a')->where('a.test', '=', 1)->toSql());
@ -76,6 +80,8 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
->orderBy(['a.test', 'b.test', ], ['ASC', 'DESC', ]) ->orderBy(['a.test', 'b.test', ], ['ASC', 'DESC', ])
->toSql() ->toSql()
); );
self::assertEquals($query->toSql(), $query->__toString());
} }
public function testMysqlOrder() : void public function testMysqlOrder() : void
@ -340,6 +346,30 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
$query->delete(); $query->delete();
} }
public function testInvalidSelectParameter() : void
{
self::expectException(\InvalidArgumentException::class);
$query = new Builder($this->con, true);
$query->select(false);
}
public function testInvalidFromParameter() : void
{
self::expectException(\InvalidArgumentException::class);
$query = new Builder($this->con, true);
$query->from(false);
}
public function testInvalidGroupByParameter() : void
{
self::expectException(\InvalidArgumentException::class);
$query = new Builder($this->con, true);
$query->groupBy(false);
}
public function testInvalidWhereOperator() : void public function testInvalidWhereOperator() : void
{ {
self::expectException(\InvalidArgumentException::class); self::expectException(\InvalidArgumentException::class);

View File

@ -10,17 +10,19 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Database\Query; namespace phpOMS\tests\DataStorage\Database\Query;
use phpOMS\DataStorage\Database\Query\Column;
/** /**
* @internal * @internal
*/ */
class ColumnTest extends \PHPUnit\Framework\TestCase class ColumnTest extends \PHPUnit\Framework\TestCase
{ {
public function testPlaceholder() : void public function testDefault() : void
{ {
self::markTestIncomplete(); self::assertInstanceOf('\phpOMS\DataStorage\Database\Query\Builder', new Column($GLOBALS['dbpool']->get()));
} }
} }

View File

@ -10,17 +10,19 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Database\Query; namespace phpOMS\tests\DataStorage\Database\Query;
use phpOMS\DataStorage\Database\Query\Count;
/** /**
* @internal * @internal
*/ */
class CountTest extends \PHPUnit\Framework\TestCase class CountTest extends \PHPUnit\Framework\TestCase
{ {
public function testPlaceholder() : void public function testDefault() : void
{ {
self::markTestIncomplete(); self::assertInstanceOf('\phpOMS\DataStorage\Database\Query\Builder', new Count($GLOBALS['dbpool']->get()));
} }
} }

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Database\Query; namespace phpOMS\tests\DataStorage\Database\Query;

View File

@ -10,17 +10,19 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Database\Query; namespace phpOMS\tests\DataStorage\Database\Query;
use phpOMS\DataStorage\Database\Query\From;
/** /**
* @internal * @internal
*/ */
class FromTest extends \PHPUnit\Framework\TestCase class FromTest extends \PHPUnit\Framework\TestCase
{ {
public function testPlaceholder() : void public function testDefault() : void
{ {
self::markTestIncomplete(); self::assertInstanceOf('\phpOMS\DataStorage\Database\Query\Builder', new From($GLOBALS['dbpool']->get()));
} }
} }

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Database\Query\Grammar; namespace phpOMS\tests\DataStorage\Database\Query\Grammar;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Database\Query\Grammar; namespace phpOMS\tests\DataStorage\Database\Query\Grammar;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Database\Query\Grammar; namespace phpOMS\tests\DataStorage\Database\Query\Grammar;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Database\Query\Grammar; namespace phpOMS\tests\DataStorage\Database\Query\Grammar;

View File

@ -10,7 +10,7 @@
* @version 1.0.0 * @version 1.0.0
* @link https://orange-management.org * @link https://orange-management.org
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\tests\DataStorage\Database\Query\Grammar; namespace phpOMS\tests\DataStorage\Database\Query\Grammar;

Some files were not shown because too many files have changed in this diff Show More