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):
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_CLASSIFICATION | BEGIN_DATE_TIME | BEGIN_DATE_TIME_LABEL | END_CLASSIFICATION | END_DATE_TIME | END_DATE_TIME_LABEL | STORM_ID |
Tropical Rainstorm | June 18, 2024 at 11:00 AM | Jun 18 2024 10:00AM CDT | Tropical Rainstorm | June 18, 2024 at 8:00 PM | Jun 18 2024 7:00PM CDT | 2,511 |
Tropical Rainstorm | June 18, 2024 at 8:00 PM | Jun 18 2024 7:00PM CDT | Tropical Storm | June 19, 2024 at 8:00 AM | Jun 19 2024 7:00AM CDT | 2,511 |
Tropical Storm | June 19, 2024 at 8:00 AM | Jun 19 2024 7:00AM CDT | Tropical Storm | June 19, 2024 at 8:00 PM | Jun 19 2024 7:00PM CDT | 2,511 |
Tropical Storm | June 19, 2024 at 8:00 PM | Jun 19 2024 7:00PM CDT | Tropical Storm | June 19, 2024 at 11:00 PM | Jun 19 2024 10:00PM CDT | 2,511 |
Tropical Storm | June 19, 2024 at 11:00 PM | Jun 19 2024 10:00PM CDT | Tropical Depression | June 20, 2024 at 8:00 AM | Jun 20 2024 7:00AM CDT | 2,511 |
Tropical Depression | June 20, 2024 at 8:00 AM | Jun 20 2024 7:00AM CDT | Tropical Rainstorm | June 20, 2024 at 8:00 PM | Jun 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().
CLASSIFICATION | TIME | TIME_LABEL |
Tropical Rainstorm | June 18, 2024 at 11:00 AM | Jun 18 2024 10:00AM CDT |
Tropical Rainstorm | June 18, 2024 at 8:00 PM | Jun 18 2024 7:00PM CDT |
Tropical Rainstorm | June 18, 2024 at 8:00 PM | Jun 18 2024 7:00PM CDT |
Tropical Storm | June 19, 2024 at 11:00 PM | Jun 19 2024 10:00PM CDT |
Tropical Storm | June 19, 2024 at 11:00 PM | Jun 19 2024 10:00PM CDT |
Tropical Storm | June 19, 2024 at 8:00 AM | Jun 19 2024 7:00AM CDT |
Tropical Storm | June 19, 2024 at 8:00 AM | Jun 19 2024 7:00AM CDT |
Tropical Storm | June 19, 2024 at 8:00 PM | Jun 19 2024 7:00PM CDT |
Tropical Storm | June 19, 2024 at 8:00 PM | Jun 19 2024 7:00PM CDT |
Tropical Depression | June 20, 2024 at 8:00 AM | Jun 20 2024 7:00AM CDT |
Tropical Depression | June 20, 2024 at 8:00 AM | Jun 20 2024 7:00AM CDT |
Tropical Rainstorm | June 20, 2024 at 8:00 PM | Jun 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:
CLASSIFICATION | TIME | TIME_LABEL |
Tropical Rainstorm | June 18, 2024 at 11:00 AM | Jun 18 2024 10:00AM CDT |
Tropical Storm | June 19, 2024 at 11:00 PM | Jun 19 2024 10:00PM CDT |
Tropical Depression | June 20, 2024 at 8:00 AM | Jun 20 2024 7:00AM CDT |
Tropical Rainstorm | June 20, 2024 at 8:00 PM | Jun 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
Solved! Go to Solution.
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;
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;