import arcpy
import os

# Placeholder for the directory path where prompt_1_data_subset is located
input_shapefile_path = r'C:\Users\BrianT\RIT\TEACHING\IGME_386_C_drive\Week_12_SDS_Predictive_Models\prompts\data_output\prompt_1_data_subset.shp'
output_directory = r'C:\temp'
output_shapefile_name = 'prompt_3_hotspots.shp'
output_shapefile_path = os.path.join(output_directory, output_shapefile_name)

try:
    print("Starting the Hot Spot Analysis (Getis-Ord Gi*) script...")

    # Step 1: Check if input shapefile exists
    if not arcpy.Exists(input_shapefile_path):
        raise FileNotFoundError(f"The input shapefile {input_shapefile_path} was not found. Please check the file path.")

    # Step 2: Set parameters for the Hot Spot Analysis (Getis-Ord Gi*)
    input_feature_class = input_shapefile_path           # Input shapefile for analysis
    input_field = "Vol"                                  # Field to analyze
    output_feature_class = output_shapefile_path         # Path for output shapefile
    spatial_relationship = "FIXED_DISTANCE_BAND"         # Spatial relationship type
    distance_band = 4584.50                              # Distance band or threshold distance
    distance_method = "MANHATTAN_DISTANCE"               # Distance calculation method

    print("Running the Hot Spot Analysis (Getis-Ord Gi*)...")

    # Step 3: Run Hot Spot Analysis (Getis-Ord Gi*) with specified parameters
    arcpy.stats.HotSpots(
        Input_Feature_Class=input_feature_class,
        Input_Field=input_field,
        Output_Feature_Class=output_feature_class,
        Conceptualization_of_Spatial_Relationships=spatial_relationship,
        Distance_Band_or_Threshold_Distance=distance_band,
        Distance_Method=distance_method
    )

    print(f"Hot Spot Analysis completed successfully. Output saved at: {output_shapefile_path}")

except FileNotFoundError as fnf_error:
    print(f"Error: {fnf_error}")
except arcpy.ExecuteError:
    # ArcPy-specific errors
    print("ArcPy error occurred during Hot Spot Analysis:")
    print(arcpy.GetMessages(2))  # Prints detailed ArcPy error messages
except Exception as e:
    # Generic error handling for any other exceptions
    print(f"An unexpected error occurred: {e}")

print("Hot Spot Analysis script completed.")
