A set of Python scripts and notebooks to help administer and configure Workforce projects.

Overview

Workforce Scripts

A set of Python scripts and notebooks to help administer and configure Workforce projects.

Notebooks

Several example Jupyter notebooks are provided to demonstrate some more advanced workflows that are possible via the ArcGIS API for Python and Workforce:

Notebooks used for previous demos are also available:

In addition, we have uploaded our AGOL-compatible notebooks into a publicly accessible group of Hosted Notebooks in ArcGIS Online

Scripts

Supports:

  • Python 3.6+
  • Python API for ArcGIS 1.8.3+

The Workforce team released a new version of the app supporting offline-enabled Projects in July 2020. To work with those projects in Python and deploy the corresponding scripts in this repo, users will need to update their version of the Python API to 1.8.3. This can be downloaded in Conda prior to 1.8.3's official release via:

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

A set of Python scripts using the ArcGIS API for Python v1.8.3+. These scripts support Workforce in both ArcGIS Online and ArcGIS Enterprise.

Note that some may scripts may work with a Python API for ArcGIS version that is less than 1.8.3 but this cannot be guaranteed.

Features

Functionality Script
Create Assignment Types create_assignment_types.py
Import Workers import_workers.py
Import Dispatchers import_dispatchers.py
Create Assignments From CSV create_assignments_from_csv.py
Copy Assignments To Feature Service copy_assignments_to_fs.py
Export Assignments to CSV export_assignments_from_csv.py
Check Assignment Completion Location check_completion_location.py
Delete Assignments delete_assignments.py
Delete Assignment Types create_assignment_types.py
Assignment Monitor (Slack Integration) assignment_monitor.py
Migrate to Version 2 Project migrate_to_v2.py
Reset Stale Workers reset_stale_workers.py
Report Incomplete Assignments with Work Orders report_incomplete_assignments_with_work_orders.py
Report Complete Assignments without Work Orders report_complete_assignments_without_work_orders.py
Create Default Ops Dashboard create_ops_dashboard.py
Create Joined View create_joined_view

Instructions

  1. Install ArcGIS API for Python package via Conda as described here.
  2. Clone or download this repository
  3. In terminal/cmd navigate to the scripts folder
  4. Create Conda environment
    1. Install Anaconda
    2. Run conda env create --file environment.yml to create the virtual environment with the correct dependencies
    3. Run conda activate workforce-scripts to activate the environment
  5. (Optional - dev only) Configure pre-commit to run flake8 linting on pushes
    • pre-commit install --hook-type pre-push

To run in ArcGIS Notebooks:

  1. Visit our AGOL Hosted Notebooks group
  2. Click on "Content"
  3. Choose a notebook you'd like
  4. Click on the thumbnail for "Open Notebook" to open in ArcGIS Notebooks

Resources

Issues

Although we do our best to ensure these scripts and notebooks work as expected, they are provided as is and there is no official support.

If you find a bug, please let us know by submitting an issue.

Contributing

Esri welcomes contributions from anyone and everyone. Please see our guidelines for contributing.

Licensing

Copyright 2020 Esri

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

A copy of the license is available in the repository's LICENSE file.

