AnsweredAssumed Answered

Issue with spatially assigning assignments in Notebooks

Question asked by Tyler.Dunn@thorntonco.gov_cityofthornton on Oct 5, 2020
Latest reply on Oct 6, 2020 by Tyler.Dunn@thorntonco.gov_cityofthornton

So I've been using Notebooks in ArcOnline to do some batch assignments for a Workforce project. Quick run down of the project: Fire Dept needs to do bi annually inspections on every business in the city. I've built a survey in survey123 that'll handle all the questions. They'll use Workforce to dispatch their people to the locations. This is decided by fire station areas. I'd like to automate creating these assignments by the station area polygons so we dont have to do it by hand twice a year. 


I have their dispatch polygons hosted on arconline but can't seem to get the script to work. Here's what it looks like, it's 100% modelled off the template on github:


conda install -c esri/label/prerelease -c esri arcgis==1.8.3

conda update -n base -c defaults conda

from datetime import datetime
from arcgis.gis import GIS
from arcgis.geometry import Geometry
from arcgis.mapping import WebMap
from arcgis.apps import workforce
from datetime import datetime

gis = GIS("home")
item = gis.content.get("afca01f6dda742e69896412da860b924")
project = workforce.Project(item)

# Get Layer of City Districts

fireInspectionDistricts_layer = gis.content.get("0afccc9e48c3471f8bfc1954f4602c23").layers[0]
fireInspectionDistricts_map ="Thornton, CO", zoomlevel=10)

# Add Assignments to the Map


# Create a spatially enabled dataframe of the districts

fireInspectionDistricts_df = fireInspectionDistricts_layer.query(as_df=True)
print (fireInspectionDistricts_df)
#0         1    6  None    None  169552.086294  4.020346e+08  
#1         2    2  None    None   64910.441381  7.760154e+07  
#2         3    1  None    None   49842.642184  8.343908e+07  
#3         4    3  None    None  143750.130571  2.249331e+08  
#4         5    4  None    None   57284.309928  1.412634e+08  
#5         6    5  None    None  129542.914257  3.418221e+08

# Get all of the unassigned assignments

assignments ="status=0")

# Assign Assignments Based on Which District They Intersect¶

tyler = project.workers.get(user_id="Tyler.Dunn@XXXXXX")
brandi = project.workers.get(user_id="Brandi.Rank@XXXXXXX")
for assignment in assignments:
    contains = fireInspectionDistricts_df["SHAPE"].geom.contains(Geometry(assignment.geometry))
    print (contains)
    #0    False
    #1    False
    #2    False
    #3    False
    #4    False
    #5    False
    #Name: contains, dtype: bool  
    containers = fireInspectionDistricts_df[contains]
    print (containers)
    #Empty DataFrame
    #Index: []

    if not containers.empty:
        fireInspectionDistrict = containers['ZONE'].iloc[0]
        if fireInspectionDistrict == 4:
            assignment.worker = tyler
            assignment.status = "assigned"
            assignment.assigned_date = datetime.utcnow()
        elif fireInspectionDistrict == 2:
            assignment.worker = brandi
            assignment.status = "assigned"
            assignment.assigned_date = datetime.utcnow()    
assignments = project.assignments.batch_update(assignments)

# Verify Assignments are Assigned

webmap ="Thornton, CO", zoomlevel=11)

One of my concerns is that the results of containers is returning and empty dataframe and empty index. 
Not sure if that's part of the issue, but at this point I've hit a brick wall.

Any suggestions?