mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 09:48:40 +00:00
Re-naming and moving
This commit is contained in:
parent
24371cf5fd
commit
1892f33f68
1
.github/contributing.md
vendored
Normal file
1
.github/contributing.md
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
A developer and contribution documentation can be found at https://orange-management.gitbooks.io/developer-guide/content/index.html.
|
||||
119
Math/Statistic/Correlation.php
Normal file
119
Math/Statistic/Correlation.php
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
<?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\Statistic;
|
||||
|
||||
/**
|
||||
* Correlation.
|
||||
*
|
||||
* @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 Correlation
|
||||
{
|
||||
|
||||
/**
|
||||
* Calculage bravais person correlation coefficient.
|
||||
*
|
||||
* Example: ([4, 5, 9, 1, 3], [4, 5, 9, 1, 3])
|
||||
*
|
||||
* @param array $x Values
|
||||
* @param array $y Values
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function bravaisPersonCorrelationCoefficient(array $x, array $y) : float
|
||||
{
|
||||
return MeasureOfDispersion::empiricalCovariance($x, $y) / (MeasureOfDispersion::standardDeviation($x) * MeasureOfDispersion::standardDeviation($y));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 = MeasureOfDispersion::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));
|
||||
}
|
||||
|
||||
/**
|
||||
* Box Pierce test (portmanteau test).
|
||||
*
|
||||
* @param array $autocorrelations Autocorrelations
|
||||
* @param int $h Maximum leg considered
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function boxPierceTest(array $autocorrelations, int $h) : float
|
||||
{
|
||||
$sum = 0;
|
||||
for ($i = 0; $i < $h; $i++) {
|
||||
$sum += $autocorrelations[$i] ** 2;
|
||||
}
|
||||
|
||||
return count($autocorrelations) * $sum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Box Pierce test (portmanteau test).
|
||||
*
|
||||
* @param array $autocorrelations Autocorrelations
|
||||
* @param int $h Maximum leg considered
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function ljungBoxTest(array $autocorrelations, int $h) : float
|
||||
{
|
||||
$count = count($autocorrelations);
|
||||
$sum = 0;
|
||||
|
||||
for ($i = 0; $i < $h; $i++) {
|
||||
$sum += 1 / ($count - $i) * $autocorrelations[$i] ** 2;
|
||||
}
|
||||
|
||||
return $count * ($count + 2) * $sum;
|
||||
}
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\Math\Forecast;
|
||||
namespace phpOMS\Math\Statistic\Forecast;
|
||||
|
||||
use phpOMS\Math\Functions;
|
||||
use phpOMS\Math\Statistic\Average;
|
||||
46
Math/Statistic/Forecast/ForecastIntervalMultiplier.php
Normal file
46
Math/Statistic/Forecast/ForecastIntervalMultiplier.php
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<?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\Statistic\Forecast;
|
||||
use phpOMS\Datatypes\Enum;
|
||||
|
||||
/**
|
||||
* Address type enum.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\Datatypes
|
||||
* @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 ForecastIntervalMultiplier extends Enum
|
||||
{
|
||||
const P_50 = 0.67;
|
||||
const P_55 = 0.76;
|
||||
const P_60 = 0.84;
|
||||
const P_65 = 0.93;
|
||||
const P_70 = 1.04;
|
||||
const P_75 = 1.15;
|
||||
const P_80 = 1.28;
|
||||
const P_85 = 1.44;
|
||||
const P_90 = 1.64;
|
||||
const P_95 = 1.96;
|
||||
const P_96 = 2.05;
|
||||
const P_97 = 2.17;
|
||||
const P_98 = 2.33;
|
||||
const P_99 = 2.58;
|
||||
}
|
||||
48
Math/Statistic/Forecast/Forecasts.php
Normal file
48
Math/Statistic/Forecast/Forecasts.php
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?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\Statistic\Forecast;
|
||||
|
||||
/**
|
||||
* Address type enum.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\Datatypes
|
||||
* @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 Forecast
|
||||
{
|
||||
/**
|
||||
* Get forecast interval.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param array $observed Dataset
|
||||
* @param array $forecasted Forecasted
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getForecastInteval(float $forecast, float $standardDeviation, float $interval = ForecastIntervalMultiplier::P_95) : array
|
||||
{
|
||||
return [$forecast - $interval * $standardDeviation, $forecast + $interval * $standardDeviation];
|
||||
}
|
||||
}
|
||||
185
Math/Statistic/Forecast/LinearRegression.php
Normal file
185
Math/Statistic/Forecast/LinearRegression.php
Normal file
|
|
@ -0,0 +1,185 @@
|
|||
<?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\Statistic;
|
||||
|
||||
use phpOMS\Math\Statistic\Average;
|
||||
use phpOMS\Math\Statistic\Forecast\ForecastIntervalMultiplier;
|
||||
use phpOMS\Math\Statistic\MeasureOfDispersion;
|
||||
|
||||
/**
|
||||
* Regression class.
|
||||
*
|
||||
* @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 LinearRegression
|
||||
{
|
||||
/**
|
||||
* Get linear regression based on scatter plot.
|
||||
*
|
||||
* y = b0 + b1 * x
|
||||
*
|
||||
* @param array $x Obersved x values
|
||||
* @param array $y Observed y values
|
||||
*
|
||||
* @return array [b0 => ?, b1 => ?]
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getLinearRegresseion(array $x, array $y) : array
|
||||
{
|
||||
$b1 = self::getBeta1($x, $y);
|
||||
|
||||
return ['b0' => self::getBeta0($x, $y, $b1), 'b1' => $b1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get linear regression parameter beta 1.
|
||||
*
|
||||
* @param array $x Obersved x values
|
||||
* @param array $y Observed y values
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
private static function getBeta1(array $x, array $y) : float
|
||||
{
|
||||
$count = count($x);
|
||||
$meanX = Average::arithmeticMean($x);
|
||||
$meanY = Average::arithmeticMean($y);
|
||||
|
||||
$sum1 = 0;
|
||||
$sum2 = 0;
|
||||
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$sum1 += ($y[$i] - $meanY) * ($x[$i] - $meanX);
|
||||
$sum2 += ($x[$i] - $meanX) ** 2;
|
||||
}
|
||||
|
||||
return $sum1 / $sum2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get linear regression parameter beta 0.
|
||||
*
|
||||
* @param array $x Obersved x values
|
||||
* @param array $y Observed y values
|
||||
* @param float $b1 Beta 1
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
private static function getBeta0(array $x, array $y, float $b1) : float
|
||||
{
|
||||
return Average::arithmeticMean($y) - $b1 * Average::arithmeticMean($x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Goodness of fit.
|
||||
*
|
||||
* Evaluating how well the observed data fit the linear regression model
|
||||
*
|
||||
* @param array $observed Obersved y values
|
||||
* @param array $forecasted Forecasted y values
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getGoodnessOfFit(array $observed, array $forecasted) : float
|
||||
{
|
||||
$countO = count($observed);
|
||||
$countF = count($forecasted);
|
||||
$sum1 = 0;
|
||||
$sum2 = 0;
|
||||
$meanY = Average::arithmeticMean($observed);
|
||||
|
||||
for ($i = 0; $i < $countF; $i++) {
|
||||
$sum1 += ($forecasted[$i] - $meanY) ** 2;
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $countO; $i++) {
|
||||
$sum2 += ($observed[$i] - $meanY) ** 2;
|
||||
}
|
||||
|
||||
return $sum1 / $sum2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Standard error of the regression.
|
||||
*
|
||||
* Used in order to evaluate the performance of the linear regression
|
||||
*
|
||||
* @param array $errors Errors (e = y - y_forecasted)
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getStandardErrorOfRegression(array $errors) : float
|
||||
{
|
||||
$count = count($errors);
|
||||
$sum = 0.0;
|
||||
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$sum += $errors[$i] ** 2;
|
||||
}
|
||||
|
||||
// todo: could this be - 1 depending on the different definitions?!
|
||||
return sqrt(1 / ($count - 2) * $sum);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get predictional interval for linear regression.
|
||||
*
|
||||
* @param float $forecasted Forecasted y value
|
||||
* @param array $x observex x values
|
||||
* @param array $errors Errors for y values (y - y_forecasted)
|
||||
* @param float $multiplier Multiplier for interval
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getPredictionInterval(float $forecasted, array $x, array $errors, float $multiplier = ForecastIntervalMultiplier::P_95) : array
|
||||
{
|
||||
$count = count($x);
|
||||
$meanX = Average::arithmeticMean($x);
|
||||
$sum = 0.0;
|
||||
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$sum += ($x[$i] - $meanX) ** 2;
|
||||
}
|
||||
|
||||
$interval = $multiplier * self::getStandardErrorOfRegression($errors) * sqrt(1 + 1 / $count + $sum / (($count - 1) * MeasureOfDispersion::standardDeviation($x) ** 2));
|
||||
|
||||
return [$forecasted - $interval, $forecasted + $interval];
|
||||
}
|
||||
}
|
||||
|
|
@ -189,24 +189,6 @@ class MeasureOfDispersion
|
|||
return $sum / ($count - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculage bravais person correlation coefficient.
|
||||
*
|
||||
* Example: ([4, 5, 9, 1, 3], [4, 5, 9, 1, 3])
|
||||
*
|
||||
* @param array $x Values
|
||||
* @param array $y Values
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function bravaisPersonCorrelationcoefficient(array $x, array $y) : float
|
||||
{
|
||||
return self::empiricalCovariance($x, $y) / (self::standardDeviation($x) * self::standardDeviation($y));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get interquartile range.
|
||||
*
|
||||
|
|
@ -265,28 +247,4 @@ class MeasureOfDispersion
|
|||
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));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,11 +89,11 @@ class LZW implements CompressionInterface
|
|||
if ($dictionary[$k]) {
|
||||
$entry = $dictionary[$k];
|
||||
} else {
|
||||
if ($k === $dictSize) {
|
||||
$entry = $w . $w[0];
|
||||
} else {
|
||||
if ($k !== $dictSize) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$entry = $w . $w[0];
|
||||
}
|
||||
|
||||
$result .= $entry;
|
||||
|
|
|
|||
|
|
@ -54,11 +54,11 @@ class File
|
|||
if ($bytes < 1000) {
|
||||
return $bytes . 'b';
|
||||
} elseif ($bytes > 999 && $bytes < 1000000) {
|
||||
return $bytes / 1000 . 'kb';
|
||||
return ((float) number_format($bytes / 1000, 1)) . 'kb';
|
||||
} elseif ($bytes > 999999 && $bytes < 1000000000) {
|
||||
return $bytes / 1000000 . 'mb';
|
||||
return ((float) number_format($bytes / 1000000, 1)) . 'mb';
|
||||
} else {
|
||||
return $bytes / 1000000000 . 'gb';
|
||||
return ((float) number_format($bytes / 1000000000, 1)) . 'gb';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -75,11 +75,11 @@ class File
|
|||
public static function kilobyteSizeToString(int $kilobytes) : string
|
||||
{
|
||||
if ($kilobytes < 1000) {
|
||||
return round($kilobytes, 2) . 'kb';
|
||||
return ((float) number_format($kilobytes, 1)) . 'kb';
|
||||
} elseif ($kilobytes > 999 && $kilobytes < 1000000) {
|
||||
return round($kilobytes / 1000, 2) . 'mb';
|
||||
return ((float) number_format($kilobytes / 1000, 1)) . 'mb';
|
||||
} else {
|
||||
return round($kilobytes / 1000000, 2) . 'gb';
|
||||
return ((float) number_format($kilobytes / 1000000, 1)) . 'gb';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,11 +38,14 @@ class Measurement
|
|||
*
|
||||
* @return float
|
||||
*
|
||||
* @todo: implement more
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function convertTemperature(float $value, string $from, string $to) : float
|
||||
public static function convertTemperature(float $value, string $from = TemperatureType::FAHRENHEIT, string $to = TemperatureType::CELSIUS) : float
|
||||
{
|
||||
// to celving
|
||||
switch ($from) {
|
||||
case TemperatureType::CELSIUS:
|
||||
$value += 273.15;
|
||||
|
|
@ -77,4 +80,204 @@ class Measurement
|
|||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert weight.
|
||||
*
|
||||
* @param float $value Value to convert
|
||||
* @param string $from Input weight
|
||||
* @param string $to Output weight
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @todo: implement more
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function convertWeight(float $value, string $from = WeightType::GRAM, string $to = WeightType::KILOGRAM) : float
|
||||
{
|
||||
// to gram
|
||||
switch ($from) {
|
||||
case WeightType::MILLIGRAM:
|
||||
$value /= 1000;
|
||||
break;
|
||||
case WeightType::GRAM:
|
||||
break;
|
||||
case WeightType::KILOGRAM:
|
||||
$value *= 1000;
|
||||
break;
|
||||
case WeightType::TONS:
|
||||
$value *= 1000000;
|
||||
break;
|
||||
case WeightType::STONES:
|
||||
$value /= 0.15747 * 1000;
|
||||
break;
|
||||
case WeightType::OUNCES:
|
||||
$value /= 0.035274;
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException('Weight not supported');
|
||||
}
|
||||
|
||||
switch ($to) {
|
||||
case WeightType::MILLIGRAM:
|
||||
$value *= 1000;
|
||||
break;
|
||||
case WeightType::GRAM:
|
||||
break;
|
||||
case WeightType::KILOGRAM:
|
||||
$value /= 1000;
|
||||
break;
|
||||
case WeightType::TONS:
|
||||
$value /= 1000000;
|
||||
break;
|
||||
case WeightType::STONES:
|
||||
$value *= 0.15747 * 1000;
|
||||
break;
|
||||
case WeightType::OUNCES:
|
||||
$value *= 0.035274;
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException('Weight not supported');
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert length.
|
||||
*
|
||||
* @param float $value Value to convert
|
||||
* @param string $from Input weight
|
||||
* @param string $to Output weight
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function convertLength(float $value, string $from = WeightType::GRAM, string $to = WeightType::KILOGRAM) : float
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert area.
|
||||
*
|
||||
* @param float $value Value to convert
|
||||
* @param string $from Input weight
|
||||
* @param string $to Output weight
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function convertArea(float $value, string $from = WeightType::GRAM, string $to = WeightType::KILOGRAM) : float
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert volume.
|
||||
*
|
||||
* @param float $value Value to convert
|
||||
* @param string $from Input weight
|
||||
* @param string $to Output weight
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function convertVolume(float $value, string $from = WeightType::GRAM, string $to = WeightType::KILOGRAM) : float
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert speed.
|
||||
*
|
||||
* @param float $value Value to convert
|
||||
* @param string $from Input weight
|
||||
* @param string $to Output weight
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function convertSpeed(float $value, string $from = WeightType::GRAM, string $to = WeightType::KILOGRAM) : float
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert speed.
|
||||
*
|
||||
* @param float $value Value to convert
|
||||
* @param string $from Input weight
|
||||
* @param string $to Output weight
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function convertTime(float $value, string $from = WeightType::GRAM, string $to = WeightType::KILOGRAM) : float
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert speed.
|
||||
*
|
||||
* @param float $value Value to convert
|
||||
* @param string $from Input weight
|
||||
* @param string $to Output weight
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function convertAngle(float $value, string $from = WeightType::GRAM, string $to = WeightType::KILOGRAM) : float
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert speed.
|
||||
*
|
||||
* @param float $value Value to convert
|
||||
* @param string $from Input weight
|
||||
* @param string $to Output weight
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function convertPressure(float $value, string $from = WeightType::GRAM, string $to = WeightType::KILOGRAM) : float
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert speed.
|
||||
*
|
||||
* @param float $value Value to convert
|
||||
* @param string $from Input weight
|
||||
* @param string $to Output weight
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function convertEnergie(float $value, string $from = WeightType::GRAM, string $to = WeightType::KILOGRAM) : float
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
40
Utils/Converter/WeightType.php
Normal file
40
Utils/Converter/WeightType.php
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?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\Utils\Converter;
|
||||
|
||||
use phpOMS\Datatypes\Enum;
|
||||
|
||||
/**
|
||||
* Weight type enum.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\Utils\Converter
|
||||
* @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 WeightType extends Enum
|
||||
{
|
||||
const MILLIGRAM = 'mg';
|
||||
const GRAM = 'g';
|
||||
const KILOGRAM = 'kg';
|
||||
const TONS = 't';
|
||||
const POUNDS = 'lb';
|
||||
const OUNCES = 'oz';
|
||||
const STONES = 'st';
|
||||
}
|
||||
|
|
@ -26,7 +26,7 @@ namespace phpOMS\Utils;
|
|||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class JsonBuilder
|
||||
class JsonBuilder implements \Serializable
|
||||
{
|
||||
|
||||
/**
|
||||
|
|
@ -64,7 +64,7 @@ class JsonBuilder
|
|||
* Add data.
|
||||
*
|
||||
* @param string $path Path used for storage
|
||||
* @param array $value Data to add
|
||||
* @param mixed $value Data to add
|
||||
* @param bool $overwrite Should overwrite existing data
|
||||
*
|
||||
* @return void
|
||||
|
|
@ -72,7 +72,7 @@ class JsonBuilder
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn
|
||||
*/
|
||||
public function add(string $path, array $value, bool $overwrite = true)
|
||||
public function add(string $path, $value, bool $overwrite = true)
|
||||
{
|
||||
$this->json = ArrayUtils::setArray($path, $this->json, $value, '/', $overwrite);
|
||||
}
|
||||
|
|
@ -81,28 +81,39 @@ class JsonBuilder
|
|||
* Remove data.
|
||||
*
|
||||
* @param string $path Path to the element to delete
|
||||
* @param string $delim Delim used inside path
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn
|
||||
*/
|
||||
public function remove(string $path, string $delim)
|
||||
public function remove(string $path)
|
||||
{
|
||||
$this->json = ArrayUtils::unsetArray($path, $this->json, $delim);
|
||||
$this->json = ArrayUtils::unsetArray($path, $this->json, '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get json string.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn
|
||||
* 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 __toString()
|
||||
public function serialize()
|
||||
{
|
||||
return json_encode($this->json);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
$this->json = json_decode($serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
0
Utils/Parser/LaTex/Expressions/Product.php
Normal file
0
Utils/Parser/LaTex/Expressions/Product.php
Normal file
0
Utils/Parser/LaTex/Expressions/Sum.php
Normal file
0
Utils/Parser/LaTex/Expressions/Sum.php
Normal file
0
Utils/Parser/LaTex/Expressions/Trigonometry.php
Normal file
0
Utils/Parser/LaTex/Expressions/Trigonometry.php
Normal file
0
Utils/Parser/LaTex/LaTexParser.php
Normal file
0
Utils/Parser/LaTex/LaTexParser.php
Normal file
0
Utils/Parser/LaTex/Types/Function.php
Normal file
0
Utils/Parser/LaTex/Types/Function.php
Normal file
0
Utils/Parser/LaTex/Types/Interval.php
Normal file
0
Utils/Parser/LaTex/Types/Interval.php
Normal file
0
Utils/Parser/LaTex/Types/Variable.php
Normal file
0
Utils/Parser/LaTex/Types/Variable.php
Normal file
|
|
@ -108,11 +108,13 @@ class Permutation
|
|||
public static function permutate($toPermute, array $key)
|
||||
{
|
||||
if (!is_array($toPermute) || !is_string($toPermute)) {
|
||||
throw new \Exception();
|
||||
throw new \InvalidArgumentException('Parameter has to be array or string');
|
||||
}
|
||||
|
||||
if (count($key) > strlen($toPermute)) {
|
||||
throw new \Exception();
|
||||
$length = is_array($toPermute) ? count($toPermute) : strlen($toPermute);
|
||||
|
||||
if (count($key) > $length) {
|
||||
throw new \InvalidArgumentException('There mustn not be more keys than permutation elements.');
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user