decision_agent 0.1.7 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/decision_agent/dsl/condition_evaluator.rb +1129 -12
- data/lib/decision_agent/dsl/schema_validator.rb +10 -0
- data/lib/decision_agent/version.rb +1 -1
- data/lib/decision_agent/web/public/app.js +119 -1
- data/lib/decision_agent/web/public/index.html +68 -0
- data/spec/advanced_operators_spec.rb +2147 -0
- data/spec/examples.txt +1633 -0
- metadata +2 -1
|
@@ -7,7 +7,17 @@ module DecisionAgent
|
|
|
7
7
|
eq neq gt gte lt lte in present blank
|
|
8
8
|
contains starts_with ends_with matches
|
|
9
9
|
between modulo
|
|
10
|
+
sin cos tan sqrt power exp log
|
|
11
|
+
round floor ceil abs
|
|
12
|
+
min max sum average mean median stddev standard_deviation variance percentile count
|
|
10
13
|
before_date after_date within_days day_of_week
|
|
14
|
+
duration_seconds duration_minutes duration_hours duration_days
|
|
15
|
+
add_days subtract_days add_hours subtract_hours add_minutes subtract_minutes
|
|
16
|
+
hour_of_day day_of_month month year week_of_year
|
|
17
|
+
rate_per_second rate_per_minute rate_per_hour
|
|
18
|
+
moving_average moving_sum moving_max moving_min
|
|
19
|
+
compound_interest present_value future_value payment
|
|
20
|
+
join length
|
|
11
21
|
contains_all contains_any intersects subset_of
|
|
12
22
|
within_radius in_polygon
|
|
13
23
|
].freeze
|
|
@@ -3,7 +3,7 @@ module DecisionAgent
|
|
|
3
3
|
# MAJOR: Incremented for incompatible API changes
|
|
4
4
|
# MINOR: Incremented for backward-compatible functionality additions
|
|
5
5
|
# PATCH: Incremented for backward-compatible bug fixes
|
|
6
|
-
VERSION = "0.
|
|
6
|
+
VERSION = "0.2.0".freeze
|
|
7
7
|
|
|
8
8
|
# Validate version format (semantic versioning)
|
|
9
9
|
unless VERSION.match?(/\A\d+\.\d+\.\d+(-[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*)?(\+[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*)?\z/)
|
|
@@ -307,12 +307,80 @@ class RuleBuilder {
|
|
|
307
307
|
'between': '[min, max] or {"min": 0, "max": 100}',
|
|
308
308
|
'modulo': '[divisor, remainder] or {"divisor": 2, "remainder": 0}',
|
|
309
309
|
|
|
310
|
+
// Mathematical functions
|
|
311
|
+
'sin': 'expected result (e.g., 0.0)',
|
|
312
|
+
'cos': 'expected result (e.g., 1.0)',
|
|
313
|
+
'tan': 'expected result (e.g., 0.0)',
|
|
314
|
+
'sqrt': 'expected result (e.g., 3.0)',
|
|
315
|
+
'power': '[exponent, result] or {"exponent": 2, "result": 4}',
|
|
316
|
+
'exp': 'expected result (e.g., 2.718)',
|
|
317
|
+
'log': 'expected result (e.g., 0.0)',
|
|
318
|
+
'round': 'expected rounded value (e.g., 3)',
|
|
319
|
+
'floor': 'expected floor value (e.g., 3)',
|
|
320
|
+
'ceil': 'expected ceiling value (e.g., 4)',
|
|
321
|
+
'abs': 'expected absolute value (e.g., 5)',
|
|
322
|
+
'min': 'expected minimum value (e.g., 1)',
|
|
323
|
+
'max': 'expected maximum value (e.g., 10)',
|
|
324
|
+
|
|
325
|
+
// Statistical aggregations
|
|
326
|
+
'sum': 'expected sum (e.g., 100) or {"min": 50, "max": 150}',
|
|
327
|
+
'average': 'expected average (e.g., 25.5) or {"gt": 20, "lt": 30}',
|
|
328
|
+
'mean': 'expected mean (e.g., 25.5) or {"gt": 20, "lt": 30}',
|
|
329
|
+
'median': 'expected median (e.g., 25) or {"gt": 20}',
|
|
330
|
+
'stddev': 'expected stddev (e.g., 5.2) or {"lt": 10}',
|
|
331
|
+
'standard_deviation': 'expected stddev (e.g., 5.2) or {"lt": 10}',
|
|
332
|
+
'variance': 'expected variance (e.g., 27.04) or {"lt": 100}',
|
|
333
|
+
'percentile': '{"percentile": 95, "threshold": 200} or {"percentile": 95, "gt": 100}',
|
|
334
|
+
'count': 'expected count (e.g., 10) or {"min": 5, "max": 20}',
|
|
335
|
+
|
|
310
336
|
// Date/time operators
|
|
311
337
|
'before_date': '2025-12-31',
|
|
312
338
|
'after_date': '2024-01-01',
|
|
313
339
|
'within_days': '7',
|
|
314
340
|
'day_of_week': 'monday or 1',
|
|
315
341
|
|
|
342
|
+
// Duration calculations
|
|
343
|
+
'duration_seconds': '{"end": "now", "max": 3600} or {"end": "field.end_time", "min": 60}',
|
|
344
|
+
'duration_minutes': '{"end": "now", "max": 60} or {"end": "field.end_time", "min": 5}',
|
|
345
|
+
'duration_hours': '{"end": "now", "max": 24} or {"end": "field.end_time", "min": 1}',
|
|
346
|
+
'duration_days': '{"end": "now", "max": 7} or {"end": "field.end_time", "min": 1}',
|
|
347
|
+
|
|
348
|
+
// Date arithmetic
|
|
349
|
+
'add_days': '{"days": 7, "compare": "lt", "target": "now"}',
|
|
350
|
+
'subtract_days': '{"days": 1, "compare": "gt", "target": "now"}',
|
|
351
|
+
'add_hours': '{"hours": 2, "compare": "lt", "target": "now"}',
|
|
352
|
+
'subtract_hours': '{"hours": 1, "compare": "gt", "target": "now"}',
|
|
353
|
+
'add_minutes': '{"minutes": 30, "compare": "lt", "target": "now"}',
|
|
354
|
+
'subtract_minutes': '{"minutes": 15, "compare": "gt", "target": "now"}',
|
|
355
|
+
|
|
356
|
+
// Time components
|
|
357
|
+
'hour_of_day': '9 or {"min": 9, "max": 17}',
|
|
358
|
+
'day_of_month': '15 or {"gte": 1, "lte": 31}',
|
|
359
|
+
'month': '12 or {"gte": 1, "lte": 12}',
|
|
360
|
+
'year': '2025 or {"gte": 2024}',
|
|
361
|
+
'week_of_year': '25 or {"gte": 1, "lte": 52}',
|
|
362
|
+
|
|
363
|
+
// Rate calculations
|
|
364
|
+
'rate_per_second': '{"max": 10} or {"min": 5, "max": 100}',
|
|
365
|
+
'rate_per_minute': '{"max": 600} or {"min": 50, "max": 1000}',
|
|
366
|
+
'rate_per_hour': '{"max": 36000} or {"min": 5000, "max": 50000}',
|
|
367
|
+
|
|
368
|
+
// Moving window
|
|
369
|
+
'moving_average': '{"window": 5, "threshold": 100} or {"window": 5, "gt": 50}',
|
|
370
|
+
'moving_sum': '{"window": 10, "threshold": 1000} or {"window": 10, "lt": 2000}',
|
|
371
|
+
'moving_max': '{"window": 5, "threshold": 200} or {"window": 5, "gt": 100}',
|
|
372
|
+
'moving_min': '{"window": 5, "threshold": 10} or {"window": 5, "lt": 50}',
|
|
373
|
+
|
|
374
|
+
// Financial calculations
|
|
375
|
+
'compound_interest': '{"rate": 0.05, "periods": 12, "result": 1050}',
|
|
376
|
+
'present_value': '{"rate": 0.05, "periods": 10, "result": 613.91}',
|
|
377
|
+
'future_value': '{"rate": 0.05, "periods": 10, "result": 1628.89}',
|
|
378
|
+
'payment': '{"rate": 0.05, "periods": 12, "result": 100}',
|
|
379
|
+
|
|
380
|
+
// String aggregations
|
|
381
|
+
'join': '{"separator": ",", "result": "a,b,c"} or {"separator": ",", "contains": "a"}',
|
|
382
|
+
'length': '{"max": 500} or {"min": 10, "max": 100}',
|
|
383
|
+
|
|
316
384
|
// Collection operators
|
|
317
385
|
'contains_all': '["item1", "item2"]',
|
|
318
386
|
'contains_any': '["item1", "item2"]',
|
|
@@ -332,9 +400,59 @@ class RuleBuilder {
|
|
|
332
400
|
'modulo': 'Modulo: [divisor, remainder] or {"divisor": 2, "remainder": 0}',
|
|
333
401
|
'matches': 'Regular expression pattern (e.g., ^user@company\\.com$)',
|
|
334
402
|
'within_days': 'Number of days from now (e.g., 7 for within a week)',
|
|
403
|
+
'sum': 'Numeric or {"min": 50, "max": 150}',
|
|
404
|
+
'average': 'Numeric or {"gt": 20, "lt": 30}',
|
|
405
|
+
'mean': 'Numeric or {"gt": 20, "lt": 30}',
|
|
406
|
+
'median': 'Numeric or {"gt": 20}',
|
|
407
|
+
'stddev': 'Numeric or {"lt": 10}',
|
|
408
|
+
'standard_deviation': 'Numeric or {"lt": 10}',
|
|
409
|
+
'variance': 'Numeric or {"lt": 100}',
|
|
410
|
+
'percentile': '{"percentile": 95, "threshold": 200}',
|
|
411
|
+
'count': 'Numeric or {"min": 5, "max": 20}',
|
|
412
|
+
'duration_seconds': '{"end": "now" or "field.path", "max": 3600}',
|
|
413
|
+
'duration_minutes': '{"end": "now" or "field.path", "max": 60}',
|
|
414
|
+
'duration_hours': '{"end": "now" or "field.path", "max": 24}',
|
|
415
|
+
'duration_days': '{"end": "now" or "field.path", "max": 7}',
|
|
416
|
+
'add_days': '{"days": 7, "compare": "lt", "target": "now" or "field.path"}',
|
|
417
|
+
'subtract_days': '{"days": 1, "compare": "gt", "target": "now" or "field.path"}',
|
|
418
|
+
'add_hours': '{"hours": 2, "compare": "lt", "target": "now" or "field.path"}',
|
|
419
|
+
'subtract_hours': '{"hours": 1, "compare": "gt", "target": "now" or "field.path"}',
|
|
420
|
+
'add_minutes': '{"minutes": 30, "compare": "lt", "target": "now" or "field.path"}',
|
|
421
|
+
'subtract_minutes': '{"minutes": 15, "compare": "gt", "target": "now" or "field.path"}',
|
|
422
|
+
'hour_of_day': 'Numeric (0-23) or {"min": 9, "max": 17}',
|
|
423
|
+
'day_of_month': 'Numeric (1-31) or {"gte": 1, "lte": 31}',
|
|
424
|
+
'month': 'Numeric (1-12) or {"gte": 1, "lte": 12}',
|
|
425
|
+
'year': 'Numeric or {"gte": 2024}',
|
|
426
|
+
'week_of_year': 'Numeric (1-52) or {"gte": 1, "lte": 52}',
|
|
427
|
+
'rate_per_second': '{"max": 10} or {"min": 5, "max": 100}',
|
|
428
|
+
'rate_per_minute': '{"max": 600} or {"min": 50, "max": 1000}',
|
|
429
|
+
'rate_per_hour': '{"max": 36000} or {"min": 5000, "max": 50000}',
|
|
430
|
+
'moving_average': '{"window": 5, "threshold": 100}',
|
|
431
|
+
'moving_sum': '{"window": 10, "threshold": 1000}',
|
|
432
|
+
'moving_max': '{"window": 5, "threshold": 200}',
|
|
433
|
+
'moving_min': '{"window": 5, "threshold": 10}',
|
|
434
|
+
'compound_interest': '{"rate": 0.05, "periods": 12, "result": 1050}',
|
|
435
|
+
'present_value': '{"rate": 0.05, "periods": 10, "result": 613.91}',
|
|
436
|
+
'future_value': '{"rate": 0.05, "periods": 10, "result": 1628.89}',
|
|
437
|
+
'payment': '{"rate": 0.05, "periods": 12, "result": 100}',
|
|
438
|
+
'join': '{"separator": ",", "result": "a,b,c"}',
|
|
439
|
+
'length': '{"max": 500} or {"min": 10, "max": 100}',
|
|
335
440
|
'day_of_week': 'Day name (monday) or number (0=Sunday, 1=Monday, ...)',
|
|
336
441
|
'within_radius': 'JSON: {"center": {"lat": y, "lon": x}, "radius": km}',
|
|
337
|
-
'in_polygon': 'Array of coordinates: [{"lat": y, "lon": x}, ...]'
|
|
442
|
+
'in_polygon': 'Array of coordinates: [{"lat": y, "lon": x}, ...]',
|
|
443
|
+
'sin': 'Expected result of sin(field_value). Example: 0.0 for sin(0)',
|
|
444
|
+
'cos': 'Expected result of cos(field_value). Example: 1.0 for cos(0)',
|
|
445
|
+
'tan': 'Expected result of tan(field_value). Example: 0.0 for tan(0)',
|
|
446
|
+
'sqrt': 'Expected result of sqrt(field_value). Example: 3.0 for sqrt(9)',
|
|
447
|
+
'power': 'Power: [exponent, result] or {"exponent": 2, "result": 4}. Checks if field^exponent == result',
|
|
448
|
+
'exp': 'Expected result of exp(field_value) = e^field_value. Example: 2.718 for exp(1)',
|
|
449
|
+
'log': 'Expected result of log(field_value) = natural logarithm. Example: 0.0 for log(1)',
|
|
450
|
+
'round': 'Expected rounded value. Example: 3 for round(3.4)',
|
|
451
|
+
'floor': 'Expected floor value. Example: 3 for floor(3.9)',
|
|
452
|
+
'ceil': 'Expected ceiling value. Example: 4 for ceil(3.1)',
|
|
453
|
+
'abs': 'Expected absolute value. Example: 5 for abs(-5) or abs(5)',
|
|
454
|
+
'min': 'Expected minimum value from array. Example: 1 for min([3, 1, 5, 2])',
|
|
455
|
+
'max': 'Expected maximum value from array. Example: 5 for max([3, 1, 5, 2])'
|
|
338
456
|
};
|
|
339
457
|
|
|
340
458
|
if (hints[operator]) {
|
|
@@ -181,12 +181,80 @@
|
|
|
181
181
|
<option value="between">between (range)</option>
|
|
182
182
|
<option value="modulo">modulo equals</option>
|
|
183
183
|
</optgroup>
|
|
184
|
+
<optgroup label="Mathematical Functions">
|
|
185
|
+
<option value="sin">sin (trigonometric)</option>
|
|
186
|
+
<option value="cos">cos (trigonometric)</option>
|
|
187
|
+
<option value="tan">tan (trigonometric)</option>
|
|
188
|
+
<option value="sqrt">sqrt (square root)</option>
|
|
189
|
+
<option value="power">power (exponentiation)</option>
|
|
190
|
+
<option value="exp">exp (exponential)</option>
|
|
191
|
+
<option value="log">log (natural logarithm)</option>
|
|
192
|
+
<option value="round">round</option>
|
|
193
|
+
<option value="floor">floor</option>
|
|
194
|
+
<option value="ceil">ceil</option>
|
|
195
|
+
<option value="abs">abs (absolute value)</option>
|
|
196
|
+
<option value="min">min (array minimum)</option>
|
|
197
|
+
<option value="max">max (array maximum)</option>
|
|
198
|
+
</optgroup>
|
|
199
|
+
<optgroup label="Statistical Aggregations">
|
|
200
|
+
<option value="sum">sum (array sum)</option>
|
|
201
|
+
<option value="average">average (array mean)</option>
|
|
202
|
+
<option value="mean">mean (array average)</option>
|
|
203
|
+
<option value="median">median (array median)</option>
|
|
204
|
+
<option value="stddev">stddev (standard deviation)</option>
|
|
205
|
+
<option value="standard_deviation">standard_deviation (stddev)</option>
|
|
206
|
+
<option value="variance">variance (array variance)</option>
|
|
207
|
+
<option value="percentile">percentile (Nth percentile)</option>
|
|
208
|
+
<option value="count">count (array length)</option>
|
|
209
|
+
</optgroup>
|
|
184
210
|
<optgroup label="Date/Time Operators">
|
|
185
211
|
<option value="before_date">before date</option>
|
|
186
212
|
<option value="after_date">after date</option>
|
|
187
213
|
<option value="within_days">within N days</option>
|
|
188
214
|
<option value="day_of_week">day of week</option>
|
|
189
215
|
</optgroup>
|
|
216
|
+
<optgroup label="Duration Calculations">
|
|
217
|
+
<option value="duration_seconds">duration (seconds)</option>
|
|
218
|
+
<option value="duration_minutes">duration (minutes)</option>
|
|
219
|
+
<option value="duration_hours">duration (hours)</option>
|
|
220
|
+
<option value="duration_days">duration (days)</option>
|
|
221
|
+
</optgroup>
|
|
222
|
+
<optgroup label="Date Arithmetic">
|
|
223
|
+
<option value="add_days">add days</option>
|
|
224
|
+
<option value="subtract_days">subtract days</option>
|
|
225
|
+
<option value="add_hours">add hours</option>
|
|
226
|
+
<option value="subtract_hours">subtract hours</option>
|
|
227
|
+
<option value="add_minutes">add minutes</option>
|
|
228
|
+
<option value="subtract_minutes">subtract minutes</option>
|
|
229
|
+
</optgroup>
|
|
230
|
+
<optgroup label="Time Components">
|
|
231
|
+
<option value="hour_of_day">hour of day (0-23)</option>
|
|
232
|
+
<option value="day_of_month">day of month (1-31)</option>
|
|
233
|
+
<option value="month">month (1-12)</option>
|
|
234
|
+
<option value="year">year</option>
|
|
235
|
+
<option value="week_of_year">week of year (1-52)</option>
|
|
236
|
+
</optgroup>
|
|
237
|
+
<optgroup label="Rate Calculations">
|
|
238
|
+
<option value="rate_per_second">rate per second</option>
|
|
239
|
+
<option value="rate_per_minute">rate per minute</option>
|
|
240
|
+
<option value="rate_per_hour">rate per hour</option>
|
|
241
|
+
</optgroup>
|
|
242
|
+
<optgroup label="Moving Window">
|
|
243
|
+
<option value="moving_average">moving average</option>
|
|
244
|
+
<option value="moving_sum">moving sum</option>
|
|
245
|
+
<option value="moving_max">moving max</option>
|
|
246
|
+
<option value="moving_min">moving min</option>
|
|
247
|
+
</optgroup>
|
|
248
|
+
<optgroup label="Financial Calculations">
|
|
249
|
+
<option value="compound_interest">compound interest</option>
|
|
250
|
+
<option value="present_value">present value</option>
|
|
251
|
+
<option value="future_value">future value</option>
|
|
252
|
+
<option value="payment">payment (loan PMT)</option>
|
|
253
|
+
</optgroup>
|
|
254
|
+
<optgroup label="String Aggregations">
|
|
255
|
+
<option value="join">join (array to string)</option>
|
|
256
|
+
<option value="length">length (string/array length)</option>
|
|
257
|
+
</optgroup>
|
|
190
258
|
<optgroup label="Collection Operators">
|
|
191
259
|
<option value="contains_all">contains all</option>
|
|
192
260
|
<option value="contains_any">contains any</option>
|