SlideShare a Scribd company logo
1 of 17
Download to read offline
Simple Drools Examples
A couple of simple examples for the JUG Milano meeting.
Matteo Mortari
http://linkedin.com/in/matteomortari
http://github.com/tarilabs
@tari_manga
Drools: effective use-cases
● Business logic changes often
● Rule definition as common language between
Developers, Analysts and Stakeholders
● Framework to support Data Analysis
● Data “cleaning”: filtering, augmentation, ...
● Inference: assert new data, FSM, …
● Time series: Complex Event Processing (CEP)
… and many others!
( Two simple examples )
cit. YouTube: Maccio Capatonda “Burle”
Example #1
Monitor commuting route
● Strike
● Traffic delays
● Multiple notifications
...
Live: http://reex2014-tarilabs.rhcloud.com/
Source: https://github.com/tarilabs/reex2014-rules
Strike announcements
Metro delays
Final result
(demo)
(demo)
(demo)
(demo)
Example #2
Filtering, Inference, CEP, ...
https://github.com/tarilabs/mpes-demo2015/blob/master/src/main/resources/rules.drl
Filtering rules
rule "Filter01"
no-loop
salience 1000
when
$e : ZnetRxIoSampleResponse(
addressAsMacFormat(remoteAddress64) != "00:13:A2:00:40:68:E0:95"
)
then
retract($e);
end
rule "Filter02"
no-loop
salience 1000
when
$e : ZNetRxIoSampleResponse(
addressAsMacFormat(remoteAddress64) == "00:13:A2:00:40:68:E0:95" ,
containsAnalog == false
)
then
retract($e);
end
Inference rules
rule "Detect Docked"
no-loop
when
accumulate ( ZNetRxIoSampleResponse(
containsAnalog == true, $analog1 : analog1
) over window:length( 3 );
$avg : average( $analog1 ),
$count : count( $analog1 );
$avg > 950 , $count == 3
)
not ( DockedEvt() )
then
DockedEvt de = new DockedEvt();
de.setTs(drools.getWorkingMemory().getSessionClock().getCurrentTime());
insert(de);
end
CEP rules
rule "Toothbrush Session"
no-loop
when
$ude : UnDockedEvt()
$de : DockedEvt( this after $ude )
then
long millis = $de.getTs() - $ude.getTs() - 1000;
long mins = millis/1000/60;
long secs = (millis/1000) % 60;
long oscillations = (long) ( (7600.0/60/1000) * millis );
String sentence = "I just used my toothbrush! Total time: "
+( (mins>0)?mins+"m":"" )
+secs+"s "
+"Oscillations: "+oscillations;
LOG.debug("{}", sentence);
onCamel("direct:sentence", sentence);
retract($de);
retract($ude);
end
(live coding & demo)
Thank you!
Thanks JUG Milano
Matteo Mortari
http://linkedin.com/in/matteomortari
http://github.com/tarilabs
@tari_manga

More Related Content

Viewers also liked

syntegra-brochure-11_14b_2014_v3
syntegra-brochure-11_14b_2014_v3syntegra-brochure-11_14b_2014_v3
syntegra-brochure-11_14b_2014_v3Alan Wing-King
 
Magazine
MagazineMagazine
MagazineAHJoshy
 
поступление подушек и одеял
поступление подушек и одеялпоступление подушек и одеял
поступление подушек и одеял84959847778
 
Comparison of Latent Heat Flux Using Aerodynamic Methods and Using the Penman...
Comparison of Latent Heat Flux Using Aerodynamic Methods and Using the Penman...Comparison of Latent Heat Flux Using Aerodynamic Methods and Using the Penman...
Comparison of Latent Heat Flux Using Aerodynamic Methods and Using the Penman...Ramesh Dhungel
 
Top Ideas for Wash Sanitation and Hygiene
Top Ideas for Wash Sanitation and HygieneTop Ideas for Wash Sanitation and Hygiene
Top Ideas for Wash Sanitation and HygieneCopenhagen_Consensus
 

Viewers also liked (8)

syntegra-brochure-11_14b_2014_v3
syntegra-brochure-11_14b_2014_v3syntegra-brochure-11_14b_2014_v3
syntegra-brochure-11_14b_2014_v3
 
