I'm working on a dashboard that records spawning data of salmon. As part of the dashboard I need to be able to call in survey records from a table, determine if the survey year is even or odd and then apply a transformation specific to a species and differs by odd and even years.
The following code seemingly functions as expected in that it applies the appropriate transformation.
However, not all records are being returned by the data expression. I can't figure out why some records aren't being returned and its consistently the same records which are excluded (several dozen of the 1900+ records in the original table). Any insights into why this is happening or how to optimize the code would be greatly appreciated.
var p = Portal('https://www.arcgis.com/');
var fs = FeatureSetByPortalItem(
p,
'XYZ',
0,
['StreamID_fk',
'DateSurveyed',
'Species',
'TotalRedds'
],
false
);
var features = [];
var feat;
for (var r in fs) {
var d = r['DateSurveyed']
var sd = Number(d)
var oey = Number(Year(d))
var stream = r['StreamID_fk']
var fishType = r['Species']
var reddNum = r['TotalRedds']
function isOdd(value) {
if (Boolean(value % 2)) {
if (fishType == 'Steelhead') {
return reddNum * 1.62
} else {
return reddNum * 1
}
} else {
if (fishType == 'Chinook') {
return reddNum * 2.5
} else if (fishType == 'Steelhead'){
return reddNum * 1.62
} else {
return reddNum * 1
}
}
}
var esc = isOdd(oey)
feat = {
attributes: {
'StreamID': stream,
'SurveyDate': sd,
'FishSpecies': fishType,
'ReddNums': reddnum,
'EscValue': esc,
}
}
Push(features, feat)
}
var Dict = {
'fields':[
{'name': 'StreamID', 'type': 'esriFieldTypeString'},
{'name': 'SurveyDate', 'type': 'esriFieldTypeDate'},
{'name': 'FishSpecies', 'type': 'esriFieldTypeString'},
{'name': 'ReddNums', 'type': 'esriFieldTypeInteger'},
{'name': 'EscValue', 'type': 'esriFieldTypeInteger'},],
'geometryType': '',
'features': features,
};
return FeatureSet(Text(Dict));