Formula 0.2: Functional computing & spreadsheet formulas for TiddlyWiki

908 views
Skip to first unread message

Evan Balster

unread,
Jan 17, 2018, 2:15:24 AM1/17/18
to TiddlyWiki
Announcing the second generation of my formula plugin for TiddlyWiki.

See the Formula wiki for the latest documentation:  http://evanbalster.com/tiddlywiki/formulas.html

Report issues and view source GitHub:  https://github.com/EvanBalster/TiddlyWikiFormula


Formula lets you do computation in TiddlyWiki in the style of popular spreadsheet apps Excel and Google Sheets, with the addition of TiddlyWiki's own filter, transclude and variable systems.  Tiddlers can behave like individual rows in a spreadsheet.  A large collection of built-in functions is included, for use with text, numbers, dates, arrays and regular expressions.

Formula is implemented as a widget, with a special (= "mushroom bracket" =) syntax for inclusion in WikiText, and can also be used in widget/HTML attributes.  Formulas included via transclusion, filters and variables are computed and refreshed like any other part of your wiki.

(= ( sum([tag[Profits]get[value]]) - sum(tag[Expenses]get[value]]) ) * {{Tax!!rate}} =)

The second generation of formula adds support for local variables, comments, lambda functions and element-wise operations on arrays (such as filter results), allowing more advanced computations to be expressed inside TiddlyWiki.  Search the wiki for "demo" to see some of the things I've built.


The plugin is a work in progress and may have bugs.  Please report these on GitHub or in this thread.

Evan Balster

unread,
Jan 17, 2018, 2:17:14 AM1/17/18
to TiddlyWiki
I've started this new thread because some users were complaining that the length of the previous thread was making it hard to read and navigate on some devices.

Changelog for version 0.2.1:

0.2.1 — January 16, 2018

  • Implemented /* comments */ in the C/JavaScript style.
  • Implemented closures — functions can now "capture" local variables declared outside them.
    • Note: Variables are captured from the place a function is declared, not where it is used.
  • Added the join function, which is simpler than textjoin.
  • Fixed a major error in value conversion that caused a reversion to JavaScript behaviors.
  • Fixed the transclude_index function.

@TiddlyTweeter

unread,
Jan 17, 2018, 6:19:45 AM1/17/18
to TiddlyWiki
Ciao Evan

IMO, this plugin is SO rich it deserves an EXAMPLE CHANNEL.

I'm wondering if you'd be okay if I started another thread about developing examples of usage? Not necessarily for you to answer on but also other folk who are developing grasp of what it can do?

FWIW, I'm down on the farm of basic accounts, but I could probably rise to the challenge of how you could use your math to visually create kinship charts.

Josiah

Stephen Wilson

unread,
Jan 17, 2018, 7:49:03 AM1/17/18
to TiddlyWiki
Hi Evan,
Don't know if your aware, or if it's useful, but Matt did some graph work last year.

PMario

unread,
Jan 17, 2018, 7:57:25 AM1/17/18
to TiddlyWiki
On Wednesday, January 17, 2018 at 8:15:24 AM UTC+1, Evan Balster wrote:
Announcing the second generation of my formula plugin for TiddlyWiki.

See the Formula wiki for the latest documentation:  http://evanbalster.com/tiddlywiki/formulas.html

Great Work!

I just had a view about your licensing. ... Most of your plugins use MIT license, which is great. ... But some don't have any license. ...

You also should consider, to switch those plugins, that you want to be part of the TiddlyWiki core, to be "BSD 3 clause" see: [1]. OR you can also use a dual license, for those parts. MIT and BSD-3clause work well together but the TW core needs BSD [1]

Just to be clearer. ... If you stay with MIT, it won't be a big problem, because MIT allows us to change the license to BSD, once we include stuff from your plugins into the core [2]. The other way around would not be possible, except with a dual-license.

have fun!
mario

[2] https://en.wikipedia.org/wiki/License_compatibility#Compatibility_of_FOSS_licenses

hubertgk

