Question

I am building a web app which will allow users to create small "spreadsheets" with their data. This is a time keeping application and I am building the reporting tool.

I am looking for a way to for different groups to have different reports without having to hard code in the algorithms. I would like to store these algorithms in a MySQL database and pull it out on a per person basis.

The application allows users to track time and assign it to activities.

The report builder will allow users to select what activities to report on and have the ability to create small equations out the totals.

for instance: One group uses an overtime-given and overtime-paid. The overtime-given needs to be multiplied by 1.5 and then I subtract the overtime-paid from this to give a total.

This is an example output:

|Month|overtime remaining| overtime-paid | overtime-given|
|-----|------------------|---------------|---------------|
| Jan |       7          |      2        |      6        |
| Feb |       9          |      0        |      6        |
| Mar |       0          |      7        |      0        |
| Apr |       7          |      2        |      6        |
| ... |       ...        |     ...       |      ...      |
|THour|       50         |      55       |      70       |//total in hours
|TDay |       7.14       |      7.85     |      10       |//total in days

I am not sure if the best way is to build a small interpreter and create my own tiny language to describe it, or if there is something out there already like this.

I would like to know how other people are creating per user customized reporting tools that the user themselves can alter. Altering I can build I simply UI for users to alter they would not have to code anything.

If someone could point me in the proper direction is greatly appreciated.

Thanks,

Was it helpful?

Solution

The general solution to this problem is to use a runtime expression evaluator in the form of scripts. Similar problems appear in handling complex and varying calculations like costing, quoting and payroll.

To take a simple example, the script code might read:

$total = $overtime-given * 1.5 - $overtime-paid

The questions are:

  1. What language to use for the expressions.
  2. How to give the language access to the variables it needs (and nothing else)

The main choices are:

  1. Write your expression evaluator/language. Hard! (but my favorite)
  2. Use the hosting language, if suitable. I believe PHP can be used in this role, but I defer to others as to how well that would work.
  3. Embed a dynamically compiled/interpreted language designed for the purpose. I would suggest Lua, but it depends on whether it can be embedded on your platform.

This is not a complete answer, but rather a direction to pursue. I have done this in Ruby (embedded my own expression evaluator), but hesitate to suggest it unless you really like compiler technology.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top