Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com)
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi
Tinderbox Users >> Agent, Actions, Rules & Automation >> Puzzle on a query
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi?num=1461275359

Message started by J Fallows on Apr 21st, 2016, 5:49pm

Title: Puzzle on a query
Post by J Fallows on Apr 21st, 2016, 5:49pm

Here is a query that has me puzzled. The query is:
  $Prototype=="*Tasks" & $StartDate<date("today")

The idea is to find things that have already started, and to exclude those still in the future.

I have an item whose start date used to be a week ago. But it has been postponed, so I moved the start date to next month. Its KA panel shows:
 $StartDate=5/1/16

When its start date was earlier, the item showed up in the query — as it should. But after I changed the date, it still shows up. What am I doing wrong? This has me totally puzzled.

Diagnostic update for our expert friends:
 - I created a brand new file, which only one note, which had only one KA. That was $StartDate
 - I set that $StartDate value to the future
 - I created an agent with only one query term, $StartDate<date("today")
 - And that agent works correctly

So the mystery is what, in the compound (but not very complex) query $Prototype=="*Tasks" & $StartDate<date("today"), could possibly get the system confused?


Title: Re: Puzzle on a query
Post by Mark Anderson on Apr 22nd, 2016, 3:36am

Are you sure that the original file hasn't had agent automatc updates turned off or that the particular agent hasn't been set to low priority or off? I say this as of late I've had to turn off agent updating to stop the auto-scroll-to-top issue with big outline views and then forget my agents aren't updating any more.

I'd confirm (it's too easy to assume) that the agent is operating correctly before digging deeper. Certainly, re-testing yuor scenerio as best I can, the only way I can get a 'failed' agent is by turning is off or to very low priority; in the latter case it does update but takes longer.

Also, might another action be re-setting that $StartDate so it re-meets the agent query?


Title: Re: Puzzle on a query
Post by J Fallows on Apr 22nd, 2016, 8:58am

Hi Mark A -- Thanks for suggestions. I honest-to-God just can't figure this out. What seems so strange is that I can see the value of $StartDate, since it's sitting there right at the top of the item as a displayed Key Attribute. So in the results of a query searching for $StartDate in the past, I see an item whose $StartDate, right in front of me, is a month in the future. Go figure.

So here is my workaround, on which I seek your confirmation:
  • I'm going to stop messing around with $StartDate. Instead I'm going to create a new date-type value, $StartingDate
  • By default, its value will be "never"
  • I will add specific values only when I want to set something to be suppressed until its time arrives
  • And I will have a query, $StartingDate<date("today")

Now the question: for the majority of items that have no value, or with "never" as their $StartingDate, will they be included in my query. That is, is "never" an earlier time than "today"? Or will the query be limited to items with some non-default value in $StartingDate?

I can see how this looks with trial and error, but looking for the Official Answer? And, if I want to exclude "never" items, does the query need to be: $StartingDate & $StartingDate<date("today")       Or does the second part of that query imply the first? Thanks

Further head-scratcher update: I wonder if Mark A or Mark B, or other actual coders, can explain this behavior to me.

I have the new date attribute $StartingDate. The default value for the attribute is "never". Of the 1000+ items in the file, all but two have the default value. The other two have values in the future. But:
  • This query, $StartingDate>date("today") , copied verbatim from the query box, returns all notes except the two with future values, which is to say all notes with "never" values; while
  • This query, $StartingDate!>date("today"), again copied verbatim, returns only the two notes whose $StartingDate has not yet arrived.

This is exactly the opposite of what I would expect. To me, the first query means "show me everything whose date is after today, and the second means "show me everything whose date is not after today." And the results seem just the reverse.

What am I missing?

Title: Re: Puzzle on a query
Post by Mark Bernstein on Apr 22nd, 2016, 11:09am

Aha.

I notice that in your question you sometimes use $StartDate and sometimes use $StartingDate.  $StartDate is built in; $StartingDate, unless it's a user attribute, doesn't exist and will always return never.

- - -

I think your first instinct -- to check an agent with only the data clause, was right; the best way to debug a query is to make it so simple that it could not possibly fail.

What happens, then, if you check an agent with only the Prototype clause?  Sure, that can't possibly be wrong -- but it's worth a look.  Possibilities (from my own mistakes) include
  • mistyping "Prototype"
  • mistyping the name of the prototype
  • forgetting the quotation marks surrounding the prototype path
  • having several different notes sharing the same name as the prototype
  • renaming the prototype but not updating the query