unread,
Jan 18, 2018, 9:06:40 AM1/18/18
to tiddl...@googlegroups.com
Hi Evan,

Great work on the plugin!

Just wondering, has IFERROR been implemented yet? It's listed as a function under 'Selection' but when I try to use it I get the following exception:

CompileError: unknown function: IFERROR

I'm on version 0.2.1. The online 'Try Me' field shows the same error.

Thanks!

Abraham Samma

unread,
Jan 18, 2018, 1:23:05 PM1/18/18
to TiddlyWiki
A little off topic here (great work Evan) but the problem of licensing or lack thereof is an issue for many useful TW5 plugins, here's an example, a useful one by Danielo Rodriguez but with no license (if he sees this, could he possibly clarify the rights given for his plugin if any).

It would be very useful for all potential plugin authors present and future to please include an up to date license for your works. It really helps and it is super important I believe.

This probably deserves its own thread. Apologies.

Evan Balster

unread,
Jan 18, 2018, 1:35:13 PM1/18/18
to TiddlyWiki
Hey, all —

You also should consider, to switch those plugins, that you want to be part of the TiddlyWiki core, to be "BSD 3 clause"

I can do this the next time I make an update.  With formula in particular I'm expecting a period of maturation and conversation with core developers before it's considered for a merge.  I'm doing a lot of cowboy coding at this stage. 

I'm wondering if you'd be okay if I started another thread about developing examples of usage? Not necessarily for you to answer on but also other folk who are developing grasp of what it can do?

Makes perfect sense to me.  I would have some examples to contribute, myself.  And I might incorporate others into the formula wiki's repository of demos. 

It would be very useful for all potential plugin authors present and future to please include an up to date license for your works. It really helps and it is super important I believe.  This probably deserves its own thread. Apologies. 

Also very sensible.  Make a PSA thread!

Don't know if your aware, or if it's useful, but Matt did some graph work last year.

Neat!  I'm working to make formula powerful enough that graphs can be made by combining SVG and formula code.  Any input on that is welcome — I'm currently writing some complicated programs to test the programming capabilities and see what sort of walls I run into.

Just wondering, has IFERROR been implemented yet?

What, I have to implement things before I document them?  :)  But seriously, that one's my bad.  I think it's commented out in the implementation code.  I'll look into fixing that next update.

Because the complexity of what can be written in formula is rapidly increasing, I'm thinking about ways to improve the plugin's error reporting.  Specifically, it's often used in places (attributes, SVG) where error text won't be visible...  It's also useful to know when an error originates inside a certain function, LET value or transclusion...


On Wednesday, 17 January 2018 01:15:24 UTC-6, Evan Balster wrote:

Mr. Mal

unread,
Jan 18, 2018, 11:18:55 PM1/18/18
to TiddlyWiki
I think the now and date function not working in this release. May be others can confirm this "bug".

Diego Mesa

unread,
Jan 19, 2018, 12:01:20 AM1/19/18
to TiddlyWiki
Hm - Maybe a great time for all of us start contributing tests!

Evan Balster

unread,
Jan 19, 2018, 2:28:44 AM1/19/18
to TiddlyWiki
Bug(s) confirmed — array and date formatting aren't working correctly.  Need to investigate why.

There is also an issue with parsing block comments in Formula 0.2.1, which has been fixed in the repo.

Suggested format for unit-test and bug-repro contributions:
  • Tag with "FormulaTest"
  • Prefix "Test/"
  • Text comprises a single formula construct (of any type) whose result should render to TRUE, *or* match the result of rendering field "match" of the tiddler if present.
  • Submitted as JSON files here

Diego Mesa

unread,
Jan 19, 2018, 11:37:43 AM1/19/18
to TiddlyWiki
Hey Evan,

I was going to start adding some more, but the format you described above is slightly different than the previous one:

http://evanbalster.com/tiddlywiki/formulas.html#UnitTest%2FFunctions%2Fnth%2Fsorted-return

Which do you think we should stick with?

Diego

Evan Balster

