"NOT" conditional rule for filters is missing
![Ambroise](https://us.v-cdn.net/6037124/uploads/userpics/CQK66977Q335/nTGIPZ4H8MVBY.jpg)
I'm trying to write a "Query All Records" with the following rules, and I'm struggling.
def validate_time_categorization_within_punch_set(time_categorization, time_punch_set): # Check Start Time if time_categorization["startsAt"] < time_punch_set["clockIn"]: return False # Check End Time if time_categorization["endsAt"] > time_punch_set["clockOut"]: return False # TimeCategorization Within TimePunchSet if (time_categorization["startsAt"] >= time_punch_set["clockIn"]) and \ (time_categorization["endsAt"] <= time_punch_set["clockOut"]): return True return False
The first two "if statements" do not seem possible with Xano, because there is no "NOT" conditional rule.
Without it, I fail to see how I can write my request, it feels like I'll need to fetch tons of records and them filter them through a Lambda Function instead of having the DB doing this job.
Answers
-
Maybe I'm wrong, but I think you just need to filter by the third statement "TimeCategorization Within TimePunchSet" because it implicitly includes the first two statements.
It looks like any query satisfying the third statement also satisfies the first two statements, so you just need either the first two together or the third.
The NOT opertator is easy to apply by just reversing the comparison operator at any step. So I guess this is the reason Xano didn't included it explicitly.
-
"Within" can mean many things, and I very much doubt it would mean what you think it does (within 2 numbers), it's more likely to be a feature like "includes" for array, but I couldn't find the doc that explains what it does exactly.
What I know is that I tried lots of things (including Within), and couldn't get it to work the way I wanted, I eventually found a solution, but not what I wanted exactly.
-
I'm just reading the code and applying simple boolean logic.
# Check Start Time if (A < B) → false # Check End Time if (C > D) → false # TimeCategorization Within TimePunchSet if (A ≥ B) AND (C ≤ D) → true # If none of above (else) → false
If 1st and 2nd statements fail, then the 3rd statement must pass because
NOT (A < B) = (A ≥ B)
andNOT (C > D) = (C ≤ D)
. So if the execution reaches the 3rd statement, it will always returntrue
. There is no way to reach the 4th (last) statement which returnsfalse
.So basically the function could be written like this and it will produce the same results.
# TimeCategorization Within TimePunchSet if (A ≥ B) AND (C ≤ D) → true # If none of above (else) → false
Or like this.
# Check Start Time if (A < B) → false # Check End Time if (C > D) → false # If none of above (else) → true
Or like this.
# Check Start Time / End Time if (A < B) OR (C > D) → false # If none of above (else) → true
You don't need the
NOT
operator when you when you have mutually exclusive operators like>
and≤
or<
and≥
.
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback