Need to check if a value is within the range (upper limit and lower limit) configured in drools decision table - drools

I am new to Drools. Now I need to validate one value is within the range configured in drools decision table.
Scenario: Salary is the condition and grade is the action (output).
I need to configure the salary like this
(0 - 10000) - Grade A,
(10000 - 15000) - Grade B
Please help me to design the drools decision table.
Can I use "in"

You'd use < and > (or <= and >=) just like you'd do a normal comparison in Java or DRL.
Pseudo-code, it would look something like this:
| CONDITION | CONDITION | ACTION |
| salary >= $param | salary < $param | $result |
| MIN | MAX | GRADE |
| 0 | 10000 | A |
| 10000 | 15000 | B |
in is a valid keyword in Drools, but it's not for this. It's for identifying if a value is in a given list. For example, if you wanted to check that some value $color is one of red, blue, or green, you'd do like: $color in ("red", "blue", "green"). It's not appropriate for figuring out if a number is in a range.

Related

Power Query: some values are counted from zero when count should start at a higher value

I have a column with values counting occurrences.
I am trying to continue the series in Power Query.
I am thus trying to increment 1 to the max of the given column..
The ID column has rows with letter tags : AB or BE. Following these letters, specific numeric ranges are associated. For both AB and BE, number ranges first from 0000 to 3000 and from 3000 to 6000.
I thus have the following possibilities: From AB0000 to AB3000 From AB3001 to AB6000 From BE0000 to BE3000 From BE3001 to AB6000
Each category match to the a specific item in my column geography, from the other workbook: From AB0000 to AB3000, it is ItalyZ From AB3001 to AB6000, it is ItalyB From BE0000 to BE3000, it is UKY From BE3001 to AB6000, it is UKM
I am thus trying to find the highest number associated to the first AB category, the second AB category, the first BE category, and the second.
My issue is that for some values, there is simply "nothing" yet in we source file.
This means that there is no occurrence yet of UKM for example.
Here is an example with no UKM or UKY:
|------------------|---------------------|
| Max | Geography |
|------------------|---------------------|
| 0562 | ItalyZ |
|------------------|---------------------|
| 0563 | ItalyZ |
|------------------|---------------------|
Hence, I have the following result:
|------------------|---------------------|
| Increment | Place |
|------------------|---------------------|
| 0564 | ItalyZ |
|------------------|---------------------|
| 0565 | ItalyZ |
|------------------|---------------------|
| 0565 | ItalyZ |
|------------------|---------------------|
| null | UKM |
|------------------|---------------------|
Here is the used power query code:
let
Source = #table({"Prefix", "Seq_Start", "Seq_End","GeoLocation"},{{"AB",0,2999,"ItalyZ"},{"AB",3000,6000,"ItalyB"},{"BC",0,299,"UKY"},{"BC",3000,6000,"UKM"}}),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Seq_Start", Int64.Type}, {"Seq_End", Int64.Type}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Prefix"}, HighestID, {"Prefix"}, "HighestID", JoinKind.LeftOuter),
#"Expanded HighestID" = Table.ExpandTableColumn(#"Merged Queries", "HighestID", {"Number"}, {"Number"}),
#"Filtered Rows" = Table.SelectRows(#"Expanded HighestID", each [Number] >= [Seq_Start] and [Number] <= [Seq_End]),
#"Grouped Rows" = Table.Group(#"Filtered Rows", {"Prefix", "Seq_Start", "Seq_End", "GeoLocation"}, {{"NextSeq", each List.Max([Number]) + 1, type number}})
in
#"Grouped Rows"
I would like to know how I could insure that when I have the first occurrence of a value, I would not have "null", but "0000" (or 0) and so on for the next occurrences.
Because, for example, if I have 0 occurrences of UKY before, I do not know why but the end results will be as follows:
|------------------|---------------------|
| Increment | Place |
|------------------|---------------------|
| 1 | UKM |
|------------------|---------------------|
| 2 | UKM |
|------------------|---------------------|
Which is not ideal because UKM should start at 30000. And because I had no values recorded before, it is starting with "null" only and then, 1, 2...rather than 3001 and 3002.

