55
66
77def create_fit_id_df () -> pd .DataFrame :
8+ """
9+ The first step here is to get the relevant test data for compartment 2
10+ Then it calculates the check digit for each kit id retrieved
11+ Finally it adds the final part on the end (expiry date + random characters)
12+ """
813 df = get_kit_id_from_db ()
914 df ["fit_device_id" ] = df ["kitid" ].apply (calculate_check_digit )
1015 df ["fit_device_id" ] = df ["fit_device_id" ].apply (convert_kit_id_to_fit_device_id )
1116 return df
1217
1318def calculate_check_digit (kit_id : str ) -> str :
19+ """
20+ This function used used to calculate the check digit of a kit ID
21+ It calculates the check digit by getting the sum of the location of each character in the kit id
22+ Then it divides the sum by 43 and gets the remainder from this
23+ It then searches the string "char_string" to find the index of the remainder
24+ The character found is then the check digit
25+ """
1426 logging .info (f"Calculating check digit for kit id: { kit_id } " )
1527 total = 0
1628 char_string = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%"
@@ -20,6 +32,12 @@ def calculate_check_digit(kit_id: str) -> str:
2032 return f"{ kit_id } -{ check_digit } "
2133
2234def convert_kit_id_to_fit_device_id (kit_id : str ) -> str :
35+ """
36+ This is used to add the expiry date to the end of the Kit ID
37+ This by setting the month to december
38+ And the year is set to 1 year in the future.
39+ E.g. if the current date is 06/24 the expiry date will be set to 12/25
40+ """
2341 logging .info (f"Generating FIT Device ID from: { kit_id } " )
2442 today = datetime .now ()
2543 year = today .strftime ("%y" ) # Get the year from todays date in YY format
0 commit comments