unread,
Jan 19, 2018, 3:44:29 PM1/19/18
to TiddlyWiki
Both formats look good, so I'll take the best parts of each:
  • Unit tests:
    • Tiddlers tagged with FormulaTest.
    • Text is expected to render to TRUE
      • Advanced: If the field match is present on the tiddler, text is instead expected to render to the same result as rendering match.
    • Name using a prefix scheme based on the test subject
      • BugsFormulaTest/Regression/<Test Name>
      • FunctionsFormulaTest/Functions/<Function Name>/<Test Name>
        • Function names in ALL CAPS
      • LanguageFormulaTest/Feature/<Feature Name>/<Test Name>
        • Feature names being things like "Let", "Function", "Closure", "Transclude"
      • Syntax & CompilationFormulaTest/Compiler/<Feature Name>/<Test Name>
      • Miscellaneous TestsFormulaTest/Misc/<Test Name>
  • Additional tiddlers used as data in unit tests:
    • Tag with FormulaTestData.
    • Prefix with the unit test's fully-prefixed name, with an additional slash and name.
Ideally, unit tests and bug repros should be submitted on GitHub (see my call for unit tests there) but uploading JSON files in this thread is OK too.

Diego Mesa

unread,
Feb 1, 2018, 3:32:34 PM2/1/18
to TiddlyWiki
Hey all,

I am trying to use this plugin in button actions like so:

\define updateActions(newVal)
<$action-setfield $field="t1" $value="0"/>
<$action-setfield $field="t2" $value=$newVal$/>
<$action-setfield $field="t3" $value=(=3+1=)/>
<$action-setfield $field="t4" $value=(={{!!t3}}+20=)/>
\end


<$button actions=<<updateActions 10>> >
Do it!
</$button>


I am trying to make a spaced-repetition system like this. Any help would be greately appreciated!

Diego Mesa

unread,
Feb 1, 2018, 3:57:44 PM2/1/18
to TiddlyWiki
Hey all,

Sorry a better example of what Im trying to accomplish:

<$button >
<$formula-vars val1="2+3" val2="<
<val1>>+6" val3="{{!!t2}}+12">
<$action-setfield $field="t1" $value=<
<val1>>/>
<$action-setfield $field="t2" $value=<
<val2>>/>
<$action-setfield $field="t3" $value=<
<val3>>/>
</$formula-vars>
Do it!
</$button>


I can understand why it wouldn't work, but it seems tobias' excellent setvars plugin will allow you to do something like this:


<$setvars
_attr1=<
<currentTiddler>>
_attr2={{!!title}}
_attr3="1 2 3"
_attr4="[all[current]tagging[]]"
var1="attr1 \ = literal = \ attr2"
var2="attr3[n] \ \ [attr4[1,2][when-empty]] \ \ [attr3[][][ - ]]"
var3="if(attr1 ? [attr4]) || attr3 attr2"
var4="if(attr1 == attr2 ? attr3[1]) || [attr3[2]]">
* <
<var1>>
* <
<var2>>
* <
<var3>>
* <
<var4>>
</$setvars>


 Does formula let you do this type of cascading?

Diego Mesa

unread,
Feb 1, 2018, 4:07:36 PM2/1/18
to TiddlyWiki
Update:

This cascading does indeed work:

<$button >
<$formula-vars val1="2+3">
<$action-setfield $field="t1" $value=<
<val1>>/>
<$formula-vars val2="<
<val1>> + 10">
<$action-setfield $field="t2" $value=<
<val2>>/>
<$formula-vars val3="<
<val2>> + 100">
<$action-setfield $field="t3" $value=<
<val3>>/>
</$formula-vars>
</$formula-vars>
</$formula-vars>
Do it!
</$button>

Evan Balster

unread,
Feb 1, 2018, 4:24:58 PM2/1/18
to TiddlyWiki
Hey, Diego —

I've been interested in supporting "cascading" in a single widget in formula-vars, but there's no way for a widget to know the order in which attributes are written with certainty.  For that reason and because I've now implemented "cascading" in formulas' LET construct, I've been thinking about adding an idiom for constructing key-value objects in formulas, and making it possible to export one of these as a set of TiddlyWiki variables.

