因此,数据集如下所示:screenshot of the data structure
{
"YearWeekISO": "2020-W53",
"FirstDose": 0,
"FirstDoseRefused": "",
"SecondDose": 0,
"DoseAdditional1": 0,
"DoseAdditional2": 0,
"UnknownDose": 0,
"NumberDosesReceived": 0,
"NumberDosesExported": 0,
"Region": "AT",
"Population": "8901064",
"ReportingCountry": "AT",
"TargetGroup": "ALL",
"Vaccine": "JANSS",
"Denominator": 7388778
}, {
"YearWeekISO": "2020-W53",
"FirstDose": 0,
"FirstDoseRefused": "",
"SecondDose": 0,
"DoseAdditional1": 0,
"DoseAdditional2": 0,
"UnknownDose": 8,
"NumberDosesReceived": 0,
"NumberDosesExported": 0,
"Region": "AT",
"Population": "8901064",
"ReportingCountry": "AT",
"TargetGroup": "ALL",
"Vaccine": "UNK",
"Denominator": 7388778
},
link to the data set
查询参数如下所示:
GET /疫苗-总结?c=AT&日期自=2020-W10 &日期至=2020-W53 &范围=5
其中
c,要获取报告国家/地区代码
起始日期,年-周,例如2020-W10(包括)
截止日期,yyyy-Www,例如,2020-W20(不包括)
rangeSize、数字,例如,计算指标的期间
应用聚合后,您应该得到如下所示的转换数据集:
{
"summary": [{
"weekStart": "2020-W10",
"weekEnd": "2020-W15",
"NumberDosesReceived": 1000
},
{
"weekStart": "2020-W15",
"weekEnd": "2020-W20"
"NumberDosesReceived": 2000
}, …
till end of range(dateTo)
]
}
}
请注意weekStart是如何从2020-W10递增到2020-W15的,与weekEnd类似。
NumberDosesReceived是在该范围内的NumberDosesReceived字段ID的总和
2条答案
按热度按时间qaxu7uf21#
So was able to come up with a working solution using a mongo aggregate method called bucket, but one of the problem is that if you want an aggregation of like week 1 - week 20 in chunks of 5, i.e, 1-5 (1 included, 5 excluded), 5- 10,10-15 and 15-20, you will have to give it an array like; boundaries: [1,5,10,15,20] as part of the argument and from the question, i have to create a JS function to return an array of numbers between start week and end week with the range given also. Written in typescript, the return array from this question would look like : [2020-W01,2020-W05,2020-W10,2020-W15,2020-W20], Also there are certain edge cases you have to account for since all the parameters are dynamic, like if the week spans more than one year, also, the fact that mongo to the best of my knowledge don't have date format like "2020-W10" makes it a bit more complex
After this i opened my mongo compass on local to construct and chain aggregate methods and function to satisfy the task given:
In that aggregation:
here is the link to the repo: link
jucafojl2#
应该可以的
常数年周ISO = { $截止日期:“$年周ISO”};