1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

In charts, make "min" and "max" into pure functions and formally mark pure functions as pure

Summary:
Depends on D20814. Currently, "min()" and "max()" are still "min(f, n)". This is no longer consistent with the construction of functions a function-generators that are composed at top level.

Turn them into "min(n)" and "max(n)" (i.e., not higher-order functions).

Then, mark all the functions which are pure mathematical functions and not higher-order as "pure". These functions have no function parameters and do not reference external data. For now, this distinction has no immediate implications, but it will simplify the next change (which tracks where data came from when it originated from an external source -- these pure functions never have any source information, since they only apply pure mathematical transformations to data).

Test Plan: Loaded a burnup chart, nothing seemed obviously broken.

Subscribers: yelirekim

Differential Revision: https://secure.phabricator.com/D20815
This commit is contained in:
epriestley 2019-09-16 11:34:25 -07:00
parent f529abf900
commit 769e745a3f
10 changed files with 48 additions and 52 deletions

View file

@ -4422,6 +4422,7 @@ phutil_register_library_map(array(
'PhabricatorProjectsWatchersSearchEngineAttachment' => 'applications/project/engineextension/PhabricatorProjectsWatchersSearchEngineAttachment.php',
'PhabricatorPronounSetting' => 'applications/settings/setting/PhabricatorPronounSetting.php',
'PhabricatorProtocolLog' => 'infrastructure/log/PhabricatorProtocolLog.php',
'PhabricatorPureChartFunction' => 'applications/fact/chart/PhabricatorPureChartFunction.php',
'PhabricatorPygmentSetupCheck' => 'applications/config/check/PhabricatorPygmentSetupCheck.php',
'PhabricatorQuery' => 'infrastructure/query/PhabricatorQuery.php',
'PhabricatorQueryConstraint' => 'infrastructure/query/constraint/PhabricatorQueryConstraint.php',
@ -9155,7 +9156,7 @@ phutil_register_library_map(array(
'PhabricatorConpherenceWidgetVisibleSetting' => 'PhabricatorInternalSetting',
'PhabricatorConsoleApplication' => 'PhabricatorApplication',
'PhabricatorConsoleContentSource' => 'PhabricatorContentSource',
'PhabricatorConstantChartFunction' => 'PhabricatorChartFunction',
'PhabricatorConstantChartFunction' => 'PhabricatorPureChartFunction',
'PhabricatorContactNumbersSettingsPanel' => 'PhabricatorSettingsPanel',
'PhabricatorContentSource' => 'Phobject',
'PhabricatorContentSourceModule' => 'PhabricatorConfigModule',
@ -9167,7 +9168,7 @@ phutil_register_library_map(array(
'PhabricatorCoreCreateTransaction' => 'PhabricatorCoreTransactionType',
'PhabricatorCoreTransactionType' => 'PhabricatorModularTransactionType',
'PhabricatorCoreVoidTransaction' => 'PhabricatorModularTransactionType',
'PhabricatorCosChartFunction' => 'PhabricatorChartFunction',
'PhabricatorCosChartFunction' => 'PhabricatorPureChartFunction',
'PhabricatorCountFact' => 'PhabricatorFact',
'PhabricatorCountdown' => array(
'PhabricatorCountdownDAO',
@ -10068,7 +10069,7 @@ phutil_register_library_map(array(
'PhabricatorMarkupInterface',
),
'PhabricatorMarkupPreviewController' => 'PhabricatorController',
'PhabricatorMaxChartFunction' => 'PhabricatorChartFunction',
'PhabricatorMaxChartFunction' => 'PhabricatorPureChartFunction',
'PhabricatorMemeEngine' => 'Phobject',
'PhabricatorMemeRemarkupRule' => 'PhutilRemarkupRule',
'PhabricatorMentionRemarkupRule' => 'PhutilRemarkupRule',
@ -10135,7 +10136,7 @@ phutil_register_library_map(array(
'PhabricatorMetronome' => 'Phobject',
'PhabricatorMetronomeTestCase' => 'PhabricatorTestCase',
'PhabricatorMetronomicTriggerClock' => 'PhabricatorTriggerClock',
'PhabricatorMinChartFunction' => 'PhabricatorChartFunction',
'PhabricatorMinChartFunction' => 'PhabricatorPureChartFunction',
'PhabricatorModularTransaction' => 'PhabricatorApplicationTransaction',
'PhabricatorModularTransactionType' => 'Phobject',
'PhabricatorMonogramDatasourceEngineExtension' => 'PhabricatorDatasourceEngineExtension',
@ -10950,6 +10951,7 @@ phutil_register_library_map(array(
'PhabricatorProjectsWatchersSearchEngineAttachment' => 'PhabricatorSearchEngineAttachment',
'PhabricatorPronounSetting' => 'PhabricatorSelectSetting',
'PhabricatorProtocolLog' => 'Phobject',
'PhabricatorPureChartFunction' => 'PhabricatorChartFunction',
'PhabricatorPygmentSetupCheck' => 'PhabricatorSetupCheck',
'PhabricatorQuery' => 'Phobject',
'PhabricatorQueryConstraint' => 'Phobject',
@ -11208,7 +11210,7 @@ phutil_register_library_map(array(
'PhabricatorPolicyInterface',
),
'PhabricatorSavedQueryQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorScaleChartFunction' => 'PhabricatorChartFunction',
'PhabricatorScaleChartFunction' => 'PhabricatorPureChartFunction',
'PhabricatorScheduleTaskTriggerAction' => 'PhabricatorTriggerAction',
'PhabricatorScopedEnv' => 'Phobject',
'PhabricatorSearchAbstractDocument' => 'Phobject',
@ -11299,12 +11301,12 @@ phutil_register_library_map(array(
'PhabricatorSetupIssue' => 'Phobject',
'PhabricatorSetupIssueUIExample' => 'PhabricatorUIExample',
'PhabricatorSetupIssueView' => 'AphrontView',
'PhabricatorShiftChartFunction' => 'PhabricatorChartFunction',
'PhabricatorShiftChartFunction' => 'PhabricatorPureChartFunction',
'PhabricatorShortSite' => 'PhabricatorSite',
'PhabricatorShowFiletreeSetting' => 'PhabricatorSelectSetting',
'PhabricatorSignDocumentsUserLogType' => 'PhabricatorUserLogType',
'PhabricatorSimpleEditType' => 'PhabricatorEditType',
'PhabricatorSinChartFunction' => 'PhabricatorChartFunction',
'PhabricatorSinChartFunction' => 'PhabricatorPureChartFunction',
'PhabricatorSite' => 'AphrontSite',
'PhabricatorSlackAuthProvider' => 'PhabricatorOAuth2AuthProvider',
'PhabricatorSlowvoteApplication' => 'PhabricatorApplication',

View file

@ -1,7 +1,7 @@
<?php
final class PhabricatorConstantChartFunction
extends PhabricatorChartFunction {
extends PhabricatorPureChartFunction {
const FUNCTIONKEY = 'constant';

View file

@ -1,7 +1,7 @@
<?php
final class PhabricatorCosChartFunction
extends PhabricatorChartFunction {
extends PhabricatorPureChartFunction {
const FUNCTIONKEY = 'cos';

View file

@ -1,36 +1,27 @@
<?php
final class PhabricatorMaxChartFunction
extends PhabricatorChartFunction {
extends PhabricatorPureChartFunction {
const FUNCTIONKEY = 'max';
protected function newArguments() {
return array(
$this->newArgument()
->setName('x')
->setType('function'),
$this->newArgument()
->setName('max')
->setType('number'),
);
}
public function getDomain() {
return $this->getArgument('x')->getDomain();
}
public function newInputValues(PhabricatorChartDataQuery $query) {
return $this->getArgument('x')->newInputValues($query);
}
public function evaluateFunction(array $xv) {
$yv = $this->getArgument('x')->evaluateFunction($xv);
$max = $this->getArgument('max');
foreach ($yv as $k => $y) {
if ($y > $max) {
$yv[$k] = null;
$yv = array();
foreach ($xv as $x) {
if ($x > $max) {
$yv[] = null;
} else {
$yv[] = $x;
}
}

View file

@ -1,36 +1,27 @@
<?php
final class PhabricatorMinChartFunction
extends PhabricatorChartFunction {
extends PhabricatorPureChartFunction {
const FUNCTIONKEY = 'min';
protected function newArguments() {
return array(
$this->newArgument()
->setName('x')
->setType('function'),
$this->newArgument()
->setName('min')
->setType('number'),
);
}
public function getDomain() {
return $this->getArgument('x')->getDomain();
}
public function newInputValues(PhabricatorChartDataQuery $query) {
return $this->getArgument('x')->newInputValues($query);
}
public function evaluateFunction(array $xv) {
$yv = $this->getArgument('x')->evaluateFunction($xv);
$min = $this->getArgument('min');
foreach ($yv as $k => $y) {
if ($y < $min) {
$yv[$k] = null;
$yv = array();
foreach ($xv as $x) {
if ($x < $min) {
$yv[] = null;
} else {
$yv[] = $x;
}
}

View file

@ -0,0 +1,4 @@
<?php
abstract class PhabricatorPureChartFunction
extends PhabricatorChartFunction {}

View file

@ -1,7 +1,7 @@
<?php
final class PhabricatorScaleChartFunction
extends PhabricatorChartFunction {
extends PhabricatorPureChartFunction {
const FUNCTIONKEY = 'scale';

View file

@ -1,7 +1,7 @@
<?php
final class PhabricatorShiftChartFunction
extends PhabricatorChartFunction {
extends PhabricatorPureChartFunction {
const FUNCTIONKEY = 'shift';

View file

@ -1,7 +1,7 @@
<?php
final class PhabricatorSinChartFunction
extends PhabricatorChartFunction {
extends PhabricatorPureChartFunction {
const FUNCTIONKEY = 'sin';

View file

@ -32,12 +32,14 @@ final class PhabricatorProjectBurndownChartEngine
if ($project_phids) {
foreach ($project_phids as $project_phid) {
$function = $this->newFunction(
'min',
array(
'accumulate',
array('fact', 'tasks.open-count.assign.project', $project_phid),
),
0);
array(
'min',
0,
));
$function->getFunctionLabel()
->setName(pht('Tasks Moved Into Project'))
@ -47,12 +49,14 @@ final class PhabricatorProjectBurndownChartEngine
$functions[] = $function;
$function = $this->newFunction(
'min',
array(
'accumulate',
array('fact', 'tasks.open-count.status.project', $project_phid),
),
0);
array(
'min',
0,
));
$function->getFunctionLabel()
->setName(pht('Tasks Reopened'))
@ -68,20 +72,24 @@ final class PhabricatorProjectBurndownChartEngine
array('fact', 'tasks.open-count.create.project', $project_phid),
),
array(
'max',
array(
'accumulate',
array('fact', 'tasks.open-count.status.project', $project_phid),
),
0,
array(
'max',
0,
),
),
array(
'max',
array(
'accumulate',
array('fact', 'tasks.open-count.assign.project', $project_phid),
),
0,
array(
'max',
0,
),
));
$function->getFunctionLabel()