That would look something like this:

<$formula-vars $dict="""
  dict(
    t1 = 0,
    t2 = <
<newVal>>,
    t3 = 3+1,
    t4 = t3+20)
  """>
  ...
</$formula-vars>

At which point the primitive objects usable in formulas start to look a lot like JavaScript's!  Hashmaps (aka "objects" aka "dictionaries") are useful for lots of things...

Diego Mesa

unread,
Feb 1, 2018, 5:05:47 PM2/1/18
to TiddlyWiki
Thanks for the reply Evan this seems like a really useful feature

coda coder

unread,
Feb 1, 2018, 5:09:57 PM2/1/18
to TiddlyWiki
Hi Evan


On Thursday, February 1, 2018 at 3:24:58 PM UTC-6, Evan Balster wrote:

That would look something like this:

<$formula-vars $dict="""
  dict(
    t1 = 0,
    t2 = <
<newVal>>,
    t3 = 3+1,
    t4 = t3+20)
  """>
  ...
</$formula-vars>

At which point the primitive objects usable in formulas start to look a lot like JavaScript's!  Hashmaps (aka "objects" aka "dictionaries") are useful for lots of things...


At which point, one wonders why you don't add another idiom... json.

<$formula-vars $thing="""
  json {
    t1: 0,
    t2: <
<newVal>>,
    t3: 3+1,
    t4: t3+20}
  """>
  ...
</$formula-vars>

thoughts?

Evan Balster

unread,
Feb 1, 2018, 5:18:07 PM2/1/18
to TiddlyWiki
Hey, Coda —

With the full set of values supported, working with JSON data would be perfectly feasible.  Putting it directly in formulas is a can of worms, though.  I'm already treading a fine line between conforming to WikiText syntax and filter syntax and standard spreadsheet syntax while maintaining a consistent code style...  Merging JSON into that, with its syntactic nuances, would threaten to over-constrain things.

On the upside, you could just do

json({{MyJsonTiddler}})

On a related note, I want to support excel style array literals, but the distinction with transclusions will be nuanced when they nest.  Fortunately Excel and Sheets both include a 2D array syntax already...

{1, 2, 3; 4, 5, 6; 7, 8, "fish"}

The curly braces are, of course, anathema to the JavaScript developer.  :)

Diego Mesa

unread,
Feb 2, 2018, 4:48:35 PM2/2/18
to TiddlyWiki
Hey Evan,

Just wanted to bump this to see if Formula 0.2.2 could make its way to the site when you get a chance.

Best,

Diego

On Friday, January 19, 2018 at 1:28:44 AM UTC-6, Evan Balster wrote:

Evan Balster

unread,
Feb 2, 2018, 5:42:23 PM2/2/18
to TiddlyWiki
Tomorrow, probably.  I've been away at the NAMM Show for imitone, and I've had a lot of catching up to do.

coda coder

unread,
Feb 2, 2018, 5:56:37 PM2/2/18
to TiddlyWiki
NAMM.  Jeez... always wanted to go, never have.  Probably never will (too old, too lazy).

TonyM

unread,
Feb 2, 2018, 8:50:16 PM2/2/18
to TiddlyWiki
Evan and any others?

On installing the 0.2.0 Version I noticed a lot of my date functions are returning 
ComputeError: Cannot auto-convert "" to a date!
and in other views 
ComputeError: Cannot auto-convert "2017122410592500" to a date! 

This is from of the following

A Macro <<daystoday item-touched>>

Where item-touched is a date field with or without a date

\define daystoday(datefield)
(= days( now(), date( {{!!$datefield$}} )  ) =)
\end

In short it seems to no longer tolerate empty fields 

Nor handle dates the same way,

Any suggestions from your intimate knowledge?

Thanks
Tony

Diego Mesa

unread,
Feb 2, 2018, 9:53:18 PM2/2/18
to TiddlyWiki
Hey Tony,

Earlier in this thread Mr. Mal reported the date related functions as not working and Evan confirmed. A fix is forthcoming

BurningTreeC

