I am attempting to get the day counts for incidents that occurred on that date. Really just need it to show how many collectively happened on Monday, Tuesday, etc.. It would also be nice to see if they happened after working hours. This is my code so far:
var fs = FeatureSetByPortalItem(
portal,
"b7a7144cda9046a5bfc6b36fa88e0477",
0,
['DateTime'],
false
);
var dayCounts = {
"0": 0,
"1": 0,
"2": 0,
"3": 0,
"4": 0,
"5": 0,
"6": 0
};
for (var f in fs) {
var dateVal = f['DateTime'];
if (!IsEmpty(dateVal)) {
var day = Weekday(dateVal) - 1;
if (HasKey(dayCounts, day)) {
dayCounts[day] += 1;
}
}
}
var outDict = {
fields: [
{ name: "Day", alias: "Day of Week", type: "esriFieldTypeInteger" },
{ name: "Count", alias: "Incident Count", type: "esriFieldTypeInteger" }
],
geometryType: "",
features: []
};
// Add the results as features
for (var k in dayCounts) {
Push(outDict.features, {
attributes: {
Day: Number(k),
Count: dayCounts[k]
}
});
};
return FeatureSet(Text(outDict));