Number of conversations by contact

103 views
Skip to first unread message

JJ

unread,
Jun 30, 2021, 7:18:58 AM6/30/21
to TiddlyWiki
Hello,

I have tiddlers tagged with "Person" for contacts. For each conversation, I created a new tiddler with the content of the conversation along with the field "contact", in which the Person is mentioned. The conversation tiddler is tagged "Conversation".

Now I'd like to create a table, which shows me the People I talked to with the amount of conversations I had with them. Sometimes, the conversation is with more than one person, so I write two names in the contact-field, like "PersonOne PersonTwo". I understood that separating those, I should use the enlist-operator.

I tried the following, but I cannot find out, what to write in the space marked with ????. If I try to enter one Persons name manually, the correct count shows up in all rows, as expected. Somehow, I need to reference the currentTiddler, but I don't know how.

Could someone point me in the right direction?
Many Thanks!
JJ

<table>
  <tr>
    <th>Person</th>
    <th>Conversation Count</th>
  </tr>
<$list filter="[tag[Person]sort[caption]]">
<tr>
  <td><$link to={{!!title}}>{{!!title}}</$link></td>
  <td>{{{ [tag[Conversation]contact[????]count[]] }}} </td>
</tr>
</$list>
</table>

Soren Bjornstad

unread,
Jun 30, 2021, 7:55:14 AM6/30/21
to TiddlyWiki
Hi JJ,

On Wednesday, June 30, 2021 at 6:18:58 AM UTC-5 JJ wrote:
Now I'd like to create a table, which shows me the People I talked to with the amount of conversations I had with them. Sometimes, the conversation is with more than one person, so I write two names in the contact-field, like "PersonOne PersonTwo". I understood that separating those, I should use the enlist-operator.

I don't see you using the enlist operator in the snippet above? Anyway, I would use contains, not enlist – it's possible to do it with enlist, but makes things unnecessarily trickier.
 
I tried the following, but I cannot find out, what to write in the space marked with ????. If I try to enter one Persons name manually, the correct count shows up in all rows, as expected. Somehow, I need to reference the currentTiddler, but I don't know how.

You need to use a soft parameter with <> or {} instead of [], which fill in the value of a variable or field respectively. So your filter would look like:

[tag[Conversation]contains:contact<currentTiddler>]

Or equivalently:

[tag[Conversation]contains:contact{!!title}]

See Filters and Transclusions for more on this.

It's worth noting you can take advantage of the $count widget and some default parameters of $link to simplify all this:

<$list filter="[tag[Person]sort[caption]]">
<tr>
  <td><$link /></td>
  <td><$count filter="[tag[Conversation]contains:contact<currentTiddler>]"/></td>
</tr>
</$list>

(But did you really want the title to display for each person after you sorted by the caption? You might prefer:

<td><$link to={{!!title}}><$transclude field="caption">{{!!title}}</$transclude></$link></td>

...which will show the caption if it exists and the title otherwise, linking to the title in either case.)

JJ

unread,
Jul 1, 2021, 2:46:17 AM7/1/21
to TiddlyWiki
Thank you so much for the solution and extensive explanation! It's working perfectly.

A follow up question: Would it be possible to sort the table by the column "Conversations" in descending order of number of conversations? I can imagine that it's hard with the current solution because TW renders the table line by line for each Person.

I also tried using TiddlyTables. Using the tbl-anything column with a custom column template 

<td>
<$count filter="[tag[Conversation]contains:contact<currentRecord>]"/>
</td> 

works the same as above solution and shows the correct number of conversations per contact.
I can click on the column header to sort it, but nothing happens. Also I tried changing the sort mode in the settings without luck. I guess the table is still being rendered line by line alphabetically by person because that is the initial filter expression.

Any ideas how to sort the column?
Thanks again!
JJ

Eric Shulman

unread,
Jul 1, 2021, 4:45:39 AM7/1/21
to TiddlyWiki
On Wednesday, June 30, 2021 at 11:46:17 PM UTC-7 JJ wrote:
A follow up question: Would it be possible to sort the table by the column "Conversations" in descending order of number of conversations?

You can use the sortsub[] filter operator to sort the Person list, based on the number of Conversations that list that person.

Try this:
\define byCount() [<currentTiddler>listed[contact]tag[Conversation]!has[draft.of]count[]]
<table>
  <tr><th>Person</th><th>Conversation Count</th></tr>
   <$list filter="[tag[Person]!sortsub:integer<byCount>]">
      <tr><td><$link/></td><td><$text text={{{ [subfilter<byCount>] }}}/></td></tr>
   </$list>
</table>
 
Notes:
* The byCount() macro is needed because the sortsub parameter is itself a filter syntax that contains square brackets, and you can't "nest" the square brackets.
* I used <currentTiddler>listed[contact]tag[Conversation] ("find all tiddlers with the currentTiddler listed as a contact that are also tagged as Conversations") rather than tag[Conversation]contains:contact<currentTiddler> ("find all tiddlers tagged as Conversations that contain the currentTiddler in the contact field").  Although these filters may seem to be equivalent, they produce different results.  I have to admit that I'm not sure why... but the "listed" filter produces the correct results, while the "contains" filter doesn't.
* I added !has[draft.of] to the filter to exclude any tiddlers that are currently being edited
* I re-used the <byCount> filter in a $text widget to display the actual count value

enjoy,
-e

JJ

unread,
Jul 1, 2021, 6:17:04 AM7/1/21
to TiddlyWiki
Thank you, Eric, it's working well!
Such an elegant solution, short text of code and a lot of things to study for me :-)

Reply all
Reply to author
Forward
0 new messages