|
POST
|
You can use this code in each of your indicators // Define the feature set
var Dates = FeatureSetByPortalItem(
Portal('https://regionofpeel.maps.arcgis.com'),
'5d0f25a7a3314686b526bab55653befb',
0
);
// Function to check if a string represents a valid date
function IsDate(dateString) {
// Check if the date string is not null, undefined, or an empty string
if (dateString == null || dateString == "") {
return false;
}
// Attempt to create a Date object from the string using DateTime function
var dateObject = Date(dateString);
// Check if the created Date object is a valid date
return !IsEmpty(dateObject);
}
var i = 0;
var totalWaitingTime = 0;
var maxWaitingTime = -Infinity;
var minWaitingTime = Infinity;
var features = [];
// Loop through records in the feature set
for (var record in Dates) {
var wellAbandonmentDate = record['Date_abandonment'];
var dateReceived = record['date_recieved'];
// Check if both dates are valid
if (IsDate(wellAbandonmentDate) && IsDate(dateReceived)) {
// Calculate waiting time in days using the DateDiff function
var waitingTime = DateDiff(dateReceived, wellAbandonmentDate, 'days');
// Update total, max, and min waiting times
totalWaitingTime += waitingTime;
maxWaitingTime = Max(maxWaitingTime, waitingTime);
minWaitingTime = Min(minWaitingTime, waitingTime);
// Add feature to Dict
var feat = {
'attributes': {
'WellAbandonmentDate': wellAbandonmentDate,
'DateReceived': dateReceived,
'WaitingTime': waitingTime
}
);
Push(features, feat)
i++;
}
}
// Calculate average waiting time
var averageWaitingTime;
if (i > 0) {
averageWaitingTime = totalWaitingTime / i;
} else {
averageWaitingTime = null;
}
// Loop through features
for (var j in features) {
var featureData = features[j];
// Add calculated values to the features
featureData.attributes.AverageWaitingTime = averageWaitingTime;
featureData.attributes.MaxWaitingTime = maxWaitingTime;
featureData.attributes.MinWaitingTime = minWaitingTime;
}
var Dict = {
'fields': [
{'name': 'AverageWaitingTime', 'type': 'esriFieldTypeDouble'},
{'name': 'MaxWaitingTime', 'type': 'esriFieldTypeDouble'},
{'name': 'MinWaitingTime', 'type': 'esriFieldTypeDouble'}
],
'geometryType': '',
'features': [{
'attributes': {
'AverageWaitingTime': averageWaitingTime,
'MaxWaitingTime': maxWaitingTime,
'MinWaitingTime': minWaitingTime
}
}]
};
return FeatureSet((Dict))
... View more
11-24-2023
01:08 PM
|
0
|
2
|
3541
|
|
POST
|
You're using Push incorrectly in several places. I've restructured your code a little bit and it returns the Dict. // Define the feature set
var Dates = FeatureSetByPortalItem(
Portal('https://regionofpeel.maps.arcgis.com'),
'5d0f25a7a3314686b526bab55653befb',
0
);
// Function to check if a string represents a valid date
function IsDate(dateString) {
// Check if the date string is not null, undefined, or an empty string
if (dateString == null || dateString == "") {
return false;
}
// Attempt to create a Date object from the string using DateTime function
var dateObject = Date(dateString);
// Check if the created Date object is a valid date
return !IsEmpty(dateObject);
}
var i = 0;
var totalWaitingTime = 0;
var maxWaitingTime = -Infinity;
var minWaitingTime = Infinity;
var features = [];
// Loop through records in the feature set
for (var record in Dates) {
var wellAbandonmentDate = record['Date_abandonment'];
var dateReceived = record['date_recieved'];
// Check if both dates are valid
if (IsDate(wellAbandonmentDate) && IsDate(dateReceived)) {
// Calculate waiting time in days using the DateDiff function
var waitingTime = DateDiff(dateReceived, wellAbandonmentDate, 'days');
// Update total, max, and min waiting times
totalWaitingTime += waitingTime;
maxWaitingTime = Max(maxWaitingTime, waitingTime);
minWaitingTime = Min(minWaitingTime, waitingTime);
// Add feature to Dict
var feat = {
'attributes': {
'WellAbandonmentDate': wellAbandonmentDate,
'DateReceived': dateReceived,
'WaitingTime': waitingTime
}
);
Push(features, feat)
i++;
}
}
// Calculate average waiting time
var averageWaitingTime;
if (i > 0) {
averageWaitingTime = totalWaitingTime / i;
} else {
averageWaitingTime = null;
}
var Dict = {
'fields': [
{'name': 'WellAbandonmentDate', 'type': 'esriFieldTypeDate'},
{'name': 'DateReceived', 'type': 'esriFieldTypeDate'},
{'name': 'WaitingTime', 'type': 'esriFieldTypeDouble'}, // New field for waiting time
{'name': 'AverageWaitingTime', 'type': 'esriFieldTypeDouble'},
{'name': 'MaxWaitingTime', 'type': 'esriFieldTypeDouble'},
{'name': 'MinWaitingTime', 'type': 'esriFieldTypeDouble'}
],
'geometryType': '',
'features': features
};
// Loop through features
for (var j in Dict.features) {
var featureData = Dict.features[j];
// Add calculated values to the features
featureData.attributes.AverageWaitingTime = averageWaitingTime;
featureData.attributes.MaxWaitingTime = maxWaitingTime;
featureData.attributes.MinWaitingTime = minWaitingTime;
}
return Dict; However, is your intent to just have one record for the maximum, minimum, and average waiting times for your indicator? All of the records in your dataset will have the same values for these three times.
... View more
11-24-2023
12:22 PM
|
0
|
4
|
3547
|
|
POST
|
When you replace "Time" with "Text" in this line, your script works chartValues[Text(f.time_stamp, 'H:mm dddd MMMM D, Y')] = Number(f.pm25calibrated,'000')
... View more
11-24-2023
05:56 AM
|
0
|
0
|
1385
|
|
POST
|
And you should click the Accept as Solution button in your response to help others if they have this problem.
... View more
11-22-2023
11:25 AM
|
1
|
0
|
2771
|
|
POST
|
It looks like "-8" is getting added to the beginning of the latitude of each point. When I examine one of the points in the response, its latitude attribute is "46.53949113" while the geometry latitude is "-846.5394911299999". I can't figure out where that is happening, since looking at the same point from the rest service shows the correct values. rest.png response.png And you're getting lots of dojo errors when you used v4.28 since dojo has been been almost fully removed from the SKD
... View more
11-22-2023
09:31 AM
|
0
|
4
|
2780
|
|
POST
|
That SQL statement is picky! Try this instead (changing the quotes) var onlyRemoved = Filter(sortedTable,"Maintenance_Performed = 'Removal'");
... View more
11-22-2023
08:59 AM
|
0
|
1
|
4939
|
|
POST
|
var onlyRemoved = Filter(sortedTable,'Maintenance_Performed = 1'); //or whatever the domain code is for Removal You should use the numeric domain code, since the SQL function won't understand how to work with them.
... View more
11-22-2023
08:03 AM
|
0
|
2
|
4949
|
|
POST
|
It looks like you're having a spatial reference problem when making graphics from the query results. If you zoom out far enough, you'll see the records, but they're in a straight line. If you click the home button, the map shows up again. map.png Examining one of the points in the query results shows its latitude and longitude are kind of screwy. point.png
... View more
11-22-2023
08:00 AM
|
0
|
6
|
2799
|
|
POST
|
Is it possible that the Maintenance_Performed field uses a domain?
... View more
11-22-2023
07:36 AM
|
0
|
4
|
4953
|
|
POST
|
You need to put quotes around Removal in your filter var onlyRemoved = Filter(sortedTable,'Maintenance_Performed = "Removal"');
... View more
11-22-2023
07:08 AM
|
0
|
6
|
4966
|
|
POST
|
Have you seen the new Time Only field now available?
... View more
11-22-2023
06:13 AM
|
2
|
1
|
936
|
|
POST
|
Yes, if a service is added to the web map that contains groups, they will be maintained in Web AppBuilder.
... View more
11-22-2023
06:06 AM
|
0
|
0
|
1221
|
|
POST
|
Which web app are you using? Some of them are built with ArcGIS Maps SDK for JavaScript v3.x (like Web AppBuilder), which doesn't support group layers. Experience Builder uses v4.x, which does support group layers.
... View more
11-22-2023
04:46 AM
|
0
|
2
|
1229
|
| Title | Kudos | Posted |
|---|---|---|
| 3 | 2 weeks ago | |
| 1 | 02-04-2025 06:39 AM | |
| 1 | 05-01-2026 08:26 AM | |
| 1 | 04-10-2026 12:01 PM | |
| 1 | 04-13-2026 09:11 AM |
| Online Status |
Offline
|
| Date Last Visited |
a week ago
|