unread,
Feb 2, 2018, 11:30:02 PM2/2/18
to TiddlyWiki
Hi Evan,

I've found this handsontable library and tried making a basic widget here: spreadsheet widget

The docs look promising and the interface is very nice - the license is MIT

Simon

Evan Balster

unread,
Feb 3, 2018, 8:54:42 PM2/3/18
to TiddlyWiki
Hey all —


Changes:
  • Fixed a bug in the parsing of /* block comments */// line comments also work.
  • Implemented regular expression literals in the JavaScript style: /regex/g
    • May be used as a Datum
    • When converting strings to regex, both JavaScript and TiddlyWiki styles will be recognized.
  • Formula errors now mention LET assignments they lie inside.
  • Formulas as Tag Attributes are now facilitated by a mod using the experimental Mod-Loader Plugin.

Tony — I fixed some coercion bugs in 0.2.1 but I'm not sure if those cover the issues you're reporting.

The blank definitely won't be treated as a date (what would it default to, anyway?)

As for the other one, 2017122410592500 isn't quite a valid TiddlyWiki date under current semantics.

2017 12 24 10 59 25 00

The last bit (milliseconds) should be either 3 digits or completely absent.  AFAIK TiddlyWiki dates are never expressed to "centisecond" precision so this looks out of place to me.  I'm strict about what Formula interprets as a date, because these strings of digits could also be numbers.


BurningTree — that's a nice looking spreadsheet UI.  Consider your experimentation encouraged!

TonyM

unread,
Feb 3, 2018, 10:35:13 PM2/3/18
to TiddlyWiki
Evan,

Thanks again for your work.

To the point : So I suppose I am asking, "can the treatment of empty or blank date fields be restored?", or could you "tell me a way to treat such fields to avoid the errors?"

I will return to blank dates shortly.

Date Format
First, removing the trailing "00" or using 000 does indeed let a date display correctly THANKYOU
I was erroneously setting dates to one digit short
<$action-setfield $field=date-field $value=<<now YYYY0MM0DD0hh0mm0ss000>> $timestamp=no />
Previously however this was tolerated. As was a date field with only the date YYYY0MM0DD and other combinations (I have not retested)

Blank dates

This behaviour has changed, I am now getting these errors below when previously use of date fields that had empty or a single space in the date field were tolerated and no result was returned,

ComputeError: Cannot auto-convert "" to a date!
ComputeError: Cannot auto-convert " " to a date!

I was using the existence of a date-field to trigger the display, time stamp or edit of that and other fields

  • For example if item-started existed it allows you to "select, enter or time stamp the date"  item-started
  • Basically the existence of item-started indicates the tiddler is now under disposition management (regardless of its value or not)
  • It also provides the ability to optionally provide a item-completed or item-cancelled dates
  • If I accidentally cancelled the item and cleared the item-cancelled date, to instead set the completed date, I would have a blank cancelled date field.
Why permit " " dates
If I am using the existence of a date field empty or otherwise I use a filter that includes has[fieldname]
Of note was that this has[fieldname] filter often seemed only to work when the field existed and was not empty, hence the use of " "

On example of where formulas was tolerant of blank and space was in the following, which calculates the number of days between the date-fields value and today.
\define daystoday(datefield)
(= days( now(), date( {{!!$datefield$}} ) ) =)
\end

Other examples, It is fine for these to return nothing
(= if(tw_date({{!!$datefield$}})=now(),"Today","Not Today") =)

\define showtodayrange(datefield1,datefield2)
<progress value=<<formula "days( date( {{!!$datefield1$}} ) , now() )">> max=<<formula "days( date( {{!!$datefield1$}} ) , date( {{!!$datefield2$}} ))">>/>
\end


<$if value=(={{!!$datefield$}}=)>
 Has value (=date({{!!$datefield$}})=)
 <$set name=indate value= (=date({{!!$datefield$}})=)>
</$if>
<$else>
 No Value (={{!!$datefield$}}=)
 <$set name=indate value=(=now()=)>
