How do I vary symbology by start and end time?

854
9
Jump to solution
12-17-2021 11:08 AM
EJhanekSzypulski
New Contributor II

Hello all,

I am creating a web map for our Tribe's fishermen to see what harvest areas are open, closed, or upcoming (to be opened soon).

The field "Status" holds the text attributes "Open," "Closed," and "Upcoming," which define the symbology of green, red, and yellow, respectively, for each polygon.

The field "StartTime" holds the date attribute of when that area is opened for fishing.

The field "EndTime" holds the date attribute of when that area is closed for fishing.

I would like the symbology to remain the same green, red, and yellow, but be defined by the "StartTime" and "EndTime" fields in reference to the current date and time.

Is this possible? 

Thanks in advance,

~Jhanek

0 Kudos
2 Solutions

Accepted Solutions
KenBuja
MVP Esteemed Contributor

Yes, you can do something like this

 

if (Now() < $feature.StartTime){
  return "Upcoming";
} else if (Now() <= $feature.EndTime){
  return  "Open";
} else {
  return "Closed";
} 

 

 

View solution in original post

rzufelt
Occasional Contributor

You can also use the same (or similar) Arcade in the popup and don't even need to maintain a status field (status field would now be an expression also).

this way, the symbol color and the popup "Status" info will always be the same.

 

R_

View solution in original post

9 Replies
KenBuja
MVP Esteemed Contributor

Yes, you can do something like this

 

if (Now() < $feature.StartTime){
  return "Upcoming";
} else if (Now() <= $feature.EndTime){
  return  "Open";
} else {
  return "Closed";
} 

 

 

EJhanekSzypulski
New Contributor II

This is great! Thank you.

This is changing the symbology according to color but it is not updating the status field with the corresponding attribute, "Open," "Closed," or "Upcoming."

Is there something else I need to do to make this happen?

Thanks again,

~Jhanek

0 Kudos
jcarlson
MVP Esteemed Contributor

I don't think you can get an attribute to be time-based like that, unless you have a Python script running to update it on a daily basis or something. If the status is basically a function of the start/end times and the current time, then do you really need it?

- Josh Carlson
Kendall County GIS
0 Kudos
KenBuja
MVP Esteemed Contributor

Yes, this only applied to the symbology. Read this blog article on using Arcade for field calculations

I'm wondering how often you foresee this value getting recalculated since it's based on the current time. Would it be on a daily basis or would it be ever time someone accesses the web map? Or every time a popup is opened? You configure the popup so it doesn't expressly use that field but just uses the results of the arcade code.

0 Kudos
EJhanekSzypulski
New Contributor II

I will read through the article now, thank you.

I think it would be best for it to be recalculated each time an end-user opens the map. The goal is to automate the "Status" field and corresponding symbology to prevent a scenario where we were unable to manually update the symbology on a weekend or if the regulation ends at midnight, etc., so the end-user won't be fishing when they're not supposed to.

0 Kudos
KenBuja
MVP Esteemed Contributor

The good thing about using the Arcade code to symbolize your map is that it does it automatically and doesn't rely on the static "Status" field. You don't have to worry about manually update the symbology when the regulation begins or ends. I wouldn't even use (or show) the table's status field, but instead rely on the code to calculate it.

0 Kudos
jcarlson
MVP Esteemed Contributor

If you really had to:

from arcgis import GIS
gis = GIS('your portal url', 'user', 'pass')

fl = gis.content.get('layer itemid').layers[0] # or other layer index as needed

sql = """
CASE
WHEN CURRENT_TIMESTAMP() < StartTime THEN 'Upcoming'
WHEN CURRENT_TIMESTAMP() <= EndTime  THEN 'Open'
ELSE 'Closed'
END
"""

fl.calculate(calc_expression={'field':'status', 'sqlExpression':sql})

Schedule something like this to run at regular intervals.

But Ken's right, the benefit of the Arcade expression is that it's not beholden to a static attribute. If the machine running your automated field calculation script is ever offline, you'll risk showing incorrect information. But the Arcade expression evaluates any time the map / popup opens, and doesn't rely on anything else.

- Josh Carlson
Kendall County GIS
0 Kudos
rzufelt
Occasional Contributor

You can also use the same (or similar) Arcade in the popup and don't even need to maintain a status field (status field would now be an expression also).

this way, the symbol color and the popup "Status" info will always be the same.

 

R_

EJhanekSzypulski
New Contributor II

I just figured that out and came here to update! Works perfectly.

Thanks!

~Jhanek

0 Kudos