Title: Re: Puzzle on a query
Post by J Fallows on Apr 22nd, 2016, 12:01pm


Quote:
I notice that in your question you sometimes use $StartDate and sometimes use $StartingDate.


HI, Mark B -- Sorry, I buried some crucial info in an update that you might not have seen.

Because I was having such quandaries with the built-in $StartDate, I created a new date-type attribute $StartingDate, and had "never" as its default. I assigned a value to only two (of ~1000) notes. To both of those,I gave a future value to $StartingDate.

I figured that this would avoid any undetected oddities with rules, actions, etc affecting $StartDate.

So the puzzlement I now have is the one mentioned at the last update I posted.I'll repeat it here for clarity. (I will avoid including significant info in updates from now on!)
***

Further head-scratcher update: I wonder if Mark A or Mark B, or other actual coders, can explain this behavior to me.

  • I have the new date attribute $StartingDate. The default value for the attribute is "never". Of the 1000+ items in the file, all but two have the default value. The other two have values in the future. But:
  • This query, $StartingDate>date("today") , copied verbatim from the query box, returns all notes except the two with future values, which is to say all notes with "never" values; while
  • This query, $StartingDate!>date("today"), again copied verbatim, returns only the two notes whose $StartingDate has not yet arrived.


This is exactly the opposite of what I would expect. To me, the first query means "show me everything whose date is after today, and the second means "show me everything whose date is not after today." And the results seem just the reverse.

What am I missing?

Title: Re: Puzzle on a query
Post by Mark Anderson on Apr 22nd, 2016, 12:23pm

$StartingDate!>date("today")

I think I can see what you intend here but this is invalid syntax so results could be anything. I assume you meant to test that $StartingDate is not greater than (i.e. after) 'today'. Note 'today' means 'now' which means the exact date/time at which the code is evaluated:

!($StartingDate>date("today"))

Negative queries always seem problematic. Why not use

$StartingDate<date("today")
or
$StartingDate<date("today+1")
or
$StartingDate<date("tomorrow")

...depending on whether you want to test in date/time or by day.

Anyway, the point here isn't to be pedantic or snippy about your test. I just want to make sure we're testing the right thing. How about putting the file on a dropbox link as then we're all testing against the same code.  :)

Title: Re: Puzzle on a query
Post by Mark Bernstein on Apr 22nd, 2016, 12:33pm

Negative queries
The operator !> is a clever idea, but it doesn't exist.  The only operator of this sort is !=.

You can always write !(a>b), which will be true if a is NOT greater than b.  Or, you can write a<=b.  These are equivalent for numbers and strings, but may be subtly different for dates because two dates are equal if they're on the same calendar day.

Comparing dates to never
When you sort a container by date, you frequently are interested in the handful of notes that have dates and less interested in those notes that do not.  To facilitate this, date comparison treats never as being in the distant future.

So, for your agent, you'll want to exclude never:

    $StartDate>date("today")&$StartDate!="never"

I made a test file and this does seem to do what you'd expect.

Finally, since you do have 1000 items (and may also have other agents), you might want to make sure that the agent has actually had time to run by taking a glance at the inspector.

Title: Re: Puzzle on a query
Post by J Fallows on Apr 22nd, 2016, 12:35pm


Quote:
I think I can see what you intend here but this is invalid syntax so results could be anything. I assume you meant to test that $StartingDate is not greater than (i.e. after) 'today'. Note 'today' means 'now' which means the exact date/time at which the code is evaluated:


Mark A, thanks, about to get on flight to Calif so will tinker with this en route.

I may not have explained myself clearly. I am trying to test the reverse proposition: looking for events whose $StartingDate has not yet occurred. And my puzzlement is that the results I get are the reverse of what I expected.

Getting on plane now, will experiment in next few hours, thanks for guidance (and for clarity on the way ! and > are supposed to interact.)

Title: Re: Puzzle on a query
Post by J Fallows on Apr 22nd, 2016, 2:09pm

Surprisingly I am online from aloft, so to close the loop on the two things I have learned here, and that I think should resolve this issue.

1) "Never" is in the distant future, not the distant past. Now that I know that, I of course understand why "never" events show up in queries looking for dates after today. I had assumed, without asking or checking, that "never" was a version of absolute-zero, or minus-infinity, and thus would only show up in "before" or "less than" queries.

2) Now I know about "!>" (and understand how to get what I am looking for).

Thanks, and again have been asking in public in case anyone else goes down this path.

Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com) » Powered by YaBB 2.2.1!
YaBB © 2000-2008. All Rights Reserved.