</$else>
The above also seems broken, using The Condition plugin for TiddlyWiki, version 0.1.0 (disabled or not)

So I suppose I am asking, "can the treatment of empty or blank date fields be restored?", or could you "tell me a way to treat such fields to avoid the errors?"

Thanks in advance,
Tony

BurningTreeC

unread,
Feb 4, 2018, 1:40:49 AM2/4/18
to TiddlyWiki
BurningTree — that's a nice looking spreadsheet UI.  Consider your experimentation encouraged!

Challenge accepted!

best wishes

Evan Balster

unread,
Feb 4, 2018, 3:09:26 AM2/4/18
to TiddlyWiki
Hey, Tony —

The tw_date function should do what you want:  It manually turns other things into dates, bypassing the normal "interpretation" mechanism.  It will accept YYYYMMDD dates with each subsequent part being optional.  It might not work on data that have been interpreted as numbers, which can happen with {{transclude}} syntax...  To avoid the interpretation, you can use the "transclude" or "variable" functions to fetch raw, uninterpreted text:

... tw_date(transclude("tiddler", "field")) ...

Basically the idea is that all automatic conversion can be bypassed or done manually.

The "fall-back" behaviors you're describing would best be implemented with the "iferror" function, which formula doesn't implement yet.  Other than that I advise using some string-related functions to figure out what kind of data you're dealing with.  For example,
len(trim(x))==0
tells you if some data is blank (ie, only whitespace or nothing at all).

I might have to investigate the interoperation problems between formula and condition.

Diego Mesa

unread,
Feb 6, 2018, 4:30:19 PM2/6/18
to TiddlyWiki
Hey Evan,

Sorry if Im missing something, but is

now() and date(12,12,12)

not working?

Thanks!

Evan Balster

unread,
Feb 9, 2018, 12:52:22 PM2/9/18
to TiddlyWiki
Hey, Diego —

Pardon the slow reply.  I've been pretty busy with Real Work since my convention trip.  I expect to do some more work on formulas this weekend and will be tracking down the issue.

In the future, please file an issue on the plugin's GitHub if possible!  Makes this stuff easier to keep track of.

Evan Balster

unread,
Feb 11, 2018, 10:01:00 PM2/11/18
to TiddlyWiki
Hey all —


Changes:
  • Add Array Literal with conventional syntax, eg. {1, 2, 3, "fork"}.
  • Add array constructor function (added in 0.2.2 but undocumented)
  • Enhanced Cell Reference syntax
    • Column names must be capitalized
    • Support $ absolute references (does not affect formula behavior)
    • The compiler now recognizes cell ranges (but they are unsupported)
  • Fixed date-to-string conversion producing an undefined result.
  • Fixed an error when failing to convert an object to a string.
Thanks Diego for pointing out the date conversion problem, which was quite nasty.  I think there may be an outstanding problem with array-to-string conversion, which I'll try to fix in my next update.


Check out the Auto-Map demo in the latest wiki:  https://evanbalster.com/tiddlywiki/formulas.html#Auto-Map

It's a bit crude but it demonstrates a first take at a self-organizing graph of links within a wiki.


For my next update, I'm thinking about adding a dictionary type (a key-value map like JavaScript's objects) and some related functionality.  Excel and Google Sheets don't support key-value maps so I'm considering my options for syntax design.

@magasine

unread,
Feb 18, 2018, 5:32:54 PM2/18/18
to TiddlyWiki
Hi

I'm trying to use 2 fields as arguments to a function and results in error: "ComputeError: Can not convert 5 to number"

(= divide( {{!! total_presencas}} , {{!! total_integrantes}} ) =)

I also tried filters and the same thing happens

(= [tag{!!grupo}tagging[]has[Presenças]count[]] / [tag{!!grupo}tagging[]count[]] =)

Sorry, I have little code experience and I do not know what the error is.

TIA

Manoel.


Em quarta-feira, 17 de janeiro de 2018 05:15:24 UTC-2, Evan Balster escreveu:
Announcing the second generation of my formula plugin for TiddlyWiki.

