Reputation: 41
I have 2 variables called "score" and "scoreRange" and assuming "score" value is 0.185 and I want to compare it with 0.3 and 0.9. my condition is as below.
if score is less than 0.3 (score <0.3) -> mark scoreRange as LOW,
0.3 to 0.9 (0.3 <= score < 0.9) --> mark scoreRange as MEDIUM
and larger than 0.9 (score >= 0.9) --> mark scoreRaneg as HIGH
How to compare 0.185 with 0.3 or 0.9 in jolt. I tried creating an array with values [0.3, 0.9] and add the "score" to that array "array" : [ 0.3, 0.9, 0.185 ]. Then took out the min and max of that array. If Score is in min position or equal to min then scoreRange is low. If Score is in max position or equal to max then scoreRange is high. If both fails then medium. But currently i'm not getting how to compare with normal or array values.
My Input ( Irrelevant )
{
"sampleArray": [
4,
2,
8
]
}
Tried out spec
[
{
"operation": "default",
"spec": {
"array": [0.3, 0.9]
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"score": 0.185,
"array": {
"[2]": "@(2,sumIntData)"
},
"minAB": "=min(@(1,array))",
"maxAB": "=max(@(1,array))"
}
}
]
My current output.
{
"sampleArray" : [ 4, 2, 8 ],
"array" : [ 0.3, 0.9, 0.185 ],
"score" : 0.185,
"minAB" : 0.185,
"maxAB" : 0.8
}
I'm new to jolt. Any guidance in comparing values will be helpful to me. And how to get a specific value from an array in jolt. elementAt option from jolt was not helpful
Upvotes: 2
Views: 781
Reputation: 65323
I suppose that you can have such an input
{
"score": 0.185,
"sampleArray": [
0.3,
0.9
]
}
and through use of shift transformation having conditionals for comparisons of values generated by using doubleSubtract and abs functions within the modify-overwrite-beta transformation such as
[
{
"operation": "modify-overwrite-beta",
"spec": {
"minAB": "=min(@(1,sampleArray))",
"maxAB": "=max(@(1,sampleArray))",
"diff1": "=doubleSubtract(@(1,score),@(1,minAB))",
"diff2": "=doubleSubtract(@(1,score),@(1,maxAB))",
"adiff1": "=abs(@(1,diff1))",
"adiff2": "=abs(@(1,diff2))",
"absdiff1": "=doubleSubtract(@(1,diff1),@(1,adiff1))",
"absdiff2": "=doubleSubtract(@(1,diff2),@(1,adiff2))"
}
},
{
"operation": "shift",
"spec": {
"absdiff1": {
"0.0": {
"@(2,absdiff2)": {
"0.0": {
"#HIGH": "scoreRange"
},
"*": {
"#MEDIUM": "scoreRange"
}
}
},
"*": {
"#LOW": "scoreRange"
}
}
}
}
]
Upvotes: 2