def onTagChange(initialChange, newValue, previousValue, event, executionCount):
	# ============================================================================
	# Gateway Tag Change Script - Induction Statistics
	# Triggers on: Induction_X/* tags (diTotal_* statistics)
	# Logic:
	#   - Only act when:
	#       * not initialChange
	#       * quality is good
	#       * quality transition from bad to good is ignored
	#   - Then:
	#       * Read induction name
	#       * INSERT into induction_data with appropriate column
	# ============================================================================
	
	DB_NAME = "MariaDB"
	import system
	
	# ============================================================================
	# ENTRY BLOCK – runs on every configured tag change
	# Objects: event, initialChange, currentValue, previousValue, executionCount
	# ============================================================================
	
	tagPath = str(event.getTagPath())
	
	# Extract tag name from path (e.g., "diTotal_Double_Carrier" from full path)
	tagName = tagPath.split("/")[-1]
	
	# Handle diTotal_Double_Carrier
	if tagName == "diTotal_Double_Carrier":
	    if not (initialChange or not currentValue.quality.isGood() or (not previousValue.quality.isGood() and currentValue.quality.isGood())):
	        try:
	            parentPath = "/".join(tagPath.split("/")[:-1])
	            namePath = parentPath + "/sInduction_Name"
	            name = system.tag.readBlocking([namePath])[0].value
            
	            system.db.runPrepUpdate("""
	                INSERT INTO induction_data (t_stamp, sInduction_Name, diTotal_Double_Carrier)
	                VALUES (NOW(), ?, 1)
	            """, [name], DB_NAME)
	        except Exception as e:
	            system.util.getLogger("InductionStatistics").error("double_carrier: %s" % e)
	
	# Handle diTotal_Single_Carrier
	if tagName == "diTotal_Single_Carrier":
	    if not (initialChange or not currentValue.quality.isGood() or (not previousValue.quality.isGood() and currentValue.quality.isGood())):
	        try:
	            parentPath = "/".join(tagPath.split("/")[:-1])
	            namePath = parentPath + "/sInduction_Name"
	            name = system.tag.readBlocking([namePath])[0].value
            
	            system.db.runPrepUpdate("""
	                INSERT INTO induction_data (t_stamp, sInduction_Name, diTotal_Single_Carrier)
	                VALUES (NOW(), ?, 1)
	            """, [name], DB_NAME)
	        except Exception as e:
	            system.util.getLogger("InductionStatistics").error("single_carrier: %s" % e)
	
	