History: Calculations
Source of version: 51 (current)
Copy to clipboard
^ Project has been accepted and we'll invest significant time on this in coming weeks / months {sign user="marclaporte" datetime="2017-04-19T11:13:30+00:00"}. What is currently called ((doc:Advanced Rating)) syntax should be renamed to Tiki __Calculations__ which can be used all over Tiki, including advanced ratings and the ((doc:Mathematical Calculation Tracker Field))
^
This page is to brainstorm and plan to make Tiki better at calculations. It should be possible for any data in Tiki to be used for calculations and for the results to be used anywhere in Tiki, to do all kinds of useful things: alerts, reports, etc.
!! Overview
* ((doc:Trackers)) are used to collaborate on data input. This part is great. Many field types, flexible permissions, good reporting, etc.
* ((doc:PluginTrackerStat)) can be useful but is not configurable enough
* ((doc:Mathematical Calculation Tracker Field)) offers a lot of power and flexibility on various data fields of the same tracker item (like rows in a spreadsheet) and do things like ((Ease Importance Priority)) , with a diversity of syntax: ((doc:Advanced Rating|#Syntax|comment, Multiply, Divide, Sum, Substract, round, coalesce, str, concat, contains, map, equals, less-than, more-than, if, and, or, hash, avg, split-list, for-each, Not, IsEmpty, date, pad, rating-average and rating-sum, article-info, attribute, tracker-field, category-present)) but
** we need a way to do such advanced calculations across field items (like columns in a spreadsheet) and with filters and conditions. Something like a "compute" param added to PluginList, PluginListExecute and PluginCustomSearch? (It should be able to add any data to the calculation. Other fields in current tracker but also other data elsewhere in Tiki
** calculation across tracker items and across trackers
++ for ex. a tracker of payments and sum all payments, all payments of a specific period or a specific user or group
++ calculate certain values of one tracker with values of another tracker based on relations, for example similar to object-links, or dynamic-object-list ites. {sign user="Torsten" datetime="2017-08-04T23:24:45+00:00"}
* ((doc:Spreadsheet)) can do some calculations (but the integration in Tiki should be improved)
** Spreadsheets are too brittle for when data is collaborated on (It becomes important to lock cells) or constantly appended to (or formula needs to be carefully planned)
*** We want a database input form (and in some cases, data importing) and not humans adding more line to a spreadsheet
** Spreadsheet are not great at data versioning (and auditing)
* ((doc:PluginPivotTable)) is great to select part of the data, and to do some calculations
* ((doc:TableSorter)) is very nifty and can do some calculations: https://mottie.github.io/tablesorter/docs/example-widget-math.html
* ((doc:PluginFitnesse)) is very cool and should be extended to all future development. All projects with calculations should use such tests to make sure of data integrity as their formulae evolve.
!! Why is it important to calculate values server-side?
For Spreadsheet, PivotTable, TableSorter and WickedGrid, calculations are done client-side (by the user's browser) and thus, we can't use formulae the same way we use ((doc:Mathematical Calculation Tracker Field)) calculations. This would be needed for
* Unattended operations. Ex.: trigger actions via ((doc:PluginListExecute)) to send alerts (based on calculations) or reports (with results of calculations)
* For security reasons: imagine we are using these formulae to manage complex tax scenarios in the shopping cart. We don't want a clever user to [https://en.wikipedia.org/wiki/Greasemonkey|Greasemonkey] the Tiki ((doc:Shopping Cart)) into giving them a special price. Same thing for form validation.
** ''It could be checked against server side value if the special price is valid but I understand your concern'' {sign user="luci" datetime="2017-04-10T17:09:54+00:00"}
!! Questions
* Should we be looking into a way to do Server-side JavaScript?
** Either JS via PHP: ((Server-side JavaScript))
++''These are just ways of coding in js instead of coding in php. There is nothing here which is easier to do in js than in php except if you haven't learnt php'' {sign user="Jyhem" datetime="2017-04-11T23:40:23+00:00"}
** Or via ((PhantomJS)) which will now be easy to deploy via ((Composer Web Installer))
** ''Yes, why not? :)'' {sign user="luci" datetime="2017-04-10T17:12:17+00:00"}
++''Isn't PhantomJS the opposite of what we want to achieve? PhantomJS is for automated regression testing of web-based software (very nice). It is an emulation of what a user can do. If we double check what the user does while he is doing it using PhantomJS, I believe it will mess whith the user's session and actions, like doubling the orders, etc'' {sign user="Jyhem" datetime="2017-04-11T23:40:23+00:00"}
!! Ideas
* Should ((doc:Advanced Ratings)) be added to ((doc:PluginList))?
* Should we have a new concept of value which can be set? Perhaps PluginValue which can be set, updated, emptied, used, etc.
** Like taking ((doc:Dynamic Variables)) to the next level
** Like ((doc:PluginAttributes))
* Could be useful for ((doc:Stats)) (e.g. how many times page was edited, most "time consuming" page, calculate man-hours, etc.) and Action Reports? {sign user="luci" datetime="2017-04-10T17:09:54+00:00"}
!! Opinions
* I like spreadsheets because it's easy to visualize the calculations. I'd like diverse values all over Tiki to be in the spreadsheet, and from here, to use the spreadsheet formulae and then, for these resulting values to make their way into wiki pages, reports, alerts, etc. and in some cases into other spreadsheets :-) {sign user="marclaporte" datetime="2017-04-10T00:22:34+00:00"}
* I prefer trackers over spreadsheets, cause trackers collect data dynamically. There is an option to import data from trackers to spreadsheets in Tiki, Although this seems to be a one-off import (not dynamically updated). Further more the input to trackers is made by pre-defined forms, which cannot be altered by most users (user groups) and work even for Anonymous in some Use Cases, where spreadsheets are difficult to maintain, specifically to lock partially. Where in spreadsheets users can alter data from other users and mix up fields, this can easily prevented with Trackers.
+ Imho the biggest disadvantage of trackers is the current lack of cross-item and cross-tracker calculation, which same time seems to be the biggest advantage of spreadsheets - calculation across culomns and sheets. {sign user="Torsten" datetime="2017-08-05T01:25:07+00:00"}
!! Use Cases
__See ((Calculations Use Cases))__
!! Code and libraries
* https://github.com/markrogoyski/math-php/
* https://hoa-project.net/En/Literature/Hack/Math.html
* https://packagist.org/packages/clue/graph
* https://packagist.org/packages/brick/math
* https://packagist.org/packages/lstrojny/hmmmath
* https://packagist.org/packages/zendframework/zend-math
* https://github.com/NumPHP/NumPHP/
!! Related links
* ((Visual Programming)) from these calculations, we can want certain actions
* ((Mail Merge)): because the text could vary depending on the result of a calculation
* {wish id=6108}
* {wish id=3870}
* {wish id=1535} -> Could be a task based on a condition
* [https://www.w3schools.com/php/php_ref_math.asp|PHP 5 Math Functions] (W3Schools)
* http://php.net/manual/en/ref.math.php
* [http://stackoverflow.com/questions/7216497/php-simple-math-calculation|Be careful about floating point number precision]
* ((Merge Tiki Spreadsheet into Tiki Trackers))
-=alias=-
(alias(Calculation))