Select to view content in your preferred language

Compare multiple features fields to create string | Popup/Arcade

54
1
Jump to solution
Tuesday
Labels (1)
SpatialSean
New Contributor III

I am trying to create a string to provide a reduced look at tropical storm systems.  I've gotten close but am struggling with looping and comparing the items since they are in different fields from different features.  Since storms change in classification throughout the timeline I want to reduce to only show those changes.  This would be my final block of text (or similar): 

  • Tropical Rainstorm: June 18, 2024 at 11:00 AM → Tropical Storm: June 19, 2024 at 11:00 PM → Tropical Depression: June 20, 2024 at 8:00 AM → Tropical Rainstorm: June 20, 2024 at 8:00 PM

Storm begins as a tropical rainstorm on the 18th, changes to a tropical storm on the 19th at 11pm, then a tropical depression on the 20th at 8am, and so on.  It would be simple to grab Distinct values but I need to compare the Begin and End classifications then add the times.

_DATE_TIME is a date/time field, _LABEL is string

STORM_ID is the unique ID

BEGIN_CLASSIFICATIONBEGIN_DATE_TIMEBEGIN_DATE_TIME_LABELEND_CLASSIFICATIONEND_DATE_TIMEEND_DATE_TIME_LABELSTORM_ID
Tropical RainstormJune 18, 2024 at 11:00 AMJun 18 2024 10:00AM CDTTropical RainstormJune 18, 2024 at 8:00 PMJun 18 2024 7:00PM CDT2,511
Tropical RainstormJune 18, 2024 at 8:00 PMJun 18 2024 7:00PM CDTTropical StormJune 19, 2024 at 8:00 AMJun 19 2024 7:00AM CDT2,511
Tropical StormJune 19, 2024 at 8:00 AMJun 19 2024 7:00AM CDTTropical StormJune 19, 2024 at 8:00 PMJun 19 2024 7:00PM CDT2,511
Tropical StormJune 19, 2024 at 8:00 PMJun 19 2024 7:00PM CDTTropical StormJune 19, 2024 at 11:00 PMJun 19 2024 10:00PM CDT2,511
Tropical StormJune 19, 2024 at 11:00 PMJun 19 2024 10:00PM CDTTropical DepressionJune 20, 2024 at 8:00 AMJun 20 2024 7:00AM CDT2,511
Tropical DepressionJune 20, 2024 at 8:00 AMJun 20 2024 7:00AM CDTTropical RainstormJune 20, 2024 at 8:00 PMJun 20 2024 7:00PM CDT

2,511

 

From this I expect needing to create a dictionary and or an array where I combine the Classification fields, Time Fields, and Time Labels where I can then perform a sort on the TIME

I've kept the TIME_LABEL since it is already a string and I wouldn't need to convert TIME later via Text().

CLASSIFICATIONTIMETIME_LABEL
Tropical RainstormJune 18, 2024 at 11:00 AMJun 18 2024 10:00AM CDT
Tropical RainstormJune 18, 2024 at 8:00 PMJun 18 2024 7:00PM CDT
Tropical RainstormJune 18, 2024 at 8:00 PMJun 18 2024 7:00PM CDT
Tropical StormJune 19, 2024 at 11:00 PMJun 19 2024 10:00PM CDT
Tropical StormJune 19, 2024 at 11:00 PMJun 19 2024 10:00PM CDT
Tropical StormJune 19, 2024 at 8:00 AMJun 19 2024 7:00AM CDT
Tropical StormJune 19, 2024 at 8:00 AMJun 19 2024 7:00AM CDT
Tropical StormJune 19, 2024 at 8:00 PMJun 19 2024 7:00PM CDT
Tropical StormJune 19, 2024 at 8:00 PMJun 19 2024 7:00PM CDT
Tropical DepressionJune 20, 2024 at 8:00 AMJun 20 2024 7:00AM CDT
Tropical DepressionJune 20, 2024 at 8:00 AMJun 20 2024 7:00AM CDT
Tropical RainstormJune 20, 2024 at 8:00 PMJun 20 2024 7:00PM CDT

 

After that I would then run a for loop and compare the next value and if they match skip to result in a final as such:

CLASSIFICATIONTIMETIME_LABEL
Tropical RainstormJune 18, 2024 at 11:00 AMJun 18 2024 10:00AM CDT
Tropical StormJune 19, 2024 at 11:00 PMJun 19 2024 10:00PM CDT
Tropical DepressionJune 20, 2024 at 8:00 AMJun 20 2024 7:00AM CDT
Tropical RainstormJune 20, 2024 at 8:00 PMJun 20 2024 7:00PM CDT

 

