fix: revert removal of distribution methods

This commit is contained in:
Marvin Flock
2025-04-22 19:16:56 +02:00
parent 021283fe7e
commit c246328540
2 changed files with 34 additions and 7 deletions
@@ -209,10 +209,10 @@ class MathParser
/** /**
* Public for performance reasons. * Public for performance reasons.
* @see getVariableResolver function for more info. * @see getVariableResolver function for more info.
* @var string * @var string|null
* @since 1.0.0 * @since 1.0.0
*/ */
public string $VariableResolver; public ?string $VariableResolver = null;
/** /**
* @ignore * @ignore
@@ -325,10 +325,10 @@ class MathParser
* the problem domain is too big to define the variables ahead of time. In such cases, it makes sense * the problem domain is too big to define the variables ahead of time. In such cases, it makes sense
* to parse with the assumption that it is a valid variable and resolve it's value when needed on demand during * to parse with the assumption that it is a valid variable and resolve it's value when needed on demand during
* evaluation. * evaluation.
* @return string * @return string|null
* @since 1.0.0 * @since 1.0.0
*/ */
public function getVariableResolver(): string public function getVariableResolver(): ?string
{ {
return $this->VariableResolver; return $this->VariableResolver;
} }
@@ -493,7 +493,7 @@ class MathParser
throw new Exception($this->getMessage1("NtVarNm", $varName)); throw new Exception($this->getMessage1("NtVarNm", $varName));
} }
//create the variable: //create the variable:
$var = new Mathparser_Variable($upcName, $newVal, $fn_valueProvider); $var = new Mathparser_Variable($this, $upcName, $newVal, $fn_valueProvider);
$this->Variables[$upcName] = $var; $this->Variables[$upcName] = $var;
$this->Dirty = true; $this->Dirty = true;
} }
@@ -1824,6 +1824,12 @@ class MathParser
class Mathparser_Variable class Mathparser_Variable
{ {
/**
* The parent parser instance, used to call the VariableResolver if needed.
* @since 1.0.0
*/
private $Parser;
/** /**
* Name of this variable. * Name of this variable.
* @since 1.0.0 * @since 1.0.0
@@ -1843,10 +1849,21 @@ class Mathparser_Variable
* <br /><br /> function VariableResolver($parser, $varName);<br /><br /> * <br /><br /> function VariableResolver($parser, $varName);<br /><br />
* @since 1.0.0 * @since 1.0.0
*/ */
public string $ValueProvider; public $ValueProvider;
public function __construct($aName, $newVal, $valueProvider) /**
* If the $this->ValueProvider is set, then this method uses it to get the runtime value.
* Otherwise, this method returns the value of $this->Value;
* @since 1.0.0
* @noinspection PhpUnused
*/
public function getRuntimeValue(){
return !is_callable($this->ValueProvider) ? $this->Value : ($this->ValueProvider)($this->Parser, $this->Name);
}
public function __construct($parser, $aName, $newVal, $valueProvider)
{ {
$this->Parser = $parser;
$this->Name = $aName; $this->Name = $aName;
$this->Value = $newVal; $this->Value = $newVal;
$this->ValueProvider = $valueProvider; $this->ValueProvider = $valueProvider;
@@ -18,6 +18,16 @@ defined('_JEXEC') or die('Restricted access');
require_once JPATH_SITE . '/components/com_sportsmanager/mathparser.php'; require_once JPATH_SITE . '/components/com_sportsmanager/mathparser.php';
require_once JPATH_SITE . '/components/com_sportsmanager/database/init.php'; require_once JPATH_SITE . '/components/com_sportsmanager/database/init.php';
/** @noinspection PhpUnused */
function mathParserVerteilung($rohpunkte, $platz, $teilnehmer, $multiplikator) {
return max(round($multiplikator * round(((($rohpunkte - 1) * (-log($platz / $teilnehmer) * (1 - ($platz / $teilnehmer)))) / (-log(1 / $teilnehmer) * (1 - (1 / $teilnehmer)))) + 1)), 1);
}
/** @noinspection PhpUnused */
function mathParserVerteilungR($rohpunkte, $platz, $teilnehmer, $multiplikator) {
return max(round(((($multiplikator * $rohpunkte - 1) * (-log($platz / $teilnehmer) * (1 - ($platz / $teilnehmer)))) / (-log(1 / $teilnehmer) * (1 - (1 / $teilnehmer)))) + 1), 1);
}
class MathParserSM extends MathParser class MathParserSM extends MathParser
{ {
// Verteilung nach Klostermann/Wahle // Verteilung nach Klostermann/Wahle