Hi,
I have a Data Expression that I am using in my Dashboard to help me create a graph that shows average use by day of week for three separate locations. I am unsure if this is actually providing me with the correct values, and was hoping someone can look this over to see if what I am doing makes sense / is actually right.
Any help refining this would also be really helpful, as I'm sure this is not elegant.
var portal = Portal("https://www.arcgis.com");
// Group the features by the BLA
var BLA = Filter(FeatureSetByPortalItem(portal,"xyz",0,['BLA_Used', 'Survey_Date', 'Name'],false), "NOT Name = 'Rental%'");
var groupBLA = GroupBy(BLA,
["Survey_Date"],
[
{ name: "BoatLaunchArea", expression: "BLA_Used", statistic: "MIN" },
{ name: "cntBoats", expression: "BLA_Used", statistic: "COUNT" },
{ name: "date", expression: "Survey_Date", statistic: "MIN" },
]
);
var combinedDict1 = {
fields: [
{ name: "sdate", type: "esriFieldTypeDate" },
{ name: "dow", type: "esriFieldTypeInteger" },
{ name: "BLA", type: "esriFieldTypeString" },
{ name: "cntSurveyScans", type: "esriFieldTypeInteger" },
],
geometryType: "",
features: [],
};
var i = 0;
for (var m in groupBLA) {
combinedDict1.features[i] = {
attributes: {
BLA: m["BoatLaunchArea"],
cntSurveyScans: (Floor(m["cntBoats"] / 2)),
sdate: DateDiff(m["Survey_Date"], Date(1970, 0, 1), "MM/DD/yyyy"),
dow: Weekday(m["Survey_Date"]),
},
};
i++;
}
var dict1 = FeatureSet(Text(combinedDict1));
var groupDOW = GroupBy(dict1,
[
{ name: "dow", expression: "dow" },
{ name: "BLA", expression: "BLA" }
],
[
// { name: "BLAName", expression: "BLA", statistic: "MIN" },
// { name: "surveydate", expression: "sdate", statistic: "MIN" },
{ name: "countBoats", expression: "BLA", statistic: "COUNT" },
]
);
var combinedDict2 = {
fields: [
{ name: "BoatArea", type: "esriFieldTypeString" },
{ name: "wday", type: "esriFieldTypeInteger" },
{ name: "avgBoats", type: "esriFieldTypeInteger" },
],
geometryType: "",
features: [],
};
var x = 0;
for (var n in groupDOW) {
combinedDict2.features[x] = {
attributes: {
BoatArea: n["BLA"],
wday: n["dow"],
avgBoats: (Floor(Average(n["countBoats"] / 2))),
},
};
x++;
}
return FeatureSet(Text(combinedDict2));
One additional note...towards the bottom for 'avgBoats', I have divided by 2 in addition to using 'Average' because each boat is scanned twice - once when launching and once when coming off water. I wanted to divide by 2 so each boat is only counted once, and then Average what was left.

Here is a sample of the output:

Any help would be appreciated!