过滤JSON数据(D3.js)

时间:2018-10-21 11:31:26

标签: javascript arrays json d3.js filter

我真的需要您的帮助!我有一个看起来像这样的.JSON文件:

{ 
    "_id" : { "$yid" : "279e128r" },
    "userId" : "245981e3",
    "data" : {
        "workRate" : 51,
        "workStages" : [
            { "quantity" : 33, "value" : "APPLES" },
            { "quantity" : 32, "value" : "PEACH" },
            { "quantity" : 12, "value" : "AVOCADO" },
            { "quantity" : 53, "value" : "APPLES" },
            { "quantity" : 22, "value" : "PEACH" },
            { "quantity" : 27, "value" : "AVOCADO" }
        ],
    "timeInterval" : 25,
    "timeSource" : 1
    },
    "sessionStartTime" : 1494311320,
    "sessionEndTime" : 1494336640
}

大约有500位ID(“ _ id”),有30位参与者(“ userId”)。

因此,我想获取现有的JSON数据,并创建一个仅包含30个对象(每个参与者的每个对象)的新数组,然后找到“数据”字段并计算提及蔬菜的次数,然后合并它们,并具有被提及的次数。

{ 
    "userId" : "245981e3",
    "data" : {
        "workRate" : 51,
        "workStages" : [
            { "value" : "APPLES", "times": 2 },
            { "value" : "PEACH", "times": 2 },
            { "value" : "AVOCADO", "times": 2 }
       ]
    }
}
{ 
    "userId" : "7295ew41",
    "data" : {
        "workRate" : 45,
        "workStages" : [
            { "value" : "LEMON", "times": 13 },
            { "value" : "AVOCADO", "times": 42 },
            { "value" : "KIWI", "times": 14 }
       ]
    }
}

我知道这听起来很困难,但是我相信有人可以帮助我!

0 个答案:

没有答案