Itogi 2014.compressed
Itogi 2014.compressedItogi 2014.compressed
Itogi 2014.compressed
 
Magazine
MagazineMagazine
Magazine
 
Editing
EditingEditing
Editing
 
поступление подушек и одеял
поступление подушек и одеялпоступление подушек и одеял
поступление подушек и одеял
 
1 adetuyi oluwafijimi yomi bch084406
1 adetuyi oluwafijimi yomi bch0844061 adetuyi oluwafijimi yomi bch084406
1 adetuyi oluwafijimi yomi bch084406
 
Comparison of Latent Heat Flux Using Aerodynamic Methods and Using the Penman...
Comparison of Latent Heat Flux Using Aerodynamic Methods and Using the Penman...Comparison of Latent Heat Flux Using Aerodynamic Methods and Using the Penman...
Comparison of Latent Heat Flux Using Aerodynamic Methods and Using the Penman...
 
Top Ideas for Wash Sanitation and Hygiene
Top Ideas for Wash Sanitation and HygieneTop Ideas for Wash Sanitation and Hygiene
Top Ideas for Wash Sanitation and Hygiene
 

Similar to Simple Drools Examples

IoT with Ruby/mruby - RubyWorld Conference 2015
IoT with Ruby/mruby - RubyWorld Conference 2015IoT with Ruby/mruby - RubyWorld Conference 2015
IoT with Ruby/mruby - RubyWorld Conference 2015哲也 廣田
 
MLFlow: Platform for Complete Machine Learning Lifecycle
MLFlow: Platform for Complete Machine Learning Lifecycle MLFlow: Platform for Complete Machine Learning Lifecycle
MLFlow: Platform for Complete Machine Learning Lifecycle Databricks
 
Model Drift Monitoring using Tensorflow Model Analysis
Model Drift Monitoring using Tensorflow Model AnalysisModel Drift Monitoring using Tensorflow Model Analysis
Model Drift Monitoring using Tensorflow Model AnalysisVivek Raja P S
 
Evolution of Monitoring and Prometheus (Dublin 2018)
Evolution of Monitoring and Prometheus (Dublin 2018)Evolution of Monitoring and Prometheus (Dublin 2018)
Evolution of Monitoring and Prometheus (Dublin 2018)Brian Brazil
 
Streaming analytics state of the art
Streaming analytics state of the artStreaming analytics state of the art
Streaming analytics state of the artStavros Kontopoulos
 
Kusto (Azure Data Explorer) Training for R&D - January 2019
Kusto (Azure Data Explorer) Training for R&D - January 2019 Kusto (Azure Data Explorer) Training for R&D - January 2019
Kusto (Azure Data Explorer) Training for R&D - January 2019 Tal Bar-Zvi
 
OORPT Dynamic Analysis
OORPT Dynamic AnalysisOORPT Dynamic Analysis
OORPT Dynamic Analysislienhard
 
DotDotPwn v3.0 [GuadalajaraCON 2012]
DotDotPwn v3.0 [GuadalajaraCON 2012]DotDotPwn v3.0 [GuadalajaraCON 2012]
DotDotPwn v3.0 [GuadalajaraCON 2012]Websec México, S.C.
 
ACM DEBS 2015: Realtime Streaming Analytics Patterns
ACM DEBS 2015: Realtime Streaming Analytics PatternsACM DEBS 2015: Realtime Streaming Analytics Patterns
ACM DEBS 2015: Realtime Streaming Analytics PatternsSrinath Perera
 
DEBS 2015 Tutorial : Patterns for Realtime Streaming Analytics
DEBS 2015 Tutorial : Patterns for Realtime Streaming AnalyticsDEBS 2015 Tutorial : Patterns for Realtime Streaming Analytics
DEBS 2015 Tutorial : Patterns for Realtime Streaming AnalyticsSriskandarajah Suhothayan
 
Software development effort reduction with Co-op
Software development effort reduction with Co-opSoftware development effort reduction with Co-op
Software development effort reduction with Co-oplbergmans
 
Prometheus: From technical metrics to business observability
Prometheus: From technical metrics to business observabilityPrometheus: From technical metrics to business observability
Prometheus: From technical metrics to business observabilityJulien Pivotto
 
