Grouping and Aggregation in Drools
by Manav
Hi,
I have a slightly tricky problem on my hand that i am trying to solve using
rules.
I am using version 5.1 of Drools.Appreciate if there are any suggestions /
pointers .
I have a customer who will have a shopping cart with various products. For
example
the shopping cart will be a list of products that belong to a certain
sub-category and
super category like
product-id= 'Noodles', sub-category='PackagedFood', super-category='FMCG-Food',
%value of total=3%
product-id= 'Cookies', sub-category='PackagedFood',super-category='FMCG-Food',
%value of total=6%
product-id= 'Pizza', sub-category='ReadyToEat',super-category='FMCG-Food',
%value of total=5%
product-id= 'Burgers', sub-category='ReadyToEat',super-category='FMCG-Food',
%value of total=7%
product-id= 'Shampoo', sub-category='Toiletaries',super-category='FMCG-NonFood',
%value of total=4%
product-id= 'Conditioner',
sub-category='Toiletaries',super-category='FMCG-NonFood', %value of total=8%
The customer will also have a suggested cart that serves as a reference at the
sub-category and supercategory level. The reference will tell what level of his
total purchase he can spend on the sub-category and super-category. The
reference will look something like
super-category='FMCG-Food', %value-suggested=20%
super-category='FMCG-NonFood', %value-suggested=15%
sub-category='PackagedFood',%value-suggested=10%
sub-category='ReadyToEat',%value-suggested=10%
sub-category='Toiletaries',%value-suggested=6%
Looking at this example the customer is going overboard in the FMCG-Food super
category as the suggested
limit is 20% and the actual grouped at the supsercategory is 21% . Also he is
crossing the limit at the
sub-category level for ReadyToEat (suggested is 10% vs actual is 12%) and
Toiletaries (suggested is 6% vs actual 12%)
My problem is how do i group the actual data at various supercategory level,
sum the %value and then compare it with the suggested in the when clause.
If they cross the limit i will then have some action taken in the then clause.
Similarly i will have to do the same at the sub-category level as well.
Regards,
Manav
13 years, 10 months
writing correct drool rule
by Odelya Holiday
Hi!
I am actually using jBPM5 but the rules are in drools.
I created the following DSL file:
[condition][]There is a new program request=$processInstance: WorkflowProcessInstance() AND $requestData: RequestData()
[consequence][]Select an officers for {requestData.genre} program=Collection<Officer> officers = Collection<Officer> officers.get(GenreType.{requestData.genre}))
[consequence][]Select an officer for {requestData.cost} program=
[consequence][]Initialize Process=$processInstance.setVariable("officers", officers);
Officer object looks like this:
Name
Mincost
Maxcost
So on the 1st consequence I get all the officers that their genre type is as in the request data
In the 2nd consequence I get all the officers that their mincost < requestData.cost and maxcost > requestData.cost
How can I write it in drools rule?
Thanks!
Odelya Holiday
13 years, 10 months
Why won't this work? (Conjunction + Disjunction over a set)
by OlliSee
Hello there and a happy new year to everyone reading :)
Why am I here again? Yep, got a problem. Don't know why it doesn't work. I'm
using the latest snapshot version.
So here it goes.
A simple rule with conjunction and disjunction but over a set of events.
when
$ldes : Set(size == 2) from collect(LoopDetectorEvent() over
window:length(2))
(or LoopDetectorEvent($t1 : transportation == "LKW", $id1 : eventID) from
$ldes
LoopDetectorEvent($t2 : transportation == "PKW", $id2 : eventID) from
$ldes)
LoopDetectorEvent($t3 : transportation == "BUS", $id3 : eventID) from
$ldes
So, what the rule says: fire when there's a BUS event plus either a LKW or
PKW event in the set.
But, instead I get a big exception. It's posted at the end.
Interestingly, it works if I don't use the Set, like this...
when
(or $e1 : LoopDetectorEvent($t1 : transportation == "PKW", $id1 : eventID)
over window:length(1)
$e2 : LoopDetectorEvent($t2 : transportation == "LKW", $id2 : eventID)
over window:length(1))
LoopDetectorEvent($t3 : transportation == "BUS", $id3 : eventID) over
window:length(1)
but that rule does not have the same meaning. So it's useless for me.
Besides, it DOES work with the set if I just cut the third event out (the
BUS event).
What is wrong here?
Thanks in advance.
Kind regards!
Oliver
Exception in thread "Thread-2" java.lang.ClassCastException:
org.drools.reteoo.InitialFactImpl cannot be cast to
trafficsys.domain.events.LoopDetectorEvent
at
org.drools.base.trafficsys.domain.events.LoopDetectorEvent446196$getTransportation.getValue(Unknown
Source)
at org.drools.base.ClassFieldReader.getValue(ClassFieldReader.java:91)
at
org.drools.base.evaluators.EqualityEvaluatorsDefinition$StringEqualEvaluator.evaluate(EqualityEvaluatorsDefinition.java:1961)
at org.drools.rule.LiteralRestriction.isAllowed(LiteralRestriction.java:92)
at org.drools.rule.LiteralConstraint.isAllowed(LiteralConstraint.java:109)
at
org.drools.reteoo.FromNode.checkConstraintsAndPropagate(FromNode.java:264)
at org.drools.reteoo.FromNode.assertLeftTuple(FromNode.java:138)
at
org.drools.reteoo.SingleLeftTupleSinkAdapter.doPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:189)
at
org.drools.reteoo.SingleLeftTupleSinkAdapter.propagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:64)
at
org.drools.reteoo.FromNode.checkConstraintsAndPropagate(FromNode.java:279)
at org.drools.reteoo.FromNode.assertLeftTuple(FromNode.java:138)
at
org.drools.reteoo.SingleLeftTupleSinkAdapter.doPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:189)
at
org.drools.reteoo.SingleLeftTupleSinkAdapter.propagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:64)
at
org.drools.reteoo.AccumulateNode.evaluateResultConstraints(AccumulateNode.java:662)
at org.drools.reteoo.AccumulateNode.assertObject(AccumulateNode.java:270)
at
org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:450)
at
org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:378)
at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:190)
at org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:145)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:1187)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:1089)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:893)
at
org.drools.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:238)
at trafficsys.SessionInterface.insertAndFire(SessionInterface.java:133)
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Why-won-t-this-work-C...
Sent from the Drools - User mailing list archive at Nabble.com.
13 years, 10 months
Guvnor - archival option
by Rob Fisher
I archived a rule, then deleted it within Administration\Archive (using
the "Delete selected asset" option). However, when trying to create a
rule with the same name, I receive the following message: "An asset with
that name already exists in the chosen package. Please use another
name". I do not see the rule under Archive any longer (since it was
deleted). It seems, however, to still be recognized within the
repository.
Anyone know how to solve this?
Thanks
Rob Fisher
13 years, 10 months
Compiling rules using maven?
by Ansgar Konermann
Hi,
is there any official support for compiling *.drl files into
pre-compiled binary rule packages using a maven plugin?
I found reminescents of a maven plugin in the ticket tracking system,
but the code seems to be orphaned.
Thanks in advance
Ansgar
13 years, 10 months
Drools Flow Fluent API and the StateNode
by Daniel Nathanson
Hi,
How can I create a StateNode using the DroolsFlowProcessFactory? I'm
using Drools 5.1.1 and the StateNode exists, but there is no method:
StateNodeFactory stateNode(long)
available. For that matter, there is no StateNodeFactory class either.
Is this an oversight? Do I need a newer version of Drools? Is there a
workaround?
Regards,
Dan Nathanson
13 years, 10 months
Can I deploy pre-compiled drools rules as OSGi bundles?
by Ansgar Konermann
Hi,
I heard that drools was called "OSGi ready" some time ago. As I am new
to OSGi, I'd like to hear some opinions on whether the following
scenario would work for rules deployment:
For the drools part:
- pre-compile all rules into a binary package file
- include these file as a resource into an OSGi bundle
- put a configuration file, say drools-rules.xml into META-INF,
containing references to all the rule files/resources which should be
loaded/used
For the OSGi part:
- create an extender bundle which uses the information from the
configuration file of the above bundle
- automatically de-serializes the rule packages and
- registers a service which offers methods to run the rules contained in
the rules bundle
The service interface in my case would be project-specific, and would be
the same for all rule bundles. We have multiple customers, each with
their own implementation of a ruleset for risk estimation. Each service
instance could carry a property configured in the
META-INF/drools-rules.xml file, making it easy for client code to find
the correct service instance to call.
What I'm particularly interested in:
- does Drools support being used in an OSGi setting as sketched above?
- can anyone estimate whether I will I into class loading issues?
Thanks in advance
Ansgar
13 years, 10 months
Integrating Drools Fusion and JBPM5
by Plug Tree
Hi guys, just wanted to share a little post that we wrote about the
integration of CustomEventListeners in JBPM5 and CEP in Drools Fusion to
control processes.
<%20http://www.plugtree.com/?p=26492>
ttp://www.plugtree.com/?p=26492 <%20http://www.plugtree.com/?p=26492>
Feedback is appreciated ! Thanks!
Plugtree LLC
13 years, 10 months
Drools definitive list of Error Codes
by Murali Venugopal
Hi,
I looking forward to find a Definitive List of Error codes and their definitions. Please help me to find and understand them.
eg: [ERR 102], [ERR 101]
_ _ _ _ |.
| | ||_|| (_||| \/
Get your world in your inbox!
Mail, widgets, documents, spreadsheets, organizer and much more with your Sifymail WIYI id!
Log on to http://www.sify.com
********** DISCLAIMER **********
Information contained and transmitted by this E-MAIL is proprietary to
Sify Limited and is intended for use only by the individual or entity to
which it is addressed, and may contain information that is privileged,
confidential or exempt from disclosure under applicable law. If this is a
forwarded message, the content of this E-MAIL may not have been sent with
the authority of the Company. If you are not the intended recipient, an
agent of the intended recipient or a person responsible for delivering the
information to the named recipient, you are notified that any use,
distribution, transmission, printing, copying or dissemination of this
information in any way or in any manner is strictly prohibited. If you have
received this communication in error, please delete this mail & notify us
immediately at admin(a)sifycorp.com
13 years, 10 months