Ruler icon indicating copy to clipboard operation
Ruler copied to clipboard

Produce results in response of rule evaluations

Open jubianchi opened this issue 9 years ago • 10 comments

See #94 for detailed information.

Todo:

  • [x] Implement the Rules collection with an SplPriorityQueue
  • [ ] Use the hoa/heap library for the Rules collection
  • [x] Implement the Then rule class (it returns a result when the rule validates the input)
  • [x] Implement the ThenElse rule class (it returns a result when the rule validates the input and another when the rule does not validate the input)
  • [ ] Implement an algorithm to resolve rules dependencies (indeed, a rule can depend on another one). hoa/graph could be a good candidate for this kind of work.
  • [x] Implement a rule() function to reference the result of one rule from another rule

Some notes about the technical choices:

  • I used some clones in the code: this is to guarantee immutability of the passed objects. For example the Hoa\Ruler\Rules::initializeRuler() may alter the ruler's asserter. Before doing this, we clone the ruler and then alter its content. Finally we return it to be used where needed.
  • I introduced a Hoa\Ruler\Result class (with a magic method: this will change). It also does a clone of the result in some cases: this is to avoid mutating the value returned by the rules.
  • This class (Hoa\Ruler\Result) is also here to return a structured result letting developers keep track of the returned value, the rule that produced it and its name in the collection

jubianchi avatar Sep 14 '16 16:09 jubianchi

@jubianchi Tell me when you need a review.

Hywan avatar Sep 16 '16 12:09 Hywan

@Hywan you can start reviewing when you want: any comment is good.

There are still some things to do but I'd be glad to fix any issue you already saw ;)

jubianchi avatar Sep 16 '16 13:09 jubianchi

ping?

Hywan avatar Oct 14 '16 06:10 Hywan

@jubianchi I am interested in this feature as well. Is there anything I can help you with?

Pittiplatsch avatar Nov 02 '16 15:11 Pittiplatsch

I can finish this issue if someone can give me:

  • clear feedbacks,
  • code review,
  • clear TODOs

With that I would be able to ship new code and fix everything you spotted in a single iteration. TBH I won't have time to come back here after every push so I'd rather do everything in a single iteration.

jubianchi avatar Feb 14 '17 20:02 jubianchi

Hi,

I took a look at the code because it seems similar to something I'm looking for. afaict, this PR provides classes to associate a result with a rule (Then & ThenElse) and a class to get the first valid result of a set of rules. While that's useful it's not exactly what I'm after. I was hoping to have rules themselves return a result instead of a boolean, eg:

$rule = 'apply_discount(price, if(premium, 0.9, 1))';
$ruler = new Hoa\Ruler\Ruler();
$context         = new Hoa\Ruler\Context();
$context['user'] = true;
$context['product'] = '100';
// add apply_discount
assert($ruler->execute($rule, $context) === '90');

is this out of the scope of this PR ?

mathroc avatar Mar 17 '17 16:03 mathroc

Coverage Status

Coverage remained the same at 97.383% when pulling 2e8f5138f702c4fe9bf0d75a555ffa8f6ad16962 on jubianchi:rule-results into 28174caf3be01144e7e213fce75598404570e094 on hoaproject:master.

coveralls avatar Jan 05 '18 21:01 coveralls

Coverage Status

Coverage remained the same at 97.383% when pulling 2e8f5138f702c4fe9bf0d75a555ffa8f6ad16962 on jubianchi:rule-results into 28174caf3be01144e7e213fce75598404570e094 on hoaproject:master.

coveralls avatar Jan 05 '18 21:01 coveralls

@jubianchi Should we do another round review?

Hywan avatar Jan 22 '18 10:01 Hywan

@Hywan yes you can if you think this feature really makes sense in Ruler.

I was asking myself if it should stay here or go somewhere else...

BTW I updated the PR to use hoa/heap instead of SplHeap as requested in previous discussions.

jubianchi avatar Jan 30 '18 19:01 jubianchi