Writing rule in Drools - conditional sum -


i stuck in writing rule particular problem statement. have excel file having columns id, specialty,salary. specialty can take values such "oncology","urology" etc. have calculate total salary corresponding each specialty. there 2 ways of doing this.

first:

rule "total salary of oncology"   no-loop lock-on-active salience 100     when      $m : masterclass( $id : phyid , $p : p,spec=="oncology")      not masterclass( spec=="oncology", phyid < $id)     $total : number() accumulate ( masterclass(  $salary : salary ,spec=="oncology") ,                 init( double total =0;),                  action(total+=$salary;),                 result(  new double (total)))         system.out.println($m.getspec());     system.out.println("total target pay : " + $total + " of specialty : "+ $m.getspec());     retract($m); end  

and other specialties. rule works fine.

second: write single rule reads value of specialty , sums salaries corresponding it. tried implement didn't succeed. appreciated.

this far perfect. note don't have insert specific string. running rule without string match produce accumulated sums specialities anyway.

and should wrap string java class - lazy invent proper java class 1 field.

rule "trigger read" when   not string()   string s = read_any_way_you_want();   insert( s ); end;  rule "total salary of something"  when   $spec: string()   $m : masterclass( $id: phyid , spec == $spec)   not masterclass( spec == $spec, phyid < $id)   $total : number()      accumulate ( masterclass($salary: salary, spec == $spec) ,             init( double total =0;),              action(total+=$salary;),             result( new double (total)))   system.out.println($m.getspec());   system.out.println("total target pay : " + $total +                       " o specialty : "+ $m.getspec());   retract($spec); end  

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -