Hello,


I am implementing temporal rules using drools fusión 6.0.1 and the new KIE
services api. I insert facts into the kie session that include some DATE
fields which I later use in the rules. I also insert events using the
pseudoclock, so I guess that means that the timestamp is kept  in long
format.

The consequence is that my temporal rules do not fire at all! I have no
@timestamp annotation in the declare of the event, so Drools internal clock
should be used as timestamp.



I have displayed  the value of the pseudoclock getCurrentTime method, and
the output shows a date of 1970:







I need to understand why the clock.getTime returns dates of 1970, maybe when
this is solved the rules will fire with the internal event timestamp.



(After that I have tried every possible combination: creating a date or long
field in the event fact representing the timestamp, converting long to date
and viceversa, but nothing seems to work..).



I enclose here the initialization that I do of the kieContainer and session:





public static void main(final String[] args) {

             try {



                    // load up the knowledge base

                    KieServices ks = KieServices.Factory.get();

                    KieContainer kContainer = ks.getKieClasspathContainer();


System.out.println(kContainer.verify().getMessages().toString());





                    // set stream mode as opposite to cloud mode

                    KieBaseConfiguration kbconf =
KieServices.Factory.get().newKieBaseConfiguration();

                    kbconf.setOption(EventProcessingOption.STREAM );



                    // set clock to pseudo clock to be able to advance it
manually

                    KieSessionConfiguration ksconf =
KieServices.Factory.get().newKieSessionConfiguration();

                    ksconf.setOption(ClockTypeOption.get("pseudo"));





                    // returns ksession from kiecontainer as defined in the
kmodule.xml file

                    KieSession kSession =
kContainer.newKieSession("VAPSession", ksconf);





                    // Insert test patients and related classes, dates are
in long format to match pseudoclock

                    final Patient p1 = new Patient( "MrJones", 45, 1,
true,false,false,35.0,

                                  5000,"None","Localized
Infiltrates","Yes","None","S.Aureus",245,false, false, 0,

                                  true,new
SimpleDateFormat("yyyy-MM-dd").parse("2014-05-31").getTime(),"",

                                  new
SimpleDateFormat("yyyy-MM-dd").parse("2014-05-31").getTime(),false,false,fal
se,false);

kSession.insert( p1 );





                    // Insert test patients and related classes, dates are
long format



                    final Patient p2 = new Patient( "MissDaisy", 90, 1,
true,false,true,37.0,

                                  5000,"Purulent","Diffuse or Patchy
Infiltrates","None","Heavy","S.Aureus",235,false, false, 0,

                                  true,new
SimpleDateFormat("yyyy-MM-dd").parse("2014-05-31").getTime(),"",

                                  new
SimpleDateFormat("yyyy-MM-dd").parse("2014-05-31").getTime(),false,false,tru
e,false);



                    kSession.insert( p2 );



                    // define and get a reference to the entry point

                    EntryPoint nursingStream = kSession.getEntryPoint(
"NursingStream" );



                    // define session clock

                    SessionPseudoClock clock = kSession.getSessionClock();



                    // insert events

                    // then, while inserting events, advance the clock as
necessary:



                    clock.advanceTime(24, TimeUnit.HOURS);

                    CPIScore cpiScore1 = new CPIScore(
p1,"diagnosis",7,ToDate(clock.getCurrentTime()) );

                    nursingStream.insert( cpiScore1 );

                    System.out.println(cpiScore1.getcpiScoreDate());



// day 2

                    clock.advanceTime( 24, TimeUnit.HOURS );

                    cpiScore1 = new CPIScore(
p1,"follow-up",5,ToDate(clock.getCurrentTime()) );

                    nursingStream.insert( cpiScore1 );

                    System.out.println(cpiScore1.getcpiScoreDate());



// day 3

                    clock.advanceTime( 24, TimeUnit.HOURS );

                    cpiScore1 = new CPIScore(
p1,"follow-up",5,ToDate(clock.getCurrentTime()) );

                    nursingStream.insert( cpiScore1 );

                    System.out.println(cpiScore1.getcpiScoreDate());





The fact classes have now long fields to represent Dates (I changed to see
if that made a difference, it didn’t). The event class has such a long field
that can be defined as @timestamp but I rather prefer to use the internal
event timestamp managed by Drools.

So in my .DRL file I’d like to have:



declare CPIScore

   @role(event)

end



In my rules I compare the patient hospitalization date (defined as Date and
later as Long in the fact class) with a stream of events , and I expect
drools to extract the correct timestamp from the event. This can’t happen if
1970 is the pseudoclock date.



Please advice as about how to proceed, I’m a bit lost at this point.



Thanks in advance

Natalia





---
Este mensaje no contiene virus ni malware porque la protección de avast! 
Antivirus está activa.
http://www.avast.com
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to