doushi1957 2013-12-12 02:26
浏览 80
已采纳

用于Web应用程序的小型电子表格式语言解释器

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,

  • 写回答

1条回答 默认 最新

  • duanshan188866 2014-04-07 11:54
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型