Fast Person Re-Identification for Intelligent Video Surveillance Systems
Fast Person Re-Identification for Intelligent Video Surveillance SystemsFast Person Re-Identification for Intelligent Video Surveillance Systems
Fast Person Re-Identification for Intelligent Video Surveillance SystemsBahram Lavi
 
Data Science for Internet of Things with Ajit Jaokar
Data Science for Internet of Things with Ajit JaokarData Science for Internet of Things with Ajit Jaokar
Data Science for Internet of Things with Ajit JaokarJessica Willis
 
The Fine Art of Time Travelling - Implementing Event Sourcing - Andrea Saltar...
The Fine Art of Time Travelling - Implementing Event Sourcing - Andrea Saltar...The Fine Art of Time Travelling - Implementing Event Sourcing - Andrea Saltar...
The Fine Art of Time Travelling - Implementing Event Sourcing - Andrea Saltar...ITCamp
 
Performance monitoring and call tracing in microservice environments
Performance monitoring and call tracing in microservice environmentsPerformance monitoring and call tracing in microservice environments
Performance monitoring and call tracing in microservice environmentsMartin Gutenbrunner
 
Go Observability (in practice)
Go Observability (in practice)Go Observability (in practice)
Go Observability (in practice)Eran Levy
 

Similar to Simple Drools Examples (20)

IoT with Ruby/mruby - RubyWorld Conference 2015
IoT with Ruby/mruby - RubyWorld Conference 2015IoT with Ruby/mruby - RubyWorld Conference 2015
IoT with Ruby/mruby - RubyWorld Conference 2015
 
MLFlow: Platform for Complete Machine Learning Lifecycle
MLFlow: Platform for Complete Machine Learning Lifecycle MLFlow: Platform for Complete Machine Learning Lifecycle
MLFlow: Platform for Complete Machine Learning Lifecycle
 
Model Drift Monitoring using Tensorflow Model Analysis
Model Drift Monitoring using Tensorflow Model AnalysisModel Drift Monitoring using Tensorflow Model Analysis
Model Drift Monitoring using Tensorflow Model Analysis
 
Evolution of Monitoring and Prometheus (Dublin 2018)
Evolution of Monitoring and Prometheus (Dublin 2018)Evolution of Monitoring and Prometheus (Dublin 2018)
Evolution of Monitoring and Prometheus (Dublin 2018)
 
Streaming analytics state of the art
Streaming analytics state of the artStreaming analytics state of the art
Streaming analytics state of the art
 
Kusto (Azure Data Explorer) Training for R&D - January 2019
Kusto (Azure Data Explorer) Training for R&D - January 2019 Kusto (Azure Data Explorer) Training for R&D - January 2019
Kusto (Azure Data Explorer) Training for R&D - January 2019
 
OORPT Dynamic Analysis
OORPT Dynamic AnalysisOORPT Dynamic Analysis
OORPT Dynamic Analysis
 
Guadalajara con 2012
Guadalajara con 2012Guadalajara con 2012
Guadalajara con 2012
 
DotDotPwn v3.0 [GuadalajaraCON 2012]
DotDotPwn v3.0 [GuadalajaraCON 2012]DotDotPwn v3.0 [GuadalajaraCON 2012]
DotDotPwn v3.0 [GuadalajaraCON 2012]
 
ACM DEBS 2015: Realtime Streaming Analytics Patterns
ACM DEBS 2015: Realtime Streaming Analytics PatternsACM DEBS 2015: Realtime Streaming Analytics Patterns
ACM DEBS 2015: Realtime Streaming Analytics Patterns
 
DEBS 2015 Tutorial : Patterns for Realtime Streaming Analytics
DEBS 2015 Tutorial : Patterns for Realtime Streaming AnalyticsDEBS 2015 Tutorial : Patterns for Realtime Streaming Analytics
DEBS 2015 Tutorial : Patterns for Realtime Streaming Analytics
 
Software development effort reduction with Co-op
Software development effort reduction with Co-opSoftware development effort reduction with Co-op
Software development effort reduction with Co-op
 
Prometheus: From technical metrics to business observability
Prometheus: From technical metrics to business observabilityPrometheus: From technical metrics to business observability
Prometheus: From technical metrics to business observability
 
