openmolecules.org

 
Home » DataWarrior » Functionality » Macro questions: preserving columnProperty and setting date filter
Macro questions: preserving columnProperty and setting date filter [message #1217] Fri, 05 February 2021 16:36 Go to next message
Andrew0
Messages: 19
Registered: August 2015
Junior Member
Hello Thomas,

I have a macro that has the following basic workflow:

  1. Open a text file
  2. Apply a template from an existing .dwar file
  3. Update some filters

I recently discovered the columnProperty field from http://openmolecules.org/forum/index.php?t=msg&goto=765, and am making use of this to link to source data. It seems that when I apply a template that has defined columnProperty values, they are not carried into the new file. Is this expected behavior, or is there a way I can carry these columnProperty values over?

Secondly, one of the filters I update at the conclusion of the macro is a date filter. Does DataWarrior use a standard date format? In the macro the date appears as a float value, which doesn't correspond to date formats that I'm familiar with.

Thank you for your continued development of this tool - it's a huge benefit to the community!

Andrew
Re: Macro questions: preserving columnProperty and setting date filter [message #1224 is a reply to message #1217] Thu, 11 February 2021 11:37 Go to previous messageGo to next message
thomas is currently offline  thomas
Messages: 715
Registered: June 2014
Senior Member
Hi Andrew,

column properties are considered to belong to the data and not to the definition of how to display the data.
Therefore, they are not part of the template. However, you may use the macro task 'Set Column Properties'
to add (or replace) column properties to a column.

When DataWarrior analyses a column, then it is rather flexible concerning data formats. It basically checks, whether it can find three different values per cell and whether they fit in the range of what could be interpreted as data value. If cell entries are plausible dates, then these are converted into float values representing the number of milliseconds since Jan 1st, 1970. This value is used internally for filtering, axis assignment, etc. And it end up in the template filter section.
(https://currentmillis.com/)

Thomas

[Updated on: Thu, 11 February 2021 11:37]

Report message to a moderator

Re: Macro questions: preserving columnProperty and setting date filter [message #1225 is a reply to message #1217] Thu, 11 February 2021 19:39 Go to previous messageGo to next message
Andrew0
Messages: 19
Registered: August 2015
Junior Member
Thomas,

Thanks very much for your reply. I have two (hopefully small) followup questions:

Using the macro editor, I was able to access "Set Column Properties" as you suggested. However, my macro does not appear to be writing the desired values to the column properties. Can you look at the macro below and let me know where my syntax is going wrong? I tried to implement the example you gave in http://openmolecules.org/forum/index.php?t=msg&goto=765

<macro name="colPropsTest">
<task name="setColumnProperties">
properties=lookupCount\t1<NL>lookupName0\tWikipedia Entry<NL>lookupURL0\thttp://en.wikipedia.org/wiki/%s
replace=true
column=Compound Name
</task>
</macro>

The "\t" in the code block above represent TAB characters.

Your response to the second question also makes sense. Is there any way to access the current time in milliseconds in DataWarrior macros? For example, if I want to update the filter to only display the last X days of data.

Thank you,
Andrew

[Updated on: Thu, 11 February 2021 19:40]

Report message to a moderator

Re: Macro questions: preserving columnProperty and setting date filter [message #1227 is a reply to message #1225] Fri, 12 February 2021 12:33 Go to previous messageGo to next message
thomas is currently offline  thomas
Messages: 715
Registered: June 2014
Senior Member
Hi Andrew,

first I must correct myself. The stored and used date value is not the milliseconds value itself. It is the milliseconds since Jan 1st, 1970 devided by 86400000, which makes the float the number of days since Jan 1st, 1970.

You cannot use a macro or filter to directly filter dates in relation to the current date, but you can calculate a new column (e.g. in a macro) using an expression like 'today()-myDateColumn' and then use a filter on that column.

Your other question related to the column properties macro: This will work if you replace the TABs by equal signs ("\t" by "="). TABs are used as separators in the column properties section of the file. The column properties dialog uses equal signs, because they are more user friendly. And they are also used within the macro file format. TABs as separators in the file have been a strange decision, but now they are there to live with them.

Thomas
Re: Macro questions: preserving columnProperty and setting date filter [message #1230 is a reply to message #1217] Tue, 16 February 2021 18:40 Go to previous message
Andrew0
Messages: 19
Registered: August 2015
Junior Member
That worked perfectly, thank you Thomas!
Previous Topic: 2D coordinates in the template
Next Topic: Confidentiality of compound structures
Goto Forum:
  


Current Time: Fri Nov 22 10:33:06 CET 2024

Total time taken to generate the page: 0.03730 seconds