salvadr / json-aggregate Goto Github PK
View Code? Open in Web Editor NEWjson-aggregate is a javascript utility to perform aggregations on JSON-formatted data.
License: MIT License
json-aggregate is a javascript utility to perform aggregations on JSON-formatted data.
License: MIT License
For eg., lets say three keys in the object a,b,c where c = a/b. After grouping the array of objects, final c value must by aggregated value of a / aggregated value of b. Is it possible? Btw, nice work.
Only 9 stars here?
Is there any support for $project operator?
@salvadr BTW, I've forked this project since I'm finding more issues and I need to fix them to use it my project. I wouldn't mind contributing to this project if you want to invite me as a contributor.
Feature request:
[{ company: "a", employeeCount: 45, category: 1, product: "Product A", price: 120 },
{ company: "a", employeeCount: 45, category: 1, product: "Product B", price: 80 },
{ company: "a", employeeCount: 45, category: 2, product: "Product C", price: 105 },
{ company: "a", employeeCount: 45, category: 2, product: "Product D", price: 95 },
{ company: "b", employeeCount: 30, category: 1, product: "Product A", price: 40 },
{ company: "b", employeeCount: 30, category: 1, product: "Product B", price: 100 },
{ company: "b", employeeCount: 30, category: 2, product: "Product C", price: 60 },
{ company: "b", employeeCount: 30, category: 2, product: "Product D", price: 130 }]
collection.group({
id: (c) => c.company.toUpperCase(),
lowestPrice: { $min: (c) => c.price * 2}
})
.exec()
output
[{ id: 'A', lowestPrice: 160 },
{ id: 'B', lowestPrice: 80 }]
Thanks for you project!
I was wondering if you had any idea on how to make it possible to use the "group" method with Numbers? I've attached an example here so the goal would be to perform SUM based on the "actor_id" attribute. Here, the result would be 3.
groupBysum() {
const jsonAggregate = require('json-aggregate')
const arr = [
{
"actor_id": 1,
"film_id": 1,
"last_update": "2006-02-15 05:05:03"
}, {
"actor_id": 1,
"film_id": 23,
"last_update": "2006-02-15 05:05:03"
}, {
"actor_id": 1,
"film_id": 25,
"last_update": "2006-02-15 05:05:03"
} ]
const collection = jsonAggregate.create(JSON.stringify(arr))
collection.group({ id: 'actor_id', count: { $sum: 1 }})
console.log('Result=',collection);
}
This gives the following error: TypeError: Cannot read property 'data' of undefined. It works fine with "last_update" instead of "actor_id".
json-aggregate/lib/operators.js
Line 41 in 972891c
i have below object...
var myJsonData=
[
{ company: "e", employeeCount: 45,
scoreRange:[
{value:110,exception:[{ifCounter:10,shouldCounter:3},{ifCounter:10,shouldCounter:3}]},
{value:50,exception:[{ifCounter:10,shouldCounter:1},{ifCounter:10,shouldCounter:4}]},
{value:10,exception:[{ifCounter:10,shouldCounter:1},{ifCounter:10,shouldCounter:7}]},
{value:10,exception:[{ifCounter:10,shouldCounter:3},{ifCounter:10,shouldCounter:8}]},
] },
{ company: "a", employeeCount: 45, scoreRange:[
{value:110,exception:[{ifCounter:10,shouldCounter:3},{ifCounter:10,shouldCounter:2}]},
{value:50,exception:[{ifCounter:10,shouldCounter:1},{ifCounter:10,shouldCounter:1}]},
{value:10,exception:[{ifCounter:10,shouldCounter:1},{ifCounter:10,shouldCounter:1}]},
{value:10,exception:[{ifCounter:10,shouldCounter:3},{ifCounter:10,shouldCounter:2}]},
] },
{ company: "b", employeeCount: 45, scoreRange:[
{value:110,exception:[{ifCounter:10,shouldCounter:3},{ifCounter:10,shouldCounter:2}]},
{value:50,exception:[{ifCounter:10,shouldCounter:1},{ifCounter:10,shouldCounter:1}]},
{value:10,exception:[{ifCounter:10,shouldCounter:1},{ifCounter:10,shouldCounter:1}]},
{value:10,exception:[{ifCounter:10,shouldCounter:3},{ifCounter:10,shouldCounter:2}]},
] },
{ company: "c", employeeCount: 45, scoreRange:[
{value:110,exception:[{ifCounter:10,shouldCounter:3},{ifCounter:10,shouldCounter:2}]},
{value:50,exception:[{ifCounter:10,shouldCounter:1},{ifCounter:10,shouldCounter:1}]},
{value:10,exception:[{ifCounter:10,shouldCounter:1},{ifCounter:10,shouldCounter:1}]},
{value:10,exception:[{ifCounter:10,shouldCounter:3},{ifCounter:10,shouldCounter:2}]},
] },
];
i want to unwind by exception array...
collection
.unwind("scoreRange")
.unwind("scoreRange.exception")
.exec();
but it doesnt work
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.