On Friday, July 18, 2014 12:27:59 AM UTC-7, julien23 wrote:
>
> I am trying to get the average value of a field for the 5 last created
> tiddlers with FET.
> [[ConfusedVectorError]]
>
>> |DPMO|<<tiddler FetAverage5Text with:cvErr>>|
>>
>
For this kind of calculation, you may be better off using
http://www.TiddlyTools.com/#InlineJavascriptPlugin
Like this:
<script>
var count=0, total=0;
// get ALL tiddlers, sorted by creation date (newest first)
var tids=store.sortTiddlers(store.getTiddlers(),"-created");
// for each tiddler...
for (var i=0; i<tids.length; i++) {
// get the desired slice value as a number, default to 0 if no slice is
defined
var val=1*store.getTiddlerText(tiddler.title+"::$1","0");
// if value is non-zero, add it to the total, and increment the count
if (val>0) { total+=val; count++; }
// if we have found five values, that's enough
if (count==5) break;
}
// calculate and return the average value
// which is then rendered by InlineJavascriptPlugin
return total/count;
</script>
Note: if there are < 5 tiddlers with a non-zero field value, the average
will be correctly calculated based on the actual number of tiddlers found.
That should do it... let me know how it goes.
enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios
YOUR DONATIONS ARE VERY IMPORTANT!
HELP ME TO HELP YOU - MAKE A CONTRIBUTION TO MY "TIP JAR"...
http://TiddlyTools.github.com/fundraising.html#MakeADonation
Professional TiddlyWiki Consulting Services...
Analysis, Design, and Custom Solutions:
http://www.TiddlyTools.com/#Contact
--
You received this message because you are subscribed to the Google Groups
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/tiddlywiki.
For more options, visit https://groups.google.com/d/optout.