# DIAGNOSTIC SCRIPT FOR LANE DETAILS
# This will help identify which field is causing the problem

# Get the data
results = self.parent.getChild("Statistics").getChild("Lane Details").getChild("Lane Details").props.filter.results.data

if len(results) > 0:
	# Print all available field names from the first result
	first_result = results[0]
	field_names = list(first_result.keys())
	
	print("="*50)
	print("AVAILABLE FIELDS IN LANE DETAILS:")
	print("="*50)
	for field in sorted(field_names):
		print(f"  {field}")
	print("="*50)
	
	# Try to access each field individually for Count mode
	print("\nTEST COUNT MODE FIELDS:")
	print("-"*50)
	test_fields = [
		'Startstamp', 'Endtstamp', 'SorterName', 'Lane',
		'Total_count', 'Diverted_count', 'DestFull_count', 
		'DestJam_count', 'DestDis_count', 'DestFault_count',
		'DivertFail_count', 'Lost_count', 'Unsafe_count',
		'Dim_count', 'GapErr_count', 'Unknown_count'
	]
	
	for field in test_fields:
		try:
			value = first_result[field]
			print(f"  ✓ {field}: {value}")
		except KeyError:
			print(f"  ✗ {field}: MISSING!")
	
	print("\nTEST PERCENTAGE MODE FIELDS:")
	print("-"*50)
	perc_fields = [
		'total_perc', 'Diverted_perc', 'destfull_perc',
		'destjam_perc', 'destdisabled_perc', 'destfault_perc',
		'DivertFail_perc', 'lost_perc', 'unsafe_perc',
		'dim_perc', 'gaperr_perc', 'unknown_perc'
	]
	
	for field in perc_fields:
		try:
			value = first_result[field]
			print(f"  ✓ {field}: {value}")
		except KeyError:
			print(f"  ✗ {field}: MISSING!")
else:
	print("No filtered results found. Checking props.data instead...")
	test_table = system.dataset.toPyDataSet(self.parent.getChild("Statistics").getChild("Lane Details").getChild("Lane Details").props.data)
	if len(test_table) > 0:
		first_row = test_table[0]
		field_names = list(first_row.keys())
		
		print("="*50)
		print("AVAILABLE FIELDS IN props.data:")
		print("="*50)
		for field in sorted(field_names):
			print(f"  {field}")
		print("="*50)

