mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
Media upload fixes and cleanup
This commit is contained in:
parent
5a854ce1c9
commit
48b42be7a9
|
|
@ -16,6 +16,17 @@
|
|||
|
||||
namespace phpOMS\DataStorage\Database\Query\Grammar;
|
||||
|
||||
/**
|
||||
* Grammar class.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database\Query\Grammar
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class MysqlGrammar extends Grammar
|
||||
{
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,17 @@
|
|||
|
||||
namespace phpOMS\DataStorage\Database\Query\Grammar;
|
||||
|
||||
/**
|
||||
* Grammar class.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database\Query\Grammar
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class SqliteGrammar extends Grammar
|
||||
{
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ namespace phpOMS\DataStorage\Database\Schema\Grammar;
|
|||
|
||||
use phpOMS\DataStorage\Database\BuilderAbstract;
|
||||
use phpOMS\DataStorage\Database\GrammarAbstract;
|
||||
use phpOMS\DataStorage\Database\Schema\Builder;
|
||||
use phpOMS\DataStorage\Database\Schema\QueryType;
|
||||
|
||||
/**
|
||||
|
|
@ -55,6 +54,16 @@ class Grammar extends GrammarAbstract
|
|||
'drop',
|
||||
];
|
||||
|
||||
/**
|
||||
* Compile components based on query type.
|
||||
*
|
||||
* @param BuilderAbstract $query Query
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function compileComponents(BuilderAbstract $query) : array
|
||||
{
|
||||
$sql = [];
|
||||
|
|
@ -77,7 +86,18 @@ class Grammar extends GrammarAbstract
|
|||
return $sql;
|
||||
}
|
||||
|
||||
protected function compileDrop(Builder $query, array $tables) : string
|
||||
/**
|
||||
* Compile drop query.
|
||||
*
|
||||
* @param BuilderAbstract $query Query
|
||||
* @param array $tables Tables to drop
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
protected function compileDrop(BuilderAbstract $query, array $tables) : string
|
||||
{
|
||||
$expression = $this->expressionizeTableColumn($tables, $query->getPrefix());
|
||||
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ class FileLogger implements LoggerInterface
|
|||
}
|
||||
|
||||
if (is_dir($lpath) || strpos($lpath, '.') === false) {
|
||||
Directory::createPath($lpath, 0644);
|
||||
Directory::createPath($lpath, '0644');
|
||||
File::createFile($path = $lpath . '/' . date('Y-m-d') . '.log');
|
||||
|
||||
$path = realpath($path);
|
||||
|
|
|
|||
|
|
@ -1,59 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
namespace phpOMS\Math;
|
||||
|
||||
class Complex
|
||||
{
|
||||
private $real = null;
|
||||
|
||||
private $im = null;
|
||||
|
||||
public function getReal()
|
||||
{
|
||||
}
|
||||
|
||||
public function setReal()
|
||||
{
|
||||
}
|
||||
|
||||
public function setImaginary()
|
||||
{
|
||||
}
|
||||
|
||||
public function getImaginary()
|
||||
{
|
||||
}
|
||||
|
||||
public function pow()
|
||||
{
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
}
|
||||
|
||||
public function sub()
|
||||
{
|
||||
}
|
||||
|
||||
public function mult()
|
||||
{
|
||||
}
|
||||
|
||||
public function div()
|
||||
{
|
||||
}
|
||||
}
|
||||
341
Math/Forecast/Error.php
Normal file
341
Math/Forecast/Error.php
Normal file
|
|
@ -0,0 +1,341 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\Math\Forecast;
|
||||
|
||||
use phpOMS\Math\Functions;
|
||||
use phpOMS\Math\Statistic\Average;
|
||||
use phpOMS\Math\Statistic\MeasureOfDispersion;
|
||||
|
||||
/**
|
||||
* Basic forecast functions.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Error
|
||||
{
|
||||
/**
|
||||
* Get the error of a forecast.
|
||||
*
|
||||
* @param float $observed Dataset
|
||||
* @param float $forecasted Forecasted
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getForecastError(float $observed, float $forecasted) : float
|
||||
{
|
||||
return $observed - $forecasted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get array of errors of a forecast.
|
||||
*
|
||||
* @param array $observed Dataset
|
||||
* @param array $forecasted Forecasted
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getForecastErrorArray(array $observed, array $forecasted) : array
|
||||
{
|
||||
$errors = [];
|
||||
|
||||
foreach ($forecasted as $key => $expected) {
|
||||
$errors[] = self::getForecastError($observed[$key], $expected);
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get error percentage.
|
||||
*
|
||||
* @param float $error Error
|
||||
* @param float $observed Dataset
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getPercentageError(float $error, float $observed) : float
|
||||
{
|
||||
return $error / $observed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get error percentages.
|
||||
*
|
||||
* @param array $errors Errors
|
||||
* @param array $observed Dataset
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getPercentageErrorArray(array $errors, array $observed) : array
|
||||
{
|
||||
$percentages = [];
|
||||
|
||||
foreach ($errors as $key => $error) {
|
||||
$percentages[] = self::getPercentageError($error, $observed[$key]);
|
||||
}
|
||||
|
||||
return $percentages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mean absolute error (MAE).
|
||||
*
|
||||
* @param array $errors Errors
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMeanAbsoulteError(array $errors) : float
|
||||
{
|
||||
return Average::arithmeticMean(Functions::abs($errors));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get root mean squared error (RMSE).
|
||||
*
|
||||
* @param array $errors Errors
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getRootMeanSquaredError(array $errors) : float
|
||||
{
|
||||
return sqrt(Average::arithmeticMean(self::square($errors)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mean absolute percentage error (MAPE).
|
||||
*
|
||||
* @param array $observed Dataset
|
||||
* @param array $forecasted Forecasted
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMeanAbsolutePercentageError(array $observed, array $forecasted) : float
|
||||
{
|
||||
return Average::arithmeticMean(Functions::abs(self::getPercentageErrorArray(self::getForecastErrorArray($observed, $forecasted), $observed)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mean absolute percentage error (sMAPE).
|
||||
*
|
||||
* @param array $observed Dataset
|
||||
* @param array $forecasted Forecasted
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getSymmetricMeanAbsolutePercentageError(array $observed, array $forecasted) : float
|
||||
{
|
||||
$error = [];
|
||||
|
||||
foreach ($observed as $key => $value) {
|
||||
$error[] = 200 * abs($value - $forecasted[$key]) / ($value + $forecasted[$key]);
|
||||
}
|
||||
|
||||
return Average::arithmeticMean($error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Square all values in array.
|
||||
*
|
||||
* @param array $values Values to square
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* todo: move to utils?! implement sqrt for array as well... could be usefull for others (e.g. matrix)
|
||||
*/
|
||||
private static function square(array $values) : array
|
||||
{
|
||||
$squared = [];
|
||||
|
||||
foreach ($values as $value) {
|
||||
$squared[] = $value * $value;
|
||||
}
|
||||
|
||||
return $squared;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cross sectional scaled errors (CSSE)
|
||||
*
|
||||
* @param array $errors Errors
|
||||
* @param array $observed Dataset
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getCrossSectionalScaledErrorArray(array $errors, array $observed) : array
|
||||
{
|
||||
$scaled = [];
|
||||
$deviation = MeasureOfDispersion::meanDeviation($observed);
|
||||
|
||||
foreach ($errors as $error) {
|
||||
$error[] = $error / $deviation;
|
||||
}
|
||||
|
||||
return $scaled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cross sectional scaled errors (CSSE)
|
||||
*
|
||||
* @param float $error Errors
|
||||
* @param array $observed Dataset
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getCrossSectionalScaledError(float $error, array $observed) : float
|
||||
{
|
||||
$mean = Average::arithmeticMean($observed);
|
||||
$sum = 0.0;
|
||||
|
||||
foreach ($observed as $value) {
|
||||
$sum += abs($value - $mean);
|
||||
}
|
||||
|
||||
return $error / MeasureOfDispersion::meanDeviation($observed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mean absolute scaled error (MASE)
|
||||
*
|
||||
* @param array $scaledErrors Scaled errors
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMeanAbsoluteScaledError(array $scaledErrors) : float
|
||||
{
|
||||
return Average::arithmeticMean(Functions::abs($scaledErrors));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mean absolute scaled error (MASE)
|
||||
*
|
||||
* @param array $scaledErrors Scaled errors
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getMeanSquaredScaledError(array $scaledErrors) : float
|
||||
{
|
||||
return Average::arithmeticMean(self::square($scaledErrors));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get scaled error (SE)
|
||||
*
|
||||
* @param array $errors Errors
|
||||
* @param array $observed Dataset
|
||||
* @param int $m Shift
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getScaledErrorArray(array $errors, array $observed, int $m = 1) : array
|
||||
{
|
||||
$scaled = [];
|
||||
$naive = 1 / (count($observed) - $m) * self::getNaiveForecast($observed, $m);
|
||||
|
||||
foreach ($errors as $error) {
|
||||
$error[] = $error / $naive;
|
||||
}
|
||||
|
||||
return $scaled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get scaled error (SE)
|
||||
*
|
||||
* @param float $error Errors
|
||||
* @param array $observed Dataset
|
||||
* @param int $m Shift
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getScaledError(float $error, array $observed, int $m = 1) : float
|
||||
{
|
||||
return $error / (1 / (count($observed) - $m) * self::getNaiveForecast($observed, $m));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get naive forecast
|
||||
*
|
||||
* @param array $observed Dataset
|
||||
* @param int $m Shift
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
private static function getNaiveForecast(array $observed, int $m = 1) : float
|
||||
{
|
||||
$sum = 0.0;
|
||||
$count = count($observed);
|
||||
|
||||
for ($i = 0 + $m; $i < $count; $i++) {
|
||||
$sum += abs($observed[$i] - $observed[$i - $m]);
|
||||
}
|
||||
|
||||
return $sum;
|
||||
}
|
||||
}
|
||||
|
|
@ -138,6 +138,18 @@ class Functions
|
|||
return self::ackermann($m - 1, self::ackermann($m, $n - 1));
|
||||
}
|
||||
|
||||
|
||||
public static function abs(array $values) : array
|
||||
{
|
||||
$abs = [];
|
||||
|
||||
foreach ($values as $value) {
|
||||
$abs[] = abs($value);
|
||||
}
|
||||
|
||||
return $abs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate inverse modular.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,14 +1,59 @@
|
|||
class Complex implements Number {
|
||||
private $real = 0;
|
||||
private $imaginary = 0;
|
||||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
namespace phpOMS\Math\Number;
|
||||
|
||||
public function __construct() {}
|
||||
class Complex
|
||||
{
|
||||
private $real = null;
|
||||
|
||||
public function setReal($real) {
|
||||
$this->real = $real;
|
||||
private $im = null;
|
||||
|
||||
public function getReal()
|
||||
{
|
||||
}
|
||||
|
||||
public function setReal()
|
||||
{
|
||||
}
|
||||
|
||||
public function setImaginary()
|
||||
{
|
||||
}
|
||||
|
||||
public function getImaginary()
|
||||
{
|
||||
}
|
||||
|
||||
public function pow()
|
||||
{
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
}
|
||||
|
||||
public function sub()
|
||||
{
|
||||
}
|
||||
|
||||
public function mult()
|
||||
{
|
||||
}
|
||||
|
||||
public function div()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public function setImaginary($imaginary) {
|
||||
$this->imaginary = $imaginary;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
<?php
|
||||
|
||||
class Number
|
||||
{
|
||||
public static function getType($number)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,43 @@
|
|||
abstract class NumberType {
|
||||
INTEGER = 1;
|
||||
NATURAL = 21;
|
||||
EVEN = 211;
|
||||
UNEVEN = 212;
|
||||
PRIME = 22;
|
||||
REAL = 3;
|
||||
RATIONAL = 4;
|
||||
IRRATIONAL = 5;
|
||||
COMPLEX = 6;
|
||||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\Math\Number;
|
||||
|
||||
use phpOMS\Datatypes\Enum;
|
||||
|
||||
/**
|
||||
* Number type enum.
|
||||
*
|
||||
* @category Framework
|
||||
* @package Utils
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
abstract class AccountType extends Enum
|
||||
{
|
||||
const INTEGER = 1;
|
||||
const NATURAL = 21;
|
||||
const EVEN = 211;
|
||||
const UNEVEN = 212;
|
||||
const PRIME = 22;
|
||||
const REAL = 3;
|
||||
const RATIONAL = 4;
|
||||
const IRRATIONAL = 5;
|
||||
const COMPLEX = 6;
|
||||
}
|
||||
|
|
@ -1,16 +1,102 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright 2013 Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
namespace phpOMS\Math\Number;
|
||||
|
||||
interface NumberInterface
|
||||
/**
|
||||
* Basic operation interface.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\Account
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
interface OperationInterface
|
||||
{
|
||||
public function add($number);
|
||||
/**
|
||||
* Add value.
|
||||
*
|
||||
* @param mixed $x Value
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function add($x);
|
||||
|
||||
public function sub($number);
|
||||
/**
|
||||
* Subtract value.
|
||||
*
|
||||
* @param mixed $x Value
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function sub($x);
|
||||
|
||||
public function mult($number);
|
||||
/**
|
||||
* Right multiplicate value.
|
||||
*
|
||||
* @param mixed $x Value
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function mult($x);
|
||||
|
||||
public function div($number);
|
||||
/**
|
||||
* Right devision value.
|
||||
*
|
||||
* @param mixed $x Value
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function div($x);
|
||||
|
||||
/**
|
||||
* Power of value.
|
||||
*
|
||||
* @param mixed $p Power
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function pow($p);
|
||||
|
||||
public function abs($number);
|
||||
/**
|
||||
* Abs of value.
|
||||
*
|
||||
* @param mixed $x Value
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function abs($x);
|
||||
}
|
||||
|
|
@ -60,6 +60,25 @@ class Average
|
|||
return $avg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Average change.
|
||||
*
|
||||
* @param array $x Dataset
|
||||
* @param int $h Future steps
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @throws
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function averageChange(array $x, int $h = 1) : float
|
||||
{
|
||||
$count = count($x);
|
||||
|
||||
return $x[$count - 1] + $h * ($x[$count - 1] - $x[0]) / ($count - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the mode.
|
||||
|
|
@ -104,7 +123,7 @@ class Average
|
|||
} else {
|
||||
$low = $values[$middleval];
|
||||
$high = $values[$middleval + 1];
|
||||
$median = (($low + $high) / 2);
|
||||
$median = ($low + $high) / 2;
|
||||
}
|
||||
|
||||
return $median;
|
||||
|
|
|
|||
0
Math/Statistic/Forecasts.php
Normal file
0
Math/Statistic/Forecasts.php
Normal file
|
|
@ -80,7 +80,7 @@ class MeasureOfDispersion
|
|||
$sum += $value - $mean;
|
||||
}
|
||||
|
||||
return $sum / $count;
|
||||
return $sum / ($count - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -204,6 +204,89 @@ class MeasureOfDispersion
|
|||
*/
|
||||
public static function bravaisPersonCorrelationcoefficient(array $x, array $y) : float
|
||||
{
|
||||
return self::empiricalCovariance($x, $y) / sqrt(self::empiricalCovariance($x, $x) * self::empiricalCovariance($y, $y));
|
||||
return self::empiricalCovariance($x, $y) / (self::standardDeviation($x) * self::standardDeviation($y));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get interquartile range.
|
||||
*
|
||||
* @param array $x Dataset
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getIQR(array $x) : float
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mean deviation.
|
||||
*
|
||||
* @param array $x Values
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function meanDeviation(array $x) : float
|
||||
{
|
||||
$mean = Average::arithmeticMean($x);
|
||||
$sum = 0.0;
|
||||
|
||||
foreach ($x as $xi) {
|
||||
$sum += ($xi - $mean);
|
||||
}
|
||||
|
||||
return $sum / count($x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get squared mean deviation.
|
||||
*
|
||||
* @param array $x Values
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function squaredMeanDeviation(array $x) : float
|
||||
{
|
||||
$mean = Average::arithmeticMean($x);
|
||||
$sum = 0.0;
|
||||
|
||||
foreach ($x as $xi) {
|
||||
$sum += ($xi - $mean) ** 2;
|
||||
}
|
||||
|
||||
return $sum / count($x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the autocorrelation coefficient (ACF).
|
||||
*
|
||||
* @param array $x Dataset
|
||||
* @param int $k k-th coefficient
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function autocorrelationCoefficient(array $x, int $k = 0) : float
|
||||
{
|
||||
$squaredMeanDeviation = self::squaredMeanDeviation($x);
|
||||
$mean = Average::arithmeticMean($x);
|
||||
$count = count($x);
|
||||
$sum = 0.0;
|
||||
|
||||
for ($i = $k + 1; $i < $count; $i++) {
|
||||
$sum += ($x[$i] - $mean) * ($x[$i - $k] - $mean);
|
||||
}
|
||||
|
||||
return $sum / ($squaredMeanDeviation * count($x));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -182,9 +182,4 @@ class UniformDistributionContinuous
|
|||
{
|
||||
return 1 / 12 * ($b - $a) ** 2;
|
||||
}
|
||||
|
||||
public static function getRandom()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -168,6 +168,9 @@ class Header extends HeaderAbstract
|
|||
case RequestStatus::R_403:
|
||||
$this->generate403();
|
||||
break;
|
||||
case RequestStatus::R_404:
|
||||
$this->generate404();
|
||||
break;
|
||||
case RequestStatus::R_406:
|
||||
$this->generate406();
|
||||
break;
|
||||
|
|
@ -182,6 +185,18 @@ class Header extends HeaderAbstract
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get status code.
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getStatusCode() : int {
|
||||
return http_response_code();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate predefined header.
|
||||
*
|
||||
|
|
@ -194,6 +209,22 @@ class Header extends HeaderAbstract
|
|||
{
|
||||
$this->set('HTTP', 'HTTP/1.0 403 Forbidden');
|
||||
$this->set('Status', 'Status: HTTP/1.0 403 Forbidden');
|
||||
http_response_code(403);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate predefined header.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
private function generate404()
|
||||
{
|
||||
$this->set('HTTP', 'HTTP/1.0 404 Not Found');
|
||||
$this->set('Status', 'Status: HTTP/1.0 404 Not Found');
|
||||
http_response_code(404);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -208,6 +239,7 @@ class Header extends HeaderAbstract
|
|||
{
|
||||
$this->set('HTTP', 'HTTP/1.0 406 Not acceptable');
|
||||
$this->set('Status', 'Status: 406 Not acceptable');
|
||||
http_response_code(406);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -223,6 +255,7 @@ class Header extends HeaderAbstract
|
|||
$this->set('HTTP', 'HTTP/1.0 503 Service Temporarily Unavailable');
|
||||
$this->set('Status', 'Status: 503 Service Temporarily Unavailable');
|
||||
$this->set('Retry-After', 'Retry-After: 300');
|
||||
http_response_code(503);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -122,6 +122,7 @@ abstract class ResponseAbstract implements MessageInterface
|
|||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* todo: shouldn't this only be available in the header?!
|
||||
*/
|
||||
public function setStatusCode(string $status)
|
||||
{
|
||||
|
|
@ -131,6 +132,7 @@ abstract class ResponseAbstract implements MessageInterface
|
|||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* todo: shouldn't this only be available in the header?!
|
||||
*/
|
||||
public function getStatusCode() : string
|
||||
{
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
* @link http://orange-management.com
|
||||
*/
|
||||
namespace phpOMS\System\File;
|
||||
|
||||
use phpOMS\Validation\Validator;
|
||||
|
||||
/**
|
||||
|
|
@ -159,7 +160,7 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
|
|||
* Create directory.
|
||||
*
|
||||
* @param string $path Path
|
||||
* @param int $permission Directory permission
|
||||
* @param string $permission Directory permission
|
||||
* @param bool $recursive Create parent directories if applicable
|
||||
*
|
||||
* @return bool
|
||||
|
|
@ -167,7 +168,7 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function createPath(string $path, int $permission = 0644, bool $recursive = false) : bool
|
||||
public static function createPath(string $path, string $permission = '0644', bool $recursive = false) : bool
|
||||
{
|
||||
if ($recursive && !file_exists($parent = self::getParent($path))) {
|
||||
self::createPath($parent, $permission, $recursive);
|
||||
|
|
|
|||
|
|
@ -44,6 +44,14 @@ class Author
|
|||
*/
|
||||
private $email = '';
|
||||
|
||||
/**
|
||||
* Commit count.
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $commitCount = 0;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
|
|
@ -55,8 +63,8 @@ class Author
|
|||
*/
|
||||
public function __construct(string $name = '', string $email = '')
|
||||
{
|
||||
$this->name = escapeshellarg($name);
|
||||
$this->email = escapeshellarg($email);
|
||||
$this->name = $name;
|
||||
$this->email = $email;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -84,4 +92,32 @@ class Author
|
|||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set commit count
|
||||
*
|
||||
* @param int $count Commit count
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function setCommitCount(int $count)
|
||||
{
|
||||
$this->commitCount = $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get commit count
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getCommitCount() : int
|
||||
{
|
||||
return $this->commitCount;
|
||||
}
|
||||
}
|
||||
|
|
@ -102,7 +102,7 @@ class Commit
|
|||
*/
|
||||
public function __construct(string $id = '')
|
||||
{
|
||||
$this->id = escapeshellarg($id);
|
||||
$this->id = $id;
|
||||
$this->author = new Author();
|
||||
$this->branch = new Branch();
|
||||
$this->tag = new Tag();
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@
|
|||
*/
|
||||
namespace phpOMS\Utils\Git;
|
||||
|
||||
use phpOMS\Auth\Auth;
|
||||
use phpOMS\System\File\PathException;
|
||||
use phpOMS\Validation\Validator;
|
||||
|
||||
/**
|
||||
* Repository class
|
||||
|
|
@ -73,8 +73,8 @@ class Repository
|
|||
*/
|
||||
public function __construct(string $path)
|
||||
{
|
||||
$this->branch = $this->getActiveBranch();
|
||||
$this->setPath($path);
|
||||
$this->branch = $this->getActiveBranch();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -119,7 +119,7 @@ class Repository
|
|||
|
||||
$this->path = realpath($path);
|
||||
|
||||
if ($this->path === false || !Validator::startsWith($this->path, ROOT_PATH)) {
|
||||
if ($this->path === false) {
|
||||
throw new PathException($path);
|
||||
}
|
||||
|
||||
|
|
@ -178,7 +178,7 @@ class Repository
|
|||
throw new \Exception($stderr);
|
||||
}
|
||||
|
||||
return $this->parseLines($stdout);
|
||||
return $this->parseLines(trim($stdout));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -193,22 +193,20 @@ class Repository
|
|||
*/
|
||||
private function parseLines(string $lines) : array
|
||||
{
|
||||
$lines = preg_replace('/!\\t+/', '|', $lines);
|
||||
$lines = preg_replace('!\s+!', ' ', $lines);
|
||||
$lineArray = preg_split('/\\r\\n|\\r|\\n/', $lines);
|
||||
//$lines = preg_replace('/!\\t+/', '|', $lines);
|
||||
//$lines = preg_replace('!\s+!', ' ', $lines);
|
||||
$lineArray = preg_split('/\r\n|\n|\r/', $lines);
|
||||
$lines = [];
|
||||
|
||||
foreach ($lineArray as $key => $line) {
|
||||
$lineArray[$key] = trim($line, ' |');
|
||||
$temp = trim($line, ' |');
|
||||
|
||||
if (empty($line)) {
|
||||
unset($lineArray[$key]);
|
||||
} else {
|
||||
$lineArray[$key] = $line;
|
||||
if (!empty($temp)) {
|
||||
$lines[] = $temp;
|
||||
}
|
||||
}
|
||||
|
||||
return $lineArray;
|
||||
|
||||
return $lines;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -333,8 +331,8 @@ class Repository
|
|||
/**
|
||||
* Create local branch.
|
||||
*
|
||||
* @param Branch $branch Branch
|
||||
* @param bool $force Force?
|
||||
* @param Branch $branch Branch
|
||||
* @param bool $force Force?
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
|
|
@ -346,12 +344,20 @@ class Repository
|
|||
return implode("\n", $this->run('branch ' . ($force ? '-D' : '-d') . ' ' . $branch->getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all branches.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getBranches() : array
|
||||
{
|
||||
$branches = $this->run('branch');
|
||||
|
||||
foreach ($branches as $key => &$branch) {
|
||||
$branch = trim($branch);
|
||||
$branch = trim($branch, '* ');
|
||||
|
||||
if ($branch === '') {
|
||||
unset($branches[$key]);
|
||||
|
|
@ -361,12 +367,20 @@ class Repository
|
|||
return $branches;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all remote branches.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getBranchesRemote() : array
|
||||
{
|
||||
$branches = $this->run('branch -r');
|
||||
|
||||
foreach ($branches as $key => &$branch) {
|
||||
$branch = trim($branch);
|
||||
$branch = trim($branch, '* ');
|
||||
|
||||
if ($branch === '' || strpos($branch, 'HEAD -> ') !== false) {
|
||||
unset($branches[$key]);
|
||||
|
|
@ -568,16 +582,28 @@ class Repository
|
|||
*
|
||||
* @return Commit
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getCommit(string $commit) : Commit
|
||||
{
|
||||
$commit = escapeshellarg($commit);
|
||||
$lines = $this->run('log show --name-only ' . $commit);
|
||||
$lines = $this->run('show --name-only ' . $commit);
|
||||
$count = count($lines);
|
||||
|
||||
if (empty($lines)) {
|
||||
// todo: return null commit
|
||||
return new Commit();
|
||||
}
|
||||
|
||||
preg_match('/[0-9ABCDEFabcdef]{40}/', $lines[0], $matches);
|
||||
|
||||
if (!isset($matches[0]) || strlen($matches[0]) !== 40) {
|
||||
throw new \Exception('Invalid commit id');
|
||||
}
|
||||
|
||||
$author = explode(':', $lines[1]);
|
||||
$author = explode('<', trim($author[1]));
|
||||
$date = explode(':', $lines[2]);
|
||||
|
|
@ -622,13 +648,50 @@ class Repository
|
|||
$commits = [];
|
||||
|
||||
foreach ($lines as $line) {
|
||||
$count = explode('|', $line);
|
||||
$commits[$count[1]] = $count[0];
|
||||
preg_match('/^[0-9]*/', $line, $matches);
|
||||
|
||||
$commits[substr($line, strlen($matches[0]) + 1)] = (int) $matches[0];
|
||||
}
|
||||
|
||||
return $commits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get contributors.
|
||||
*
|
||||
* @param \DateTime $start Start date
|
||||
* @param \DateTime $end End date
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getContributors(\DateTime $start = null, \DateTime $end = null) : array
|
||||
{
|
||||
if (!isset($start)) {
|
||||
$start = new \DateTime('1970-12-31');
|
||||
}
|
||||
|
||||
if (!isset($end)) {
|
||||
$end = new \DateTime('now');
|
||||
}
|
||||
|
||||
$lines = $this->run('shortlog -s -n --since="' . $start->format('Y-m-d') . '" --before="' . $end->format('Y-m-d') . '" --all');
|
||||
$contributors = [];
|
||||
|
||||
foreach ($lines as $line) {
|
||||
preg_match('/^[0-9]*/', $line, $matches);
|
||||
|
||||
$contributor = new Author(substr($line, strlen($matches[0]) + 1));
|
||||
$contributor->setCommitCount($this->getCommitsCount($start, $end)[$contributor->getName()]);
|
||||
|
||||
$contributors[] = $contributor;
|
||||
}
|
||||
|
||||
return $contributors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get remote.
|
||||
*
|
||||
|
|
@ -691,14 +754,25 @@ class Repository
|
|||
*
|
||||
* @return Commit
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getNewest() : Commit
|
||||
{
|
||||
$lines = $this->run('log --name-status HEAD^..HEAD');
|
||||
$lines = $this->run('log -n 1');
|
||||
|
||||
preg_match('[0-9ABCDEFabcdef]{40}', $lines[0], $matches);
|
||||
if (empty($lines)) {
|
||||
// todo: return nullcommit
|
||||
return new Commit();
|
||||
}
|
||||
|
||||
preg_match('/[0-9ABCDEFabcdef]{40}/', $lines[0], $matches);
|
||||
|
||||
if (!isset($matches[0]) || strlen($matches[0]) !== 40) {
|
||||
throw new \Exception('Invalid commit id');
|
||||
}
|
||||
|
||||
return $this->getCommit($matches[0]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ namespace phpOMS\Utils\TaskSchedule;
|
|||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class CronJob extends TaskAbstract
|
||||
class CronJob extends TaskAbstract implements \Serializable
|
||||
{
|
||||
|
||||
/**
|
||||
|
|
@ -49,7 +49,15 @@ class CronJob extends TaskAbstract
|
|||
$this->command = $cmd;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
/**
|
||||
* Serialize cronjob.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function serialize()
|
||||
{
|
||||
$minute = $this->printValue($this->interval->getMinute());
|
||||
$hour = $this->printValue($this->interval->getHour());
|
||||
|
|
@ -60,6 +68,16 @@ class CronJob extends TaskAbstract
|
|||
return $minute . ' ' . $hour . ' ' . $dayOfMonth . ' ' . $month . ' ' . $dayOfWeek . ' ' . $this->command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print value.
|
||||
*
|
||||
* @param array $value Element to serialize
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
private function printValue(array $value) : string
|
||||
{
|
||||
if (($count = count($value['dayOfWeek'])) > 0) {
|
||||
|
|
@ -78,4 +96,17 @@ class CronJob extends TaskAbstract
|
|||
|
||||
return $parsed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unserialize cronjob.
|
||||
*
|
||||
* @param string $serialized To unserialize
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function unserialize($serialized)
|
||||
{
|
||||
// TODO: Implement unserialize() method.
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ namespace phpOMS\Utils\TaskSchedule;
|
|||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Schedule extends TaskAbstract
|
||||
class Schedule extends TaskAbstract implements \Serializable
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
|
|
@ -48,8 +48,28 @@ class Schedule extends TaskAbstract
|
|||
$this->command = $cmd;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
/**
|
||||
* String representation of object
|
||||
* @link http://php.net/manual/en/serializable.serialize.php
|
||||
* @return string the string representation of the object or null
|
||||
* @since 5.1.0
|
||||
*/
|
||||
public function serialize()
|
||||
{
|
||||
return '';
|
||||
// TODO: Implement serialize() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the object
|
||||
* @link http://php.net/manual/en/serializable.unserialize.php
|
||||
* @param string $serialized <p>
|
||||
* The string representation of the object.
|
||||
* </p>
|
||||
* @return void
|
||||
* @since 5.1.0
|
||||
*/
|
||||
public function unserialize($serialized)
|
||||
{
|
||||
// TODO: Implement unserialize() method.
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user