Querying data with additional column that creates a number for ordering purposes

I am trying to create a "queue" system by adding an arbitrary column that creates a number based on a condition and date, to sort the importance of a row.
For example, below is the query result I pulled in Postgres:
Table: task
Result:
description | status/condition| task_created |
bla | A | 2019-12-01 07:00:00|
pikachu | A | 2019-12-01 16:32:10|
abcdef | B | 2019-12-02 18:34:22|
doremi | B | 2019-12-02 15:09:43|
lalala | A | 2019-12-03 22:10:59|
In the above, each task has a date/timestamp and status/condition applied to them. I would like to create another column that gives a number to a row where it prioritises the older tasks first, BUT if the condition is B, then we take the older task of those in B as first priority.
The expected end result (based on the example) should be:
Table1: task
description | status/condition| task_created | priority index
bla | A | 2019-12-01 07:00:00| 3
pikachu | A | 2019-12-01 16:32:10| 4
abcdef | B | 2019-12-02 18:34:22| 2
doremi | B | 2019-12-02 15:09:43| 1
lalala | A | 2019-12-03 22:10:59| 5
For priority number, 1 being most urgent to do/resolve, while 5 being the least.
How would I go about adding this additional column into the existing query? especially since there's another condition apart from just the task_created date/time.
Any help is appreciated. Many thanks!
You maybe want the Rank or Dense Rank function (depends on your needs) window functions.
If you don't need a conditional order on the status you can use this one.
SELECT *,
rank() OVER (
ORDER BY status desc, task_created
) as priority_index
FROM task
If you need a custom order based on the value of the status:
SELECT *,
rank() OVER (
ORDER BY
CASE status
WHEN 'B' THEN 1
WHEN 'A' THEN 2
WHEN 'C' THEN 3
ELSE 4
END, task_created
) as priority_index
FROM task
If you have few values this is good enough, because we can simply specify your custom order. But if you have a lot of values and the ordering information is fixed, then it should have its own table.

How to automatically calculate the SUS Score for a given spreadsheet in LibreOffice Calc?

I have several spreadsheets for a SUS-Score usability test.
They have this form:
| Strongly disagree | | | | Strongly agree |
I think, that I would use this system often | x | | | | |
I found the system too complex | |x| | | |
(..) | | | | | x |
(...) | x | | | | |
To calculate the SUS-Score you have 3 rules:
Odd item: Pos - 1
Even item: 5 - Pos
Add Score, multiply by 2.5
So for the first entry (odd item) you have: Pos - 1 = 1 - 1 = 0
Second item (even): 5 - Pos = 5 - 2 = 3
Now I have several of those spreadsheets and want to calculate the SUS-Score automatically. I've changed the x to a 1 and tried to use IF(F5=1,5-1). But I would need an IF-condition for every column: =IF(F5=1;5-1;IF(E5=1;4-1;IF(D5=1;3-1;IF(C5=1;2-1;IF(B5=1;1-1))))), so is there an easier way to calculate the score, based on the position in the table?
I would use a helper table and then SUM() all the cells of the helper table and multiply by 2.5. This formula (modified as needed, see notes below) can start your helper table and be copy-pasted to fill out the entire table:
=IF(D2="x";IF(MOD(ROW();2)=1;5-D$1;D$1-1);"")
Here D is an answer column
Depending on what row (odd/even) your answers start you may need to change the =1 after the MOD function to =0
This assumes the position number is in row 1; if position numbers are in a different row change the number after the $ appropriately

How to format background color of a cell which is under a group? - SSRS 2008 R2

