数据集:
foo.Y
我想基于CreatedAt列对上述数据进行分组,并根据数据集中的 new_repeat 列过滤数据。我已经为此编写了一个函数,它使用_.chain并对数据进行分组,但我无法对其进行过滤。检查以下功能:
[
{
"created_by": "5750790484393984",
"patient_dateofbirth": "02/05/1990",
"patient_aadhaar": "1234567890",
"patient_area": "wert",
"patient_state": "Arunachal Pradesh",
"patient_gender": "Male",
"patient_pincode": "123456",
"location": "Guwahati",
"patient_name": "Rakesh",
"isVisited": 2,
"new_repeat": "Repeat",
"lastVisitDate": "2017-07-04",
"updatedAt": "2017-07-04T04:41:59.261Z",
"CreatedAt": "2017-07-03T18:48:25.773Z",
"patient_bloodgroup": "B+",
"patient_country": "India"
},
{
"created_by": "5750790484393984",
"patient_dateofbirth": "07/30/2006",
"patient_aadhaar": "2343524361731",
"patient_area": "begusarai",
"patient_state": "Bihar",
"patient_gender": "Male",
"patient_pincode": "110016",
"patient_name": "gyguy yuguy",
"registration_number": "2",
"ip_address": "43.225.248.20, 162.158.155.110",
"CreatedAt": "2017-06-28T09:41:47.188Z",
"patient_bloodgroup": "A+",
"patient_country": "India"
},
{
"ip_address": "103.83.148.161, 141.101.99.35",
"lastVisitDate": "2017-07-04",
"updatedAt": "2017-07-04T09:56:51.588Z",
"CreatedAt": "2017-07-02T23:37:29.512Z",
"patient_bloodgroup": "A+",
"patient_country": "India",
"created_by": "5750790484393984",
"patient_dateofbirth": "06/24/1964",
"patient_aadhaar": "",
"patient_area": "Chattarpur",
"patient_state": "Uttar Pradesh",
"patient_gender": "Female",
"patient_pincode": "201005",
"patient_name": "Sudha Ambastha",
"isVisited": 2,
"new_repeat": "Repeat"
},
{
"patient_area": "ajsdh",
"patient_state": "Delhi",
"patient_gender": "Male",
"patient_pincode": "110074",
"patient_name": "prashant",
"registration_number": "283423472834",
"isVisited": 1,
"new_repeat": "New",
"ip_address": "43.225.248.20, 162.158.155.110",
"lastVisitDate": "2017-07-04",
"updatedAt": "2017-07-03T18:41:55.777Z",
"CreatedAt": "2017-06-28T11:18:55.792Z",
"patient_bloodgroup": "B+",
"patient_country": "India",
"created_by": "5750790484393984",
"patient_dateofbirth": "06/13/1990",
"patient_aadhaar": "2131231238"
},
{
"created_by": "5750790484393984",
"patient_dateofbirth": "06/07/1990",
"patient_aadhaar": "1278292020029",
"patient_area": "Bhubneshwar",
"patient_state": "Orissa",
"patient_gender": "Male",
"patient_pincode": "112218",
"location": "Haldia",
"patient_name": "Rajesh Mishra",
"isVisited": 2,
"new_repeat": "Repeat",
"lastVisitDate": "2017-07-04",
"updatedAt": "2017-07-04T04:40:26.724Z",
"CreatedAt": "2017-07-03T04:21:35.647Z",
"patient_bloodgroup": "B-",
"patient_country": "India"
}
]
group_by是日期格式,可以是" DD-MM-YYYY"或者" MMM" 所以,上面是函数。如何过滤参数和值。
请建议更改:
const formatDataCount = (data, group_by) => {
return _.chain(data)
.sortBy('CreatedAt')
.groupBy(datum => moment(datum.CreatedAt).format(group_by) )
.map((value, key) => {
return {
label: key,
value: _.size(value)
}
})
.value();
};
第一个是工作,第二个是没有。
答案 0 :(得分:0)
过滤行 - .filter(filter_by => filter_by.new_repeat == "New")
应位于groupBy
之前。我还会将其移到sortBy
,因为您不需要对要删除的数据进行排序。
const formatDataCount = (data, group_by) => {
return _.chain(data)
.filter(filter_by => filter_by.new_repeat == "New")
.sortBy('CreatedAt')
.groupBy(datum => moment(datum.CreatedAt).format(group_by) )
.map((value, key) => {
return {
label: key,
value: _.size(value)
}
})
.value();
};