dev mod 43

This commit is contained in:
Eduardo 2025-07-23 14:07:01 +02:00
parent bdb373852b
commit 150d4f8fc2

View File

@ -841,6 +841,13 @@ class Test(Widget):
# LABEL PRINT
recipe = archived.test_data.get("recipe", {})
# Define barcode format variables
part_number = recipe.get("part_number", "-")
self.barcode_prefix = f"#{part_number} ###*1IT ECE"
self.module_data_format = f"1IT ECE{archived.id:0>7}"
self.barcode_suffix = "*="
self.barcode_format = self.print_step.spec.get("barcode")
leak_test_1 = archived.test_data.get("leak_1", {})
leak_test_1_step = leak_test_1.get("step", {})
leak_test_1_step_spec = leak_test_1_step.get("spec", {})
@ -944,10 +951,19 @@ class Test(Widget):
#TESTING BROTHER
label_brother = context.get("RECIPE_TO_PRINT", "-") + context.get("DD","-") + context.get("MO","-") + context.get("YY","-") + context.get("SN5","-")
barcode = str(label_brother)
barcode_format = self.print_step.spec.get("barcode", "-")
self.printed_barcode = barcode_format.format_map(context)
formatted_barcode = barcode_format.format(**context)
formatted_module_data = self.module_data_format.format(**context)
check = self.calculate_modulo43_checksum(formatted_module_data)
context.update(
{
"barcode_prefix": self.barcode_prefix,
"check": check,
"barcode_suffix": self.barcode_suffix,
}
)
formatted_barcode = self.barcode_format.format(**context)
context['BCODE'] = formatted_barcode
self.printed_barcode = formatted_barcode
if self.archived is not None:
self.archived.barcode = self.printed_barcode
@ -1099,3 +1115,47 @@ class Test(Widget):
self.flag_label.setVisible(True) # Ensure the label is visible
else: # No args provided
self.flag_label.setVisible(False) # Hide label
def calculate_modulo43_checksum(self,data_sequence: str) -> str:
"""
Calculates the Modulo 43 checksum for a given data sequence.
The function determines the checksum value for each character based on a
predefined assignment table, calculates the total sum of these values,
and then finds the remainder of the division by 43. The character
corresponding to this remainder is the check digit.
Args:
data_sequence: The input string for which to calculate the checksum.
Returns:
The Modulo 43 check digit as a single character.
Raises:
ValueError: If the data_sequence contains a character not found in the
assignment table.
"""
assignment_table = {
'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9,
'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15, 'G': 16, 'H': 17, 'I': 18,
'J': 19, 'K': 20, 'L': 21, 'M': 22, 'N': 23, 'O': 24, 'P': 25, 'Q': 26, 'R': 27,
'S': 28, 'T': 29, 'U': 30, 'V': 31, 'W': 32, 'X': 33, 'Y': 34, 'Z': 35,
'-': 36, '.': 37, ' ': 38, '$': 39, '/': 40, '+': 41, '%': 42
}
total_sum = 0
for char in data_sequence:
if char in assignment_table:
total_sum += assignment_table[char]
else:
raise ValueError(f"Character '{char}' is not valid for checksum calculation.")
remainder = total_sum % 43
# Invert the assignment_table to map the remainder back to the character
for char, value in assignment_table.items():
if value == remainder:
return char
# This part of the code should be unreachable given the logic
return "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"