After that returning the items with the proper format of the string from above:

Tropical Rainstorm: June 18, 2024 at 11:00 AM → Tropical Storm: June 19, 2024 at 11:00 PM → Tropical Depression: June 20, 2024 at 8:00 AM → Tropical Rainstorm: June 20, 2024 at 8:00 PM

 

//grab the ID of the storm
var id = $feature.STORM_ID
//filter for all the features with the same ID
var fs = Filter(FeatureSetByName($map, 'Tropical_WOM',['BEGIN_CLASSIFICATION','BEGIN_DATE_TIME','END_CLASSIFICATION','END_DATE_TIME']), 'STORM_ID = @ID')
//count number of features for iterating
var items = Count(fs)
Console(items)
//set a counter to 0 for looping
var counter = 0

//add all the features to an array
var fs_arr = []
for(var f in fs) {
    var c = Dictionary('BEGIN_CLASSIFICATION',`${f.BEGIN_CLASSIFICATION}`,'BEGIN_DATE_TIME',`${f.BEGIN_DATE_TIME}`,'END_CLASSIFICATION',`${f.END_CLASSIFICATION}`,'END_DATE_TIME',`${f.END_DATE_TIME}`)
    Push(fs_arr, c)
}
console (fs_arr)
return fs_arr

 

 

Thanks in advance for the help

0 Kudos
1 Solution

Accepted Solutions
SpatialSean
New Contributor III

I figured it out, took a bit but for anyone else that needs info here was the final

 

// grab the ID of the storm and filter features
var id = $feature.STORM_ID;
var fs = Filter(FeatureSetByName($map, 'Tropical_WOM', ['BEGIN_CLASSIFICATION', 'BEGIN_DATE_TIME', 'END_CLASSIFICATION', 'END_DATE_TIME']), 'STORM_ID = @ID');

// Initialize an array to hold unique classifications
var uniqueClassifications = [];

// Function to format the date and time
function formatDateTime(dateTime) {
   return Text(dateTime, 'MMMM DD, YY hh:mma');
}

// Initialize previous classification as empty
var prevClassification = '';

// Loop through the features using a for loop
for (var f in fs) {
   var beginClass = f.BEGIN_CLASSIFICATION;
   var endClass = f.END_CLASSIFICATION;
   var beginTime = formatDateTime(f.BEGIN_DATE_TIME);
   var endTime = formatDateTime(f.END_DATE_TIME);
   // Check if the current classification is different from the previous one
   if (beginClass != prevClassification) {
       // Add the classification and begin time to the array
       Push(uniqueClassifications, (beginClass + ': ' + beginTime));
   }
   // If the end classification is different from the begin classification, add it as well
   if (endClass != beginClass) {
       Push(uniqueClassifications, (endClass + ': ' + endTime));
   }
   // Update the previous classification
   prevClassification = endClass;
}

// Join the classifications with the arrow symbol to create the final string
var finalString = Concatenate(uniqueClassifications,' → ')
// Return the final string
return finalString;

View solution in original post

0 Kudos
1 Reply
SpatialSean
New Contributor III

I figured it out, took a bit but for anyone else that needs info here was the final

 

// grab the ID of the storm and filter features
var id = $feature.STORM_ID;
var fs = Filter(FeatureSetByName($map, 'Tropical_WOM', ['BEGIN_CLASSIFICATION', 'BEGIN_DATE_TIME', 'END_CLASSIFICATION', 'END_DATE_TIME']), 'STORM_ID = @ID');

// Initialize an array to hold unique classifications
var uniqueClassifications = [];

// Function to format the date and time
function formatDateTime(dateTime) {
   return Text(dateTime, 'MMMM DD, YY hh:mma');
}

// Initialize previous classification as empty
var prevClassification = '';

// Loop through the features using a for loop
for (var f in fs) {
   var beginClass = f.BEGIN_CLASSIFICATION;
   var endClass = f.END_CLASSIFICATION;
   var beginTime = formatDateTime(f.BEGIN_DATE_TIME);
   var endTime = formatDateTime(f.END_DATE_TIME);
   // Check if the current classification is different from the previous one
   if (beginClass != prevClassification) {
       // Add the classification and begin time to the array
       Push(uniqueClassifications, (beginClass + ': ' + beginTime));
   }
   // If the end classification is different from the begin classification, add it as well
   if (endClass != beginClass) {
       Push(uniqueClassifications, (endClass + ': ' + endTime));
   }
   // Update the previous classification
   prevClassification = endClass;
}

// Join the classifications with the arrow symbol to create the final string
var finalString = Concatenate(uniqueClassifications,' → ')
// Return the final string
return finalString;
0 Kudos