This script checks the location and time of when an assignment was completed against the location of the worker at that same time. It is designed to find out if workers are completing assignments without visiting the location. It is an extension of the Copy Assignments script in that assignments that were improperly completed are copied to a different feature service so they can be analyzed.
Supports Python 3.5+, Version 1 (connected) Projects only To check completion location using the Tracker Location Tracking Service as opposed to a Workforce tracks layer, please see: https://github.com/Esri/tracker-scripts/blob/master/check_edit_location.md
This script relies on a JSON configuration file that maps the original field names to the field names in the target feature service. An example is shown here The script uses the following parameters:
- -config-file <configFile> The json file containing the field mappings
- -log-file <logFile> The log file to use for logging messages
- -project-id <projectId> - The workforce project ID (from AGOL)
- -target-fl <targetFL> - The full url of the target feature layer where the assignments will be copied to
- -workers <worker1> <worker2> ...<workern> - The specific workers to check (optional - default to all workers in project)
- -time-tolerance <timeTol> - The time tolerance to use when checking workers locations. This value is used to provide a range around the time when the assignment was completed (optional - defaults to 5 minutes)
- -distance-tolerance <distTol> - The distance tolerance to use when checking if a worker completed the assignment at the assignment location (optional - defaults to 100 (m)) The units are whatever the assignments feature layer uses which by default is meters.
- -min-accuracy <minAccuracy> - The minimum accuracy required when querying worker locations (optional - defaults to 50 (m))
Example Usage:
python check_completion_location.py -config-file "../sample_data/fieldMappings.json" -u username -p password -org "https://<org>.maps.arcgis.com" -target-fl "http://services.arcgis.com/<server>/arcgis/rest/services/AssignmentsArchives/FeatureServer/0" -where "1=1" -pid "e2293b52beef439ca475427287969466" -log-file "log.txt" -workers worker_1 -time-tolerance 5 -distance-tolerance 100 -min-accuracy 25
- First the script uses the provided credentials to authenticate with AGOL to get the requried token
- Then the assignment feature layer is fetched
- Next the target feature layer is fetched
- Then the JSON configuration file is opened
- Then the worker and location feature layers are fetched
- For each worker
- Get the id of the worker
- The assignments are queried by the workers name/id
- Then the workers location is queried based on the assignment completion date +- timeTol
- The distance between the workers locations and the assignment are found (including the accuracy) and compared to distTol
- If none of the distances are smaller than distTol, then the current assignment is marked as invalid
- The OBJECTIDS of all invalid assignments are used to create a query
- The query is used to copy assignments to a different feature service (if they don't already exists there)