How to create a new field and translate multiple values with a dictionary?

160 views
Skip to first unread message

Harry

unread,
Dec 10, 2020, 10:01:17 PM12/10/20
to TiddlyWiki
Hi,

I have a tiddlywiki with multiple entries. I now want to assign a unique field value for every entry so that I can sort them in a particular way. Is there a way that I can do this with button or other batch orders. I searched and found something of creating a dictionary.

Say I select all entries with birthdays entered.
<$list filter="[has:field[birth_year]]">

Then I want to create a new field called "rankcode" for each entry, translating their titles to a unique 6-digit code in their, using the dictionary below

John Smith (Reno):BCD-75A
John Adams:5GH-6GB
Brian Kim:67A-300
Cris Stuart (NV):3ZH-UV5

I'd appreciate help on how to do this. I tried $action-setfield to assign one single value to one entry at a time, but don't know how to do this en masse using sth like a dictionary. Many thanks!

Harry

unread,
Dec 10, 2020, 11:52:42 PM12/10/20
to TiddlyWiki
Another novice question:

I want to filter all entries born before 1948 (in the birth_year field) who has not died or been purged (in the c_status field), and assign them value "retired". The following code I created apparently contains error. I would also appreciate general guidance on filtering field value of a certain numeric range (say greater than 1952, or between 1936 and 1978) or value of a particular vector (say contains either 1,3,8,16,33,47,287,1345,9999 etc, do I need to name another tiddly for reference? Kind of confused after some research)

<$button> assign retired
   <$list filter="[field[birth_year]<<1948]-[field[c_status]=dead]-[field[c_status]=purged]">
      <$action-setfield $field="c_status" $value="retired" />
   </$list>
</$button>

Eric Shulman

unread,
Dec 11, 2020, 5:54:48 AM12/11/20
to TiddlyWiki
Here's some sample filter logic for each of the conditions you want:

On Thursday, December 10, 2020 at 8:52:42 PM UTC-8 Harry wrote:
I want to filter all entries born before 1948 (in the birth_year field) who has not died or been purged (in the c_status field), and assign them value "retired".

birth_date < 1948 and not c_status=dead and not c_status=purged
<$button> assign retired
<$list filter="[has[birth_year]]">
   <$list filter="[<currentTiddler>get[birth_year]compare:integer:lt[1948]then<currentTiddler>!c_status[dead]!c_status[purged]]">
      <$action-setfield c_status="retired" />
   </$list>
</$list>
</$button>

I would also appreciate general guidance on filtering field value of a certain numeric range (say greater than 1952, or between 1936 and 1978)

birth_date > 1952
<$list filter="[has[birth_year]]">
   <$list filter="[<currentTiddler>get[birth_year]compare:integer:gt[1952]then<currentTiddler>]">
      <<currentTiddler>><br>
   </$list>
</$list>

birth_date between 1936 and 1978 (inclusive)
<$list filter="[has[birth_year]]">
   <$list filter="[<currentTiddler>get[birth_year]compare:integer:gteq[1936]compare:integer:lteq[1978]then<currentTiddler>]">
      <<currentTiddler>><br>
   </$list>
</$list>
 
or value of a particular vector (say contains either 1,3,8,16,33,47,287,1345,9999 etc,

somefield contains any of 1,3,8,16,33,47,287,1345,9999
<$list filter="[has[somefield]]">
   <$list filter="[enlist[1 3 8 16 33 47 287 1345 9999]match{!!somefield}then<currentTiddler>]">
      <<currentTiddler>><br>
   </$list>
</$list>

enjoy,
-e

Ste

unread,
Dec 11, 2020, 6:11:18 AM12/11/20
to TiddlyWiki

Mohammed's tiddly commander thing also allows batch operations. 
I'll try and dig out the link when I get chance of no one beats me to it. 

Harry

unread,
Dec 11, 2020, 10:05:32 AM12/11/20
to TiddlyWiki
Thanks Eric! may I ask you to also look into the question in my first post? ( create a new field using a dictionary tiddler)

Also I tried the code you provided, really learned a lot on the compare operator.But when I click the button, nothing changes. I wonder if this is because my birth_year field also has "na" as a value, I changed all na to 0, but the button still does not work.
<$button> assign retired
<$list filter="[has[birth_year]]">
   <$list filter="[<currentTiddler>get[birth_year]compare:integer:lt[1948]then<currentTiddler>!c_status[dead]!c_status[purged]]">
      <$action-setfield c_status="retired" />
   </$list>
</$list>
</$button>

I then tried the following code to create a list, but the tiddler still shows nothing. I wonder if you have any idea about what might be wrong with my dataset? Many thanks!

<$list filter="[has[birth_year]]">
 <$list filter="[<currentTiddler>get[birth_year]compare:number:gteq[1]compare:number:lteq[1948]]">
      <<currentTiddler>><br>
   </$list>
</$list>

Eric Shulman

unread,
Dec 11, 2020, 12:46:10 PM12/11/20
to TiddlyWiki
On Friday, December 11, 2020 at 7:05:32 AM UTC-8 Harry wrote:
when I click the button, nothing changes. I wonder if this is because my birth_year field also has "na" as a value, I changed all na to 0, but the button still does not work.
<$button> assign retired
<$list filter="[has[birth_year]]">
   <$list filter="[<currentTiddler>get[birth_year]compare:integer:lt[1948]then<currentTiddler>!c_status[dead]!c_status[purged]]">
      <$action-setfield c_status="retired" />
   </$list>
</$list>
</$button>

A field value of "na" is equivalent to "0".  I tried the above code on TiddlyWiki.com, providing it with a tiddler named "test", containing a "birth_year" field containing "na".  After pressing the button, the "test" tiddler had a new "c_status" field added, containing a value of "retired".  Note that to see this field and value, you have to edit the "test" tiddler.
 
I then tried the following code to create a list, but the tiddler still shows nothing. I wonder if you have any idea about what might be wrong with my dataset? Many thanks!
<$list filter="[has[birth_year]]">
 <$list filter="[<currentTiddler>get[birth_year]compare:number:gteq[1]compare:number:lteq[1948]]">
      <<currentTiddler>><br>
   </$list>
</$list>

You left off the "then<currentTiddler>" syntax that follows the compare.  Without this, the result of the filter is the value that you get[...] from the birth_year field, rather than the title of the matching tiddler.  Also, your first compare is "gteq[1]", so this would not match tiddlers where the "birth_year" field contains "0" (or "na").  If you change the filter to:
 <$list filter="[<currentTiddler>get[birth_year]compare:number:gteq[0]compare:number:lteq[1948]then<currentTiddler>]">
it will show tiddler titles for all tiddlers with a non-blank "birth_year" field, even those with a value of "0" or "na".

enjoy,
-e 
Reply all
Reply to author
Forward
0 new messages