I have the following matrix:
Design view
--------------------------
| OfficeSID | [Type] |
--------------------------
| [OfficeSid] | [Value] |
--------------------------
Preview
----------------------------
| OfficeSID | A | B |
----------------------------
| 1 | 1029 | 982 |
----------------------------
| 2 | 98 | 782 |
----------------------------
| 3 | 786 | 82 |
----------------------------
| 4 | 29 | 2 |
----------------------------
I want to format background color of the cells i.e 2nd row, 2nd column which is a value field. It is grouped under Type field.
The background color should be the following:
If value < 0 red
If value < 100 and > 0 Orange
If value >= 100 Green
I tried using expressions but it dint work.
This is a pretty common requirement... It sounds like you're trying to set the BackgroundColor property at the cell level, which is correct, so there's no reason it shouldn't be working.
What expression are you using? I'd use something like:
=Switch(Fields!Value.Value < 0, "Red"
, Fields!Value.Value > 0 and Fields!Value.Value < 100, "Orange"
, Fields!Value.Value >= 100, "Green")
Edit after comment:
Hmm, not sure what's going on with your report. I put together a basic example to match your results and it's working as expected.
Put together sample dataset:
Create matrix:
Expression for Value Text Box BackgroundColor property, literally copied and pasted from the answer above:
Final results, which looks like it's working as expected:
So I'm not sure what to suggest here... About the only thing I can think of is whether you have multiple values per OfficeSID/Type combination, in which case you'd need to use an aggregate in the expression, i.e. something like:
=Switch(Sum(Fields!Value.Value) < 0, "Red"
, Sum(Fields!Value.Value) > 0 and Fields!Value.Value < 100, "Orange"
, Sum(Fields!Value.Value) >= 100, "Green")
But other than that I guess you could either add the exact details of the data you're using, or start a new report from the ground up in the simplest way possible. This would show if you can get the background working in a new report with no other logic in place.

How to implement less and greater than rules with decision table in drools?

I would like to implement simple rules based on the less and greater values in drools using decision table.
It is easy enough to implement the rules in drl, for example:
rules "less than"
when Example(value < 10)
then
System.out.println("Less than 10")
end
rules "equals"
when Example(value = 10)
then
System.out.println("Equals 10")
end
rules "greater than"
when Example(value > 10)
then
System.out.println("Greater than 10")
end
But how can I translate it into decision table in drools? All the examples I have seen so far is to have the comparison done in condition cell. Is it even possible to do the comparison in value cell?
All example I had seen are in format of:
CONDITION | ACTION
Example |
value |
-----------------------------------|-------------------------------------
10 | System.out.println("equals to 10")
But that only applies to 1 rule, and doing the following totally has different meaning:
CONDITION | CONDITION | CONDITION | ACTION
Example
value | value > $1 | value < $1 |
-----------+------------+------------+----------------
10 | 10 | 10 | ???
Is even possible to do the following?
CONDITION | ACTION
Example |
value |
-----------------------------------+----------------------------------------
10 | System.out.println("equals to 10")
> 10 | System.out.println("greater than 10")
< 10 | System.out.println("less than 10")
What is the right way to implement these rules?
I found out that I can achieve what I needed by putting just $param in the constraint field cell and put in the whole constraint in the value cells. So the decision table looks like this:
CONDITION | ACTION
Example |
$param | System.out.println("$param");
-------------------------------+-----------------------------------
value == 10 | equals to 10
value > 10 | greater than 10
value < 10 | less than 10
It is possible to give the part of the condition as a value. In the header you can give "value $param" to evaluate. (BTW to be able to enter values like == 10 you have to change the cell format to Text in Excel)
CONDITION | ACTION
Example |
value $param |
-----------------------------------+----------------------------------------
== 10 | System.out.println("equals to 10")
in (10, 11) | System.out.println("is 10 or 11")
> 10 | System.out.println("greater than 10")
< 10 | System.out.println("less than 10")
You can take look at this
http://s11.postimage.org/oya6zxr83/Screenshot.png
here we take userlocation and count from user and check if count is less than initial count of each city and if condition satisfied the loop will run till Loop Condition.
Hope It will Be Helpful .