"NOT" conditional rule for filters is missing

Options

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

  • arturosanz
    arturosanz Member ✭✭
    edited August 2023
    Options

    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.

  • Ambroise
    Ambroise Member
    Options

    "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.

  • arturosanz
    arturosanz Member ✭✭
    Options

    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) and NOT (C > D) = (C ≤ D). So if the execution reaches the 3rd statement, it will always return true. There is no way to reach the 4th (last) statement which returns false.

    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 .