Fast Person Re-Identification for Intelligent Video Surveillance Systems
Fast Person Re-Identification for Intelligent Video Surveillance SystemsFast Person Re-Identification for Intelligent Video Surveillance Systems
Fast Person Re-Identification for Intelligent Video Surveillance Systems
 
Msr2021 tutorial-di penta
Msr2021 tutorial-di pentaMsr2021 tutorial-di penta
Msr2021 tutorial-di penta
 
Data Science for Internet of Things with Ajit Jaokar
Data Science for Internet of Things with Ajit JaokarData Science for Internet of Things with Ajit Jaokar
Data Science for Internet of Things with Ajit Jaokar
 
Ajit jaokar slides
Ajit jaokar slidesAjit jaokar slides
Ajit jaokar slides
 
The Fine Art of Time Travelling - Implementing Event Sourcing - Andrea Saltar...
The Fine Art of Time Travelling - Implementing Event Sourcing - Andrea Saltar...The Fine Art of Time Travelling - Implementing Event Sourcing - Andrea Saltar...
The Fine Art of Time Travelling - Implementing Event Sourcing - Andrea Saltar...
 
Performance monitoring and call tracing in microservice environments
Performance monitoring and call tracing in microservice environmentsPerformance monitoring and call tracing in microservice environments
Performance monitoring and call tracing in microservice environments
 
Go Observability (in practice)
Go Observability (in practice)Go Observability (in practice)
Go Observability (in practice)
 

Recently uploaded

%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...chiefasafspells
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2
 

Recently uploaded (20)

%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 

Simple Drools Examples

  • 1. Simple Drools Examples A couple of simple examples for the JUG Milano meeting. Matteo Mortari http://linkedin.com/in/matteomortari http://github.com/tarilabs @tari_manga
  • 2. Drools: effective use-cases ● Business logic changes often ● Rule definition as common language between Developers, Analysts and Stakeholders ● Framework to support Data Analysis ● Data “cleaning”: filtering, augmentation, ... ● Inference: assert new data, FSM, … ● Time series: Complex Event Processing (CEP) … and many others!
  • 3. ( Two simple examples ) cit. YouTube: Maccio Capatonda “Burle”
  • 4. Example #1 Monitor commuting route ● Strike ● Traffic delays ● Multiple notifications ... Live: http://reex2014-tarilabs.rhcloud.com/ Source: https://github.com/tarilabs/reex2014-rules
  • 12. Example #2 Filtering, Inference, CEP, ... https://github.com/tarilabs/mpes-demo2015/blob/master/src/main/resources/rules.drl
  • 13. Filtering rules rule "Filter01" no-loop salience 1000 when $e : ZnetRxIoSampleResponse( addressAsMacFormat(remoteAddress64) != "00:13:A2:00:40:68:E0:95" ) then retract($e); end rule "Filter02" no-loop salience 1000 when $e : ZNetRxIoSampleResponse( addressAsMacFormat(remoteAddress64) == "00:13:A2:00:40:68:E0:95" , containsAnalog == false ) then retract($e); end
  • 14. Inference rules rule "Detect Docked" no-loop when accumulate ( ZNetRxIoSampleResponse( containsAnalog == true, $analog1 : analog1 ) over window:length( 3 ); $avg : average( $analog1 ), $count : count( $analog1 ); $avg > 950 , $count == 3 ) not ( DockedEvt() ) then DockedEvt de = new DockedEvt(); de.setTs(drools.getWorkingMemory().getSessionClock().getCurrentTime()); insert(de); end
  • 15. CEP rules rule "Toothbrush Session" no-loop when $ude : UnDockedEvt() $de : DockedEvt( this after $ude ) then long millis = $de.getTs() - $ude.getTs() - 1000; long mins = millis/1000/60; long secs = (millis/1000) % 60; long oscillations = (long) ( (7600.0/60/1000) * millis ); String sentence = "I just used my toothbrush! Total time: " +( (mins>0)?mins+"m":"" ) +secs+"s " +"Oscillations: "+oscillations; LOG.debug("{}", sentence); onCamel("direct:sentence", sentence); retract($de); retract($ude); end
  • 16. (live coding & demo)
  • 17. Thank you! Thanks JUG Milano Matteo Mortari http://linkedin.com/in/matteomortari http://github.com/tarilabs @tari_manga