Answer the question
In order to leave comments, you need to log in
How to make reports on the following JSON?
Hello!
Finally came to the sweetest part of my project - the reports.
Friends plz tell me how to get reports based on the following data?
{
"_id" : ObjectId("56e6b657753c6d890f614820"),
"user" : ObjectId("56d9793edf03960106872e76"),
"comment" : null,
"status" : ObjectId("56bd55d111b7ed891118a65b"),
"client" : null,
"created" : ISODate("2016-03-14T13:02:15.030Z"),
"ticket" : 0,
"km" : 0,
"sum" : 20,
"service" : {
"drunkDriver" : false,
"person" : false,
"nanny" : false,
"courier" : false
},
"isCash" : false,
"preorder" : false,
"direction" : {
"from" : ObjectId("56dccdd9c82df9d8048e0f6c"),
"to" : ObjectId("56dccd94c82df9d8048e0f6a")
},
"moment" : {
"closed" : ISODate("2016-03-14T13:15:00Z"),
"end" : ISODate("2016-03-14T13:45:00Z"),
"met" : ISODate("2016-03-14T13:00:00Z"),
"inplace" : ISODate("2016-03-14T13:14:00Z"),
"notification" : ISODate("2016-03-14T12:50:00Z"),
"start" : null
},
"driver" : ObjectId("56e6a3feb770b5bc0b9e7593"),
"passengers" : null,
"__v" : 6
}
Answer the question
In order to leave comments, you need to log in
if we assume that the data value contains a list of your data
var data = [{
"_id" : ObjectId("56e6b657753c6d890f614820"),
"user" : ObjectId("56d9793edf03960106872e76"),
"status" : ObjectId("56bd55d111b7ed891118"),
"created " : ISODate("2016-03-14T13:02:15.030Z"),
"sum" : 20}, ........ ];
then you can use the reduce function
data.reduce(function (result, o) {
var key = o.user;
var counter = 1;
if (!(key in result)) {
result.arr.push(result[key] = {
user: o.user,
couter: counter,
total: o.sum
});
} else {
result[key].total += o.sum;
counter++;
}
return result;
}, { arr: [] }).arr;
Hey! Maybe I didn’t quite understand the idea, but since mapReduce examples have already been written, maybe you should look towards creating reports based on the Apache Solr search engine? As a result, you will get the flexibility of rebuilding reports for new requirements + near-realtime + scalability. The idea there is this: You load data into Solr and use search and analytical queries (facet & stats components) to do the necessary aggregations. Here is a video with an example of building analytical reports https://www.youtube.com/watch?v=JtbEDef_p9U You can build reports directly in Banana or Kibana, on which dashboards are made to visualize reports, see https://www.youtube .com/watch?v=cqV5lPM2VVE and https://www.youtube.com/watch?v=ddgtvv4W8EM. I would choose Banana as the dasboard builder as it is much more flexible and more responsive to Apache Solr. I also implemented analytics using Solr with the HBase layer. The bottom line is that if you need to change data that has already arrived, then it’s better to use key-value storage for updates, and then I have a livy-hbase indexer configured that updates the data in Solr in portions. Here is a link with more details: bigdata-intips.blogspot.com/2016/06/real-time-apac...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question