diff --git a/team-CHIMPLE/tablet-tracker/extract_serial_numbers_not_found_in_tablet_tracker.py b/team-CHIMPLE/tablet-tracker/extract_serial_numbers_not_found_in_tablet_tracker.py new file mode 100644 index 00000000..75c53e0c --- /dev/null +++ b/team-CHIMPLE/tablet-tracker/extract_serial_numbers_not_found_in_tablet_tracker.py @@ -0,0 +1,90 @@ +# Extracts serial numbers found in tablet usage data, but not in tablet tracker. +# +# Usage: +# cd tablet-tracker +# python3 extract_serial_numbers_not_found_in_tablet_tracker.py +# +# The resulting list of missing serial numbers will be stored in a file named `serial-numbers-not-found-in-tablet-tracker.csv`. + +import csv +import logging + +logging.basicConfig(format='%(levelname)s | %(asctime)s | %(message)s', level=logging.DEBUG) + + +# Extract serial numbers from tablet tracker, and add them to an array +serial_numbers_in_tablet_tracker = [] +with open('tablet-tracker-CHIMPLE.csv') as in_file: + csv_data = csv.reader(in_file) + row_count = 0 + for csv_row in csv_data: + row_count += 1 + if row_count == 1: + # Skip header row + continue + + logging.debug("csv_row: {}".format(csv_row)) + + # Iterate serial columns ("Serial #1" --> "Serial #14") + removal_count = 1 + column_index = 2 + while removal_count <= 14: + serial_number = csv_row[column_index] + logging.debug("Serial #{0}: {1}".format(removal_count, serial_number)) + + if (serial_number != "") and (serial_number not in serial_numbers_in_tablet_tracker): + serial_numbers_in_tablet_tracker.append(serial_number) + + removal_count += 1 + if removal_count == 2: + column_index += 1 + else: + column_index += 2 +logging.debug("serial_numbers_in_tablet_tracker: {}".format(serial_numbers_in_tablet_tracker)) +logging.debug("len(serial_numbers_in_tablet_tracker): {}".format(len(serial_numbers_in_tablet_tracker))) + + +# Iterate the serial numbers in `tablets-uploading-data-CHIMPLE.csv` +with open('../tablets-uploading-data/tablets-uploading-data-CHIMPLE.csv') as in_file: + serial_numbers_not_found_in_tablet_tracker = [] + + csv_data = csv.reader(in_file) + row_count = 0 + for csv_row in csv_data: + row_count += 1 + if row_count == 1: + # Skip header row + continue + + logging.debug("csv_row: {}".format(csv_row)) + + tablet_serials = csv_row[4] + logging.debug("tablet_serials: {}".format(tablet_serials)) + + # Convert string to array. E.g. "['5B12002947', '6111002083', '6116000839', '6116001775', '6116002363', '6130000141']" + tablets_serials_as_array = eval(tablet_serials) + logging.debug("tablets_serials_as_array: {}".format(tablets_serials_as_array)) + logging.debug("len(tablets_serials_as_array): {}".format(len(tablets_serials_as_array))) + + # Iterate each serial number and check if it can be found in the tablet tracker + for tablet_serial in tablets_serials_as_array: + logging.debug("tablet_serial: {}".format(tablet_serial)) + + if tablet_serial not in serial_numbers_in_tablet_tracker: + logging.warning("tablet_serial not found in tablet tracker: {}".format(tablet_serial)) + if tablet_serial not in serial_numbers_not_found_in_tablet_tracker: + serial_numbers_not_found_in_tablet_tracker.append(tablet_serial) + + logging.debug("serial_numbers_not_found_in_tablet_tracker: {}".format(serial_numbers_not_found_in_tablet_tracker)) + logging.debug("len(serial_numbers_not_found_in_tablet_tracker): {}".format(len(serial_numbers_not_found_in_tablet_tracker))) + + # Write results to a CSV file + csv_filename = "serial-numbers-not-found-in-tablet-tracker.csv" + print("Writing list of missing tablet serials to the file \"" + csv_filename + "\"") + with open(csv_filename, mode='w') as csv_file: + csv_fieldnames = ['serial_number'] + csv_writer = csv.writer(csv_file, csv_fieldnames) + csv_writer.writerow(csv_fieldnames) + for serial_number in serial_numbers_not_found_in_tablet_tracker: + serial_number_as_list = [serial_number] + csv_writer.writerow(serial_number_as_list) diff --git a/team-CHIMPLE/tablet-tracker/serial-numbers-not-found-in-tablet-tracker.csv b/team-CHIMPLE/tablet-tracker/serial-numbers-not-found-in-tablet-tracker.csv new file mode 100644 index 00000000..750779ee --- /dev/null +++ b/team-CHIMPLE/tablet-tracker/serial-numbers-not-found-in-tablet-tracker.csv @@ -0,0 +1,82 @@ +serial_number +6116001019 +6116001847 +6116002599 +5A27001337 +6130000243 +5A29001450 +6113000008 +6115001201 +5A28002591 +5A27001419 +5B13001505 +5A27001395 +5A28000347 +6116002187 +6118001508 +5A27001796 +6116000842 +6116001375 +5A27001765 +6113000238 +5A28000969 +5A28002064 +5B13001085 +5A27000657 +6118002643 +6126000507 +5B13001232 +5A28000332 +6111001893 +6113000738 +6115002391 +5B20002011 +5A27000801 +6116002671 +6118002959 +5B20002263 +6118003009 +5A27000478 +6118003199 +5A28000685 +6111001783 +6115000561 +5B20001369 +6116001278 +6116001657 +6118003298 +6118002996 +5A27000554 +5A28000182 +5A27001530 +5A27002080 +5A28001170 +6129001664 +5B20002005 +6116002596 +5B20001217 +6109000540 +6111001716 +6115000386 +5A27001825 +6116001126 +5A27001483 +6111001762 +6118002946 +6111001096 +6113001068 +6116000778 +6116000805 +6118002285 +6116002652 +6116002079 +5A29000767 +5B12003436 +6112001529 +6116002824 +5A27002171 +5A28001033 +6116002209 +6118002898 +5A27000459 +5A27001891