Select to view content in your preferred language

Estimate Credit Functionality in arcpy

924
6
05-01-2023 05:39 AM
Status: Open
Labels (1)
Eric_Castonguay
New Contributor III

The estimate credit requirement that has been added in 3.1.x is preventing my scripts from running since it requires the user to manually click the button in the geoprocessing pane.  

Can we get this functionality in arcpy.  I really like the ability to estimate credits, but I would like the ability to allow bypass for certain users or to auto accept if under a certain threshold.

For example:  I run a weekly change detection script to update attributes which includes geocoding new/changed addresses.  The number of addresses varies from 0-30 on a weekly basis with an average of ~5.  I currently have to manually run the geocode script in the middle of my script.  I would like the ability to bypass and/or auto accept the estimated credits if under 40 (would be for the 40 credits/1000 addresses).  This would allow my script to run smoothly, but still throw an error if the source table somehow gets too many records added.

6 Comments
DannyMcVey

Hi Eric,

What is preventing your scripts from running? Unless I'm misunderstanding, running the tools from python already serves as a way to "bypass" the credit estimation requirement. 

We currently don't offer a way to estimate credit usage for custom scripts. It is pretty complicated to account for custom python logic that would change the credit spend. But you could add logic to your script to stop the tool from running based on the number of features involved. 

    def updateMessages(self):
        self.params[0].clearMessage()

        # get the count of the in_features 
        feature_count = int(arcpy.management.GetCount(self.params[0].value).getOutput(0))
        
        # do some math
            # 10 credits per 1,000 attributes (data variables multiplied by total feature records)
            # only one data variable is being used in this example
            # https://doc.arcgis.com/en/arcgis-online/analyze/credits-analysis-mv.htm
        enrich_cost = 10/1000*feature_count
        
        # compare the results
        if enrich_cost > 0.02:
            self.params[0].setErrorMessage(f"hey, easy big spender... that'll cost us {enrich_cost} credits" )
        else:
            self.params[0].setWarningMessage(f"alright fine go ahead, spend {enrich_cost} credits" )

        return

this kind of validation stops the tool from running (or allows it to run) like this:

DannyMcVey_0-1683055130281.png

 

DrewFlater
Status changed to: Needs Clarification
 
Eric_Castonguay

Hi Danny,

My current change detection script that I run in a notebook now fails at the geocode step  (arcpy.geocoding.GeocodeAddresses) after updating to 3.1.1.

When I open the failed tool from the geoprocessing history and try to run it manually I get the following error:

Eric_Castonguay_0-1683056955766.png

Once I click the estimate credits link at the top of the Geocode Addresses tool in the geoprocessing pane I am able to run the tool then proceed with the script.

DannyMcVey

That message should only appear in the geoprocessing pane. What error is your notebook failing with?

Eric_Castonguay

I have a better explanation of the error in a cross post in ArcGIS Pro Questions:

https://community.esri.com/t5/arcgis-pro-questions/estimate-credits-before-running-this-tool-python/...

I am getting the Error 000005: Could not open the address locator.  When I open the failed tool in the geoprocessing history I only have to click the estimate credits link for the tool to run.

HannesZiegler
Status changed to: Open

I am returning this idea back to an open state.