Comments
  • create_assignments_from_csv xField label corruption issue

    create_assignments_from_csv xField label corruption issue

    I'm using create_assignments_from_csv.py to upload assignments into Enterprise Workforce. (NB I have not before tried to get this working since my Customer migrated from AGOL (where it worked fine)). I call the script from a bash script, which passes the right parameters. I get this error on the end of my output: args.dateFormat, args.wkid, args.attachmentFileField, args.workerField, args.timezone) | File "create_assignments_from_csv.py", line 78, in get_assignments_ from_csv | new_assignment["data"]["geometry"] = dict(x=float(assignment[xField]), y=float(assignment[yField]), | KeyError: 'xField' | If I tweak your script to show the assignment created I get this: {'yField': '50.93831389', 'Description': 'Cut 2', 'Due Date': '08/21/2018 23:59:59', '\xef\xbb\xbfxField': '-0.033513889', 'Worker': 'ruralgrass1', 'Work Order Id': 'RUZ7', 'Priority': '3', 'Location': 'Rural Zone 7', 'Type': '2', 'Dispatcher': '1', 'attachment': ''} Clearly, the xField label is causing issues. I can't find those extra characters anywhere in the Python scripts. This happens every time I run it.

    The section of my Bash script which names the column label is as follows: -xField \"xField\"

    Thanks very much for reading this. [Edited to remove extra line feed in quote caused by pasting error]

    opened by jonathancgroves 11
  • Do scripts work with New WorkForce?

    Do scripts work with New WorkForce?

    Describe the bug I created a new WorkForce project at workforce.arcgis.com.

    From within ArcGIS Online, using Notebooks..... In script 1, I connect to the organization using the same account used to create a WorkForce Project.

    The following code does not list any New WorkForce projects. I do see classic WorkForce Projects item = gis.content.search("type:'Workforce Project' '*'")

    I also try AGO assistant. I grab the project id code of the New WorkForce project and use it to search AGO assistant. The only items returned are the Feature Layer for the New Workforce Project.

    opened by bkaplan1 10
  • Invalid Assignment Type

    Invalid Assignment Type

    Describe the bug The script returns this output every time:

    [2018-11-28 14:56:33,043] [create_assignments_from_csv.py: 75 - main()] [MainThread] [ root] [ INFO] Authenticating... [2018-11-28 14:56:36,363] [create_assignments_from_csv.py: 88 - main()] [MainThread] [ root] [ INFO] Reading CSV file: ../sample_data/assignments.csv... [2018-11-28 14:56:36,454] [create_assignments_from_csv.py: 217 - ()] [MainThread] [ root] [CRITICAL] Exception detected, script exiting [2018-11-28 14:56:36,455] [create_assignments_from_csv.py: 218 - ()] [MainThread] [ root] [CRITICAL] Invalid Assignment Type [2018-11-28 14:56:36,462] [create_assignments_from_csv.py: 219 - ()] [MainThread] [ root] [CRITICAL] Traceback (most recent call last) To Reproduce Steps to reproduce the behavior:

    1. When I clear out the assignments.csv file of any entries (only the headers are left), the script completes successfully, which makes me think that my formatting is wrong.

    2. Here is my script (minus the credentials): python create_assignments_from_csv.py -csv-file "../sample_data/assignments.csv" -u xxxxx -p xxxxxx -org "XXXXXXX" -project-id "f1908a1781734f3a890add01718e08b9" -x-field "xField" -y-field "yField" -assignment-type-field "Type" -location-field "Location" -description-field "Description" -priority-field "Priority" -work-order-id-field "WorkOrderId" -due-date-field "DueDate" -attachment-file-field "Attachment" -wkid 102100 -log-file "../log.txt" -worker-field "Worker" -timezone "US/Pacific"

    3. Here is the csv I'm trying to upload: xField,yField,Type,Location,Dispatcher,Description,Priority,WorkOrderId,DueDate,Attachment,Worker 4232820.809,289619.8689,2,Flush,1,Flush,None,1,01/31/2019,,1 4232820.809,289619.8689,2,Flush,1,Flush,None,2,01/31/2019,,1

    4.There are currently two assignment types in the project: Flush and Don't Flush (which are shown as coded values 2 & 3).

    Expected behavior A clear and concise description of what you expected to happen.

    Desktop (please complete the following information):

    • OS: windows 10
    • Python Version:3.6.5

    Additional context Add any other context about the problem here.

    opened by kawikakanaka 8
  • KeyError 'globalid'

    KeyError 'globalid'

    Hey,

    i'm getting and error when I run this on my enterprise install. Copying assignments from workforce installed in portal to a feature service on the same server. Any thoughts? We have this working on the same layer on our previous server so I'm a bit stumped.

    archived_assignments = target_fl.query(out_fields=field_mappings[project._assignment_schema.global_id]) | KeyError: 'globalid'

    Thanks

    opened by cpsmhammond 8
  • Support none ASCII characters in create_assignments from csv.

    Support none ASCII characters in create_assignments from csv.

    My Description field has none ascii characters (á,é,í,ó,ú). The arcgis_api create_assignments_from_csv python creats the assignments but the Description filed scribles the words with does none ascii characters. I've atached a sample. my_assignments.txt

    opened by hmelendez 7
  • Getting KeyError as

    Getting KeyError as "assignments" when using workforce with geoprocessing tool.

    Hello,

    I created a toolbox that works in local server but i could not make it work as a geoprocessing service.

    My idea is that i want to be able to reach to workforce through using ArcGIS API and want to make operations over there by using the tool i created. It works without a problem on the ArcGIS Pro, but when i publish it as a geoprocessing device i get the following error.

    Traceback (most recent call last): File "", line 71, in execute File "C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\apps\workforce\project.py", line 45, in init self._assignment_schema = AssignmentSchema(self.assignments_layer) File "C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis_impl\common_utils.py", line 158, in _lazy_property setattr(self, attr_name, fn(self)) File "C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\apps\workforce\project.py", line 233, in assignments_layer return FeatureLayer(self.assignments_layer_url, self.gis) File "C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\apps\workforce\project.py", line 183, in assignments_layer_url return self._item_data['assignments']['url'] KeyError: 'assignments' Failed to execute (Tool). Failed to execute (Tool). Failed.

    What could be the reason?

    opened by fatihenesusta 6
  • create_assignments_from_csv fails in ArcGIS Enterprise.

    create_assignments_from_csv fails in ArcGIS Enterprise.

    I'm migrating my workforce to ArcGIS Enterprise and the workforce hosted feature layer schema in portal gets created with all atrubutes names in small caps (assignmentType || assignmenttype). So the script is not matching and loading the csv fields correctly. The assignments get created but the fallowing fields are not been populated:

    • dueDate
    • assignmentType
    • workOrderId
    • workerId Here is the schema for ArcGIS Online and the one created in ArcGIS Enterprise.

    image image

    opened by hmelendez 6
  • AssignmentType shows GUID rather than text Alias in ArcGIS Pro

    AssignmentType shows GUID rather than text Alias in ArcGIS Pro

    Describe the bug New Workforce Projects AssignmentType field values in the Assignment layer display the GUID value rather than a human readable text value when the feature service is displayed in ArcGIS Pro. I was hoping to use Append in Pro to migrate assignments from V1 to V2 but found this issue.

    To Reproduce Steps to reproduce the behavior:

    1. Migrate V1 to V2 project or create a new Project
    2. Create assignment types
    3. Add assignment layer to an ArcGIS Pro map and start editing
    4. In Attribute window, GUID values are shown rather than human readable aliases

    image

    opened by langdonms 5
  • Update import_workers.py to allow importing Dispatchers as well

    Update import_workers.py to allow importing Dispatchers as well

    Would be useful if import_workers.py could also be used to add Dispatchers as well. I'd suggest changing the name of the script to import_users.py (breaking change?) and adding a userRole field where the value could be either worker or dispatcher.

    Maybe this is already possible and I just missed the documentation on it

    opened by jmdye 5
  • Create assignments - workOrderIdField & locationField

    Create assignments - workOrderIdField & locationField

    Scripts work great and are very useful, but I'm a bit unclear on two things on the assignment creation script:

    1. It seems the script tries to enforce the workOrderIdField being an integer. Why is that? The Assignments schema in a Workforce project seems to have the workOrderId field as text. This is actually a bit of a blocker since those IDs might originate from other systems, and in my case they are not just numbers. workforce_servicesschema

    UPDATE: Modified line 81 in the script, by removing the int() around the workOrderIdField and it now imports the ID fields as is. Still would like to know why it was enforced?

    1. Why is the locationField required? Shouldn't it be enough having X/Y coordinates to establish it? If X/Y is all you have you would potentially need to reverse geocode to get some sort of textual location info
    opened by nart-t 5
  • Can't Assign Work: ValidationError: Assignment must have geometry

    Can't Assign Work: ValidationError: Assignment must have geometry

    Describe the bug I can create assignments but when I go to assign the assignments to a specific user I get this error: ValidationError: Assignment must have geometry

    To Reproduce Here's my code:

    user = project.workers.get(user_id="username") test_backflows = project.assignment_types.get(name="Test Backflow Device") assignments = project.assignments.search(f"status=0 AND assignmentType={test_backflows.code}") for assignment in assignments: assignment.worker = user assignment.status = "assigned" assignment.assigned_date = datetime.datetime.utcnow() assignments = project.assignments.batch_update(assignments)

    opened by r3cyclops 4
  • Optimally Creating and Assigning Work Orders Based on Routes

    Optimally Creating and Assigning Work Orders Based on Routes

    Hello, In the 'Optimally Creating and Assigning Work Orders Based on Routes' notebook there is the following code:

    assignments_to_add = []
    for _, row in routes.iterrows():
        worker = random.choice(workers)
        workers.remove(worker)
        route_stops = stops.loc[(stops['RouteName'] == row["RouteName"]) & stops['globalid'].notnull()]
        for _, stop in route_stops.iterrows():
            assignments_to_add.append(workforce.Assignment(
                project,
                assignment_type="Inspection",
                location=stop["name"],
                status="assigned",
                worker=worker,
                assigned_date=datetime.now(),
                due_date=stop["DepartTime"],
                geometry=stop["SHAPE"]
            ))
    assignments = project.assignments.batch_add(assignments_to_add)
    

    I think the line workers.remove(worker) should be removed because then in assignments_to_add.append() the worker=worker will give an error of empty list. Am I wrong?

    Thanks

    opened by MVAC13 2
  • Not letting worker finish assignment if worker is not nearby assignment

    Not letting worker finish assignment if worker is not nearby assignment

    *If a worker is not nearby a mission worker still can finish the mission. If you have let's say 500 worker in a project it won't be easy to track down which missions are correctly completed.

    It is not easy to track down a lot of workers. We have a workforce project fully integrated with many other arcgis platforms such as dashboard and collector. If a worker completes the mission without being there, all the data we collect becomes unusable.

    **In order to complete the mission worker must be inside of the described radius around the assignment mission **

    An implementation or if there is a way to make this happen or any alternative to consider.

    opened by fatihenesusta 2
Owner
Esri
Esri
Django-environ allows you to utilize 12factor inspired environment variables to configure your Django application.

Django-environ django-environ allows you to use Twelve-factor methodology to configure your Django application with environment variables. import envi

Daniele Faraglia 2.7k Jan 3, 2023
A tool to manage configuration files, build scripts etc. across multiple projects.

A tool to manage configuration files, build scripts etc. across multiple projects.

null 8 Dec 14, 2022
🤫 Easily manage configs and secrets in your Python projects (with CLI support)

Installation pip install confidential How does it work? Confidential manages secrets for your project, using AWS Secrets Manager. First, store a secr

Candid™️ 63 Oct 30, 2022
A Python library to parse PARI/GP configuration and header files

pari-utils A Python library to parse PARI/GP configuration and header files. This is mainly used in the code generation of https://github.com/sagemath

Sage Mathematical Software System 3 Sep 18, 2022
A small example project for efficiently configuring a Python application with YAMLs and the CLI

Hydra Example Project for Python A small example project for efficiently configuring a Python application with YAMLs and the CLI. Why should I care? A

Florian Wilhelm 4 Dec 31, 2022
Python 3+ compatible port of the configobj library

configobj Python 3+ compatible port of the configobj library. Documentation You can find a full manual on how to use ConfigObj at readthedocs. If you

Differently Sized Kittens 288 Dec 14, 2022
Configuration Management for Python ⚙

dynaconf - Configuration Management for Python. Features Inspired by the 12-factor application guide Settings management (default values, validation,

Bruno Rocha 2.8k Jan 6, 2023
Flexible Python configuration system. The last one you will ever need.

OmegaConf Description Project Code quality Docs and support OmegaConf is a hierarchical configuration system, with support for merging configurations

Omry Yadan 1.4k Jan 2, 2023
A modern simfile parsing & editing library for Python 3

A modern simfile parsing & editing library for Python 3

ash garcia 38 Nov 1, 2022
Python Marlin Configurator to make valid configuration files to be used to compile Marlin with.

marlin-configurator Concept originally imagined by The-EG using PowerShell Build Script for Marlin Configurations The purpose of this project is to pa

DevPeeps 2 Oct 9, 2021
Read configuration settings from python configuration files.

Maison Read configuration settings from python configuration files. Motivation When developing a python application, e.g a command-line tool, it can b

null 9 Jan 4, 2023
Simple dataclasses configuration management for Python with hocon/json/yaml/properties/env-vars/dict support.

Simple dataclasses configuration management for Python with hocon/json/yaml/properties/env-vars/dict support, based on awesome and lightweight pyhocon parsing library.

Teo Stocco 62 Dec 23, 2022
Scooch Configures Object Oriented Class Hierarchies for python

Scooch Scooch Configures Object Oriented Class Hierarchies for python. A good place to start with Scooch is at the documentation found here. Scooch is

Pandora Media, Inc. 6 Dec 20, 2022
Apt2sbom python package generates SPDX or YAML files

Welcome to apt2sbom This package contains a library and a CLI tool to convert a Ubuntu software package inventory to a software bill of materials. You

Eliot Lear 15 Nov 13, 2022
environs is a Python library for parsing environment variables.

environs: simplified environment variable parsing environs is a Python library for parsing environment variables. It allows you to store configuration

Steven Loria 920 Jan 4, 2023
Python YAML Environment (ymlenv) by Problem Fighter Library

In the name of God, the Most Gracious, the Most Merciful. PF-PY-YMLEnv Documentation Install and update using pip: pip install -U PF-PY-YMLEnv Please

Problem Fighter 2 Jan 20, 2022
Organize Django settings into multiple files and directories. Easily override and modify settings. Use wildcards and optional settings files.

Organize Django settings into multiple files and directories. Easily override and modify settings. Use wildcards in settings file paths and mark setti

Nikita Sobolev 942 Jan 5, 2023
Generate config files and qr codes for wireguard vpn

wireguard config generator for python Generate config files and qr codes for wireguard vpn You will need to install qrcode and pillow in python and yo

null 18 Dec 2, 2022
Tools to assist with the configuration and maintenance of fapolicyd.

Tools to assist with the configuration and maintenance of fapolicyd.

Concurrent Technologies Corporation (CTC) 7 Dec 27, 2022