See the Formula wiki for the latest documentation:  http://evanbalster.com/tiddlywiki/formulas.html

Report issues and view source GitHub:  https://github.com/EvanBalster/TiddlyWikiFormula


Formula lets you do computation in TiddlyWiki in the style of popular spreadsheet apps Excel and Google Sheets, with the addition of TiddlyWiki's own filter, transclude and variable systems.  Tiddlers can behave like individual rows in a spreadsheet.  A large collection of built-in functions is included, for use with text, numbers, dates, arrays and regular expressions.

Formula is implemented as a widget, with a special (= "mushroom bracket" =) syntax for inclusion in WikiText, and can also be used in widget/HTML attributes.  Formulas included via transclusion, filters and variables are computed and refreshed like any other part of your wiki.

(= ( sum([tag[Profits]get[value]]) - sum(tag[Expenses]get[value]]) ) * {{Tax!!rate}} =)

The second generation of formula adds support for local variables, comments, lambda functions and element-wise operations on arrays (such as filter results), allowing more advanced computations to be expressed inside TiddlyWiki.  Search the wiki for "demo" to see some of the things I've built.


The plugin is a work in progress and may have bugs.  Please report these on GitHub or in this thread.

Evan Balster

unread,
Feb 18, 2018, 8:29:32 PM2/18/18
to TiddlyWiki
Hello —

In your first code example, there is a space after the !!, which is invalid syntax for a TiddlyWiki transclusion.  Or rather, it's looking for a field whose name begins with a space (and no such field exists).

