I have tables in ArcGIS containing rows for items that have fields for "Score" and "Category". I am attempting to write a function that adds the total score from the "Score" field for all rows, but takes user-provided variables for the maximum contribution limits per category.
So the function needs to check each row for what "Category" it belongs to, check if the "Category" is maxed out, and if not maxed out, add the "Score" value to the Total Score Value.
This part would be simple, but the more difficult part for me is that the categories are not standardized... so each time the function is run, it would need to read all possible field values within "Categories" in the input table, read the user-input for the category limits, and limit the score contribution of each category as each row is tallied up.
This is what I have so far...
# Set Total Score Variable
totalScore = 0
# Read table "Category" field for possible categories
categories = [row[0] for row in arcpy.da.SearchCursor("Input_Table", "CategoryID")]
uniqueCategories = set(categories)
print(uniqueCategories)
print "Found " + len(uniqueCategories) + "unique categories in table."
# TODO: Read user input to designate category limits somehow...
category_A =
category_B =
category_C =
category_A_Limit =
category_B_Limit =
category_C_Limit =
with arcpy.da.SearchCursor("Input_Table", ["CategoryID", "Score"]) as cursor:
for row in cursor:
if row[0] == category_X:
if row[0] < category_X_Limit:
# Read the Score Field for that row
totalScore += row[1]
else:
print "Category "+str(row[0])+" maxed out. This item's score cannot contribute to the total."
There must be much more elegant ways to handle this... perhaps a specific module that someone knows about? Any assistance would be EXTREMELY appreciated!
I have read arcGIS documentation and found out some ways to do so:
Execute SQL statement which explains here:
arcpy.da.SearchCursor("Input_Table", "CategoryID"), sql_clause=(None, "GROUP BY Input_Table, CategoryID")]. It shoud sum. values.
http://resources.arcgis.com/en/help/main/10.1/index.html#/SearchCursor/018v00000050000000/ http://resources.arcgis.com/en/help/main/10.1/index.html#//018w00000011000000
Explanations here https://gis.stackexchange.com/a/73300
Hope this help. Next time, please leave your question on this section https://gis.stackexchange.com/