AnsweredAssumed Answered

Unable to assign work in workforce, based on pre-defined zones

Question asked by simon.law_ren on Mar 2, 2020
Latest reply on Mar 9, 2020 by APulver-esristaff

Hi there

 

I am following the examples in this workbook workforce-scripts/3 - Assigning Work.ipynb at master · Esri/workforce-scripts · GitHub 

 

Because i want to assign work to our workforce based on the predetermined zones from an existing feature layer on the map.

 

I have completed my code section like so: 

for assignment in assignments:
    contains = squadZones_df["SHAPE"].geom.contains(Geometry(assignment.geometry))
    containers = squadZones_df[contains]
    if not containers.empty:
        squadZone = containers['OBJECTID'].iloc[0]
        if squadZone == 2:
            assignment.worker = squad_WSFF
            assignment.status = "assigned"
            assignment.assigned_date = datetime.utcnow()
        elif squadZone == 5:
            assignment.worker = squad_LL
            assignment.status = "assigned"
            assignment.assigned_date = datetime.utcnow()
        elif squadZone == 8:
            assignment.worker = squad_WG
            assignment.status = "assigned"
            assignment.assigned_date = datetime.utcnow()
        elif squadZone == 11:
            assignment.worker = squad_RR
            assignment.status = "assigned"
            assignment.assigned_date = datetime.utcnow()
        elif squadZone == 16:
            assignment.worker = squad_HLG
            assignment.status = "assigned"
            assignment.assigned_date = datetime.utcnow()
        elif squadZone == 18:
            assignment.worker = squad_JE
            assignment.status = "assigned"
            assignment.assigned_date = datetime.utcnow()

assignments = project.assignments.batch_update(assignments)

 

However, I keep getting this error:

 

Traceback (most recent call last):
File "C:/Users/.../PycharmProjects/APITesting/assign_work.py", line 45, in <module>
containers = squadZones_df[contains]
File "C:\Users\...\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\frame.py", line 2970, in __getitem__
if com.is_bool_indexer(key):
File "C:\Users\...\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\common.py", line 130, in is_bool_indexer
raise ValueError(na_msg)
ValueError: cannot index with vector containing NA / NaN values

 

Can anyone help with this at all? My feature layer table looks like this:

 

 

 

Thanks!

Outcomes