In your second example, you use filters, which always produce an array (list) of things as a result.  Even with the count[] operator you are producing an array which contains the count.  (Automatic conversion might be reasonable here but it's not how Formulas thinks...)  I suggest using the "count" function instead:

count([tag{!!grupo}tagging[]has[Presenças]]) / count([tag{!!grupo}tagging[]])

You could also use the function "first" to grab the first item from the array.

Del Vee

unread,
Mar 5, 2020, 11:52:16 AM3/5/20
to TiddlyWiki
HI,


Could you see it ?

Mark S.

unread,
Mar 5, 2020, 2:44:15 PM3/5/20
to TiddlyWiki
You can try the github site:


Though I see that it, like this thread, hasn't been updated in two years.

Evan Balster

unread,
Mar 5, 2020, 3:28:28 PM3/5/20
to TiddlyWiki
Hey, all —

Very guilty unicorn developer here.  The registrar for my personal site has been having technical issues which have kept me from renewing that domain.

I suggest using Joshua Fontany's fork for now:  https://github.com/joshuafontany/TiddlyWikiFormula
It's compatible with the latest TiddlyWiki and has a github.io demonstration wiki.

twid...@gmail.com

unread,
Jul 27, 2020, 10:40:30 AM7/27/20
to TiddlyWiki
Hi Evan,

I've just discovered Formulas and I'm enjoying its straightforward crunching. Thank you so much for making this awesome plugin! I'd like to make a tiddler that shows the overall "feeling score" of a food logging database by counting the number of results for each mood (bad, decent, good). Then, I'd find the average of their weighted values: (bad * -1 + decent * 1 + good * 2) / totalEntries.

I'm stuck on converting the number of results for the filter into a number.

 \define bad()
 (= value([tag[Food Log]tag[July]tag[bad]count[]]) =)
\end

(= <<bad>> * 2 =)

returns:

ComputeError: Cannot convert "2" to number!

Yet (= value("2") * 2 =) returns 4 as expected. I suspected that the mushrooms (?) may have been redundant when defining <<bad>>, but removing them lead to another error.

Thanks,

Emily

twid...@gmail.com

unread,
Jul 27, 2020, 10:51:36 AM7/27/20
to TiddlyWiki
I've reached a somewhat clunky solution, although I'm not sure why it works:

\define bad()
(= value([tag[Food Log]tag[July]tag[bad]count[]]) =)
\end

<$wikify name=badNum text=<<bad>>>
(= value(<<badNum>>) * 2 =)
</$wikify>


Emily

twid...@gmail.com

unread,
Jul 27, 2020, 10:52:55 AM7/27/20
to TiddlyWiki
And oh yeah the value() at the beginning is unnecessary.

Eric Shulman

unread,
Jul 27, 2020, 1:01:59 PM7/27/20
to tiddl...@googlegroups.com
On Monday, July 27, 2020 at 7:40:30 AM UTC-7, twid...@gmail.com wrote:
I've just discovered Formulas and I'm enjoying its straightforward crunching. Thank you so much for making this awesome plugin! I'd like to make a tiddler that shows the overall "feeling score" of a food logging database by counting the number of results for each mood (bad, decent, good). Then, I'd find the average of their weighted values: (bad * -1 + decent * 1 + good * 2) / totalEntries. 

While Evan's FormulaPlugin is very useful (and ground-breaking at the time), as of TiddlyWiki v5.1.20, the TWCore has math operators built-in as filters.

Here's how you might use these built-in operators instead of the FormulaPlugin...

For this example, I created a tiddler named "FoodLog" containing the following:
Choose a month:
<$select field="month">
   <$list filter="January February March April May June July August September October November December" variable="month">
      <option><<month>></option>
   </$list>
</$select>

<$vars
      bad={{{ [tag[FoodLog]tag{!!month}tag[bad]count[]multiply[-1]] }}}
   decent={{{ [tag[FoodLog]tag{!!month}tag[decent]count[]multiply[1]] }}}
     good={{{ [tag[FoodLog]tag{!!month}tag[good]count[]multiply[2]] }}}
  entries={{{ [tag[FoodLog]tag{!!month}count[]] }}}>

There are <<entries>> items in {{!!month}},
with an overall feeling score =
<$text text={{{ [<bad>add<decent>add<good>divide<entries>multiply[1000]trunc[]divide[1000]] }}}/>

Good:<br>
<$list filter="[tag[FoodLog]tag{!!month}tag[good]sort[]]"  ><li><<currentTiddler>></li></$list>
Decent:<br>
<$list filter="[tag[FoodLog]tag{!!month}tag[decent]sort[]]"><li><<currentTiddler>></li></$list>
Bad:<br>
<$list filter="[tag[FoodLog]tag{!!month}tag[bad]sort[]]"   ><li><<currentTiddler>></li></$list>

Then, I created some test tiddlers with appropriate tags:
"Hotdogs"      tags="FoodLog, July, good"
"Ice Cream"    tags="FoodLog, July, good"
"Jello"        tags="FoodLog, July, decent
"
Potato Salad" tags="FoodLog, July, bad"
"
Watermelon"   tags="FoodLog, July, good"

The output shown in FoodLog, is:
Choose a month: 
 
There are 5 items in July, with an overall feeling score = 1.2
 
Good:
  • Hotdogs
  • Ice Cream
  • Watermelon
Decent:
  • Jello
Bad:
  • Potato Salad

 
Notes:
* $select gives you a droplist of month names.  The selection is stored in FoodLog, in the "month" field.
* $vars calculates the "bad", "decent", "good", and "entries" values for the selected month, using the weighted value system you described in your post.
* The output shows the number of entries for the selected month, followed by the calculated "feeling score"
* The feeling score is "the average of their weighted values" as you described in your post, which I rounded to 3 decimal places.
* Following this result are bullet lists showing the individual food entries, sorted alphabetically, grouped by "good", "decent", and "bad"

enjoy,
-e

twid...@gmail.com

unread,
Jul 27, 2020, 2:03:55 PM7/27/20
to TiddlyWiki
Hi Eric,

Thank you!

Emily

Mark S.

unread,
Jul 28, 2020, 12:40:15 PM7/28/20
to TiddlyWiki
The TW filters are nowhere as complete or intuitive as Evan's work. Square root anyone?

I made a nutrition tracking app using Evan's tools:


It uses the nutrition database  from the USDA. I was able to track four major nutrients for my own health program. (calories, carbs, fiber, and potassium).

I'm not sure if even now it would be possible to do that with TW filters.
Reply all
Reply to author
Forward
0 new messages