Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let 'javascript' handle aggregation! #87

Closed
jf-tech opened this issue Oct 10, 2020 · 0 comments · Fixed by #92
Closed

Let 'javascript' handle aggregation! #87

jf-tech opened this issue Oct 10, 2020 · 0 comments · Fixed by #92

Comments

@jf-tech
Copy link
Owner

jf-tech commented Oct 10, 2020

The current way of doing sum/avg feels awkward and clumsy. Since we have 'javascript' custom_func, let it handle aggregation. The idea is to have its argument decl support array:

from:

                "total_price": { "custom_func": {
                    "name": "javascript",
                    "args": [
                        { "const": "num * price" },
                        { "const": "num:int" }, { "xpath": "number_purchased" },
                        { "const": "price:float" }, { "xpath": "item_price" }
                    ]
                }}

to:

                "total_price": { "custom_func": {
                    "name": "javascript",
                    "args": [
                        { "const": "var total=0; for (i=0; i<Math.min(num.length,price.length); i++) { total+=num[i]*price[i]; } total; " },
                        { "const": "num:int:array" }, { "xpath": "number_purchased" },
                        { "const": "price:float:array" }, { "xpath": "item_price" }
                    ]
                }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant