I have a collection of Objects with various fields. Here is an example:
[
{"date": "01/01/2020", "location": "Main St", "customers": 100, "shoppers": 150, "visitors": 2000},
{"date": "01/01/2020", "location": "Lower St", "customers": 105, "shoppers": 166, "visitors": 2000},
{"date": "01/01/2020", "location": "High St", "customers": 180, "shoppers": 260, "visitors": 2000},
{"date": "02/01/2020", "location": "Main St", "customers": 156, "shoppers": 194, "visitors": 1566},
{"date": "02/01/2020", "location": "Lower St", "customers": 80, "shoppers": 201, "visitors": 1566},
{"date": "02/01/2020", "location": "High St", "customers": 97, "shoppers": 133, "visitors": 1566},
{"date": "03/01/2020", "location": "Main St", "customers": 48, "shoppers": 97, "visitors": 1002},
{"date": "03/01/2020", "location": "Lower St", "customers": 211, "shoppers": 287, "visitors": 1002},
{"date": "03/01/2020", "location": "High St", "customers": 113, "shoppers": 233, "visitors": 1002}
]
The visitor count remains constant each day since it represents the total visitors for that day.
I am calculating the sum of customers and shoppers like this:
this.customerCount = this.data.filter(item => item.date >= this.startDate && item.date <= this.endDate)
.reduce((sum, current) => sum + current.customers, 0);
this.shopperCount = this.data.filter(item => item.date >= this.startDate && item.date <= this.endDate)
.reduce((sum, current) => sum + current.shoppers, 0);
This calculation works as intended, with shopperCount representing the total sum of all shopper counts within the chosen date range.
Could someone provide guidance on how to calculate the total number of unique visitors between two specific dates while only counting each visitor once per day? Using the dataset above, the visitorCount would be:
2000 + 1566 + 1002 = 4568