diff --git a/util/picklist_to_locations.py b/util/picklist_to_locations.py index fd5455d..c30b515 100644 --- a/util/picklist_to_locations.py +++ b/util/picklist_to_locations.py @@ -1,6 +1,6 @@ import json -from sys import argv -from os import path, kill +from sys import argv, exit +from os import path from dataclasses import dataclass @@ -13,45 +13,53 @@ class Location: def main(): input_file = argv[1] output_file = argv[2] + alternate_mode = len(argv) == 4 and argv[3] == "alt" if not test_file(input_file): print("Input file does not exist") - kill(1) + exit(1) if test_file(output_file): print("Output file already exists") - kill(1) + exit(1) locations = read_input_csv_to_wells(input_file) json_obj = tubes_to_tubes_json(locations) + if alternate_mode: + with open(output_file, 'w') as file: + for location in locations: + index = (location.row - 1) * 12 + location.col + file.write(f"{index}\n") + exit(0) + with open(output_file, 'w') as file: json.dump(json_obj, file) def read_input_csv_to_wells(p: str) -> [Location]: with open(p, 'r') as file: - lines = file.readlines() + lines=file.readlines() # Assume 96w format only def get_first_col(line): return line.split(',')[0] def get_row(x): return ord(x.upper()) - 64 def get_row_col(line: str) -> Location: - col = get_first_col(line)[1:] - row = get_row(get_first_col(line)[0]) + col=get_first_col(line)[1:] + row=get_row(get_first_col(line)[0]) return Location(row, int(col)) return list(set([get_row_col(line) for line in lines[1:]])) def tubes_to_tubes_json(i: [Location]) -> dict: - target_positions_list = [] + target_positions_list=[] for tube in i: target_positions_list.append((tube.row - 1) * 12 + tube.col) - output_obj = {} - output_obj["TargetPositions"] = [{"PositionIndex": p} + output_obj={} + output_obj["TargetPositions"]=[{"PositionIndex": p} for p in target_positions_list] return output_obj diff --git a/verso_spelling/letters.zip b/verso_spelling/letters.zip new file mode 100644 index 0000000..97b073f Binary files /dev/null and b/verso_spelling/letters.zip differ diff --git a/verso_spelling/letters/E b/verso_spelling/letters/E new file mode 100644 index 0000000..ad1be0c --- /dev/null +++ b/verso_spelling/letters/E @@ -0,0 +1,60 @@ +72 +25 +31 +42 +48 +49 +55 +87 +93 +90 +14 +96 +6 +23 +12 +62 +76 +73 +79 +71 +82 +38 +54 +30 +36 +86 +47 +60 +95 +89 +92 +2 +13 +19 +11 +61 +75 +81 +67 +78 +84 +26 +37 +43 +50 +35 +59 +88 +85 +91 +1 +94 +7 +18 +24 +74 +66 +77 +83 +80 diff --git a/verso_spelling/letters/H b/verso_spelling/letters/H new file mode 100644 index 0000000..0249eac --- /dev/null +++ b/verso_spelling/letters/H @@ -0,0 +1,56 @@ +31 +42 +55 +87 +93 +90 +14 +96 +6 +17 +3 +9 +23 +20 +12 +76 +73 +79 +82 +54 +30 +86 +89 +95 +92 +16 +2 +13 +19 +5 +11 +22 +8 +75 +81 +67 +78 +84 +43 +88 +85 +91 +1 +94 +4 +15 +21 +7 +18 +24 +10 +74 +66 +77 +83 +80 diff --git a/verso_spelling/letters/O b/verso_spelling/letters/O new file mode 100644 index 0000000..8887fda --- /dev/null +++ b/verso_spelling/letters/O @@ -0,0 +1,64 @@ +72 +25 +48 +49 +87 +93 +90 +14 +96 +6 +17 +3 +9 +23 +20 +12 +62 +76 +73 +79 +71 +82 +38 +36 +86 +47 +60 +95 +89 +92 +16 +2 +13 +19 +5 +11 +61 +22 +8 +75 +81 +78 +84 +26 +37 +50 +35 +59 +88 +85 +91 +1 +94 +4 +15 +21 +7 +18 +24 +74 +10 +77 +83 +80 diff --git a/verso_spelling/letters/R b/verso_spelling/letters/R new file mode 100644 index 0000000..183fb9e --- /dev/null +++ b/verso_spelling/letters/R @@ -0,0 +1,60 @@ +25 +31 +42 +49 +34 +87 +93 +90 +96 +14 +3 +23 +20 +76 +62 +73 +79 +65 +82 +38 +41 +33 +54 +30 +36 +86 +89 +95 +92 +16 +2 +13 +19 +61 +22 +75 +81 +78 +84 +26 +37 +29 +50 +35 +32 +53 +88 +85 +91 +1 +94 +4 +15 +21 +24 +74 +66 +77 +83 +80 diff --git a/verso_spelling/letters/S b/verso_spelling/letters/S new file mode 100644 index 0000000..6e682cb --- /dev/null +++ b/verso_spelling/letters/S @@ -0,0 +1,60 @@ +72 +25 +31 +42 +48 +49 +55 +87 +90 +14 +96 +6 +23 +9 +20 +12 +62 +76 +73 +79 +71 +38 +54 +30 +36 +86 +47 +60 +95 +89 +2 +13 +19 +11 +61 +22 +8 +75 +67 +78 +84 +26 +37 +43 +50 +35 +59 +88 +85 +91 +1 +21 +7 +18 +24 +74 +10 +66 +77 +83 diff --git a/verso_spelling/spell.py b/verso_spelling/spell.py new file mode 100644 index 0000000..aad85b9 --- /dev/null +++ b/verso_spelling/spell.py @@ -0,0 +1,98 @@ +import json +from sys import argv +from os import path, listdir +from dataclasses import dataclass + + +@dataclass(frozen=True) +class Tube: + barcode: str + row: int + col: int + + +@dataclass(frozen=True) +class LetterTube: + barcode: str + index: int + group: int + + +def main(): + # ARGV[1] Should be path to Ziath Output + # ARGV[2] Should be path to Letter sequences + # ARGV[3] Should be path to output + # ARGV[4] Should be word + + available_barcodes = argv[1] + letter_dir = argv[2] + output_path = argv[3] + input = argv[4] + + if not validate_word(input, letter_dir): + print("Failed to validate word") + exit(1) + + available_tubes = read_available(available_barcodes) + letters = [] + for letter in input: + x = get_tubes_for_letter(letter, + len(letters) + 1, + available_tubes, + letter_dir) + available_tubes = available_tubes[len(x):] + letters += x + + output = letter_tubes_to_obj(letters) + with open(output_path, 'w') as file: + json.dump(output, file) + + +def letter_tubes_to_obj(x: [LetterTube]) -> dict: + output = {} + output["Items"] = [{"BarcodeValue": y.barcode} for y in x] + output["TargetPositions"] = [{"PositionIndex": y.index, + "GroupIndex": y.group} + for y in x] + + return output + + +def get_tubes_for_letter(letter: str, + letter_index: int, + available_tubes: [Tube], + letter_dir: str) -> [LetterTube]: + positions = get_letter_positions(letter, letter_dir) + + if len(positions) > len(available_tubes): + raise Exception("Insufficient tubes to fill order") + + pixels = [] + for i, position in enumerate(positions): + pixel = LetterTube(available_tubes[i], + position, + letter_index) + pixels.append(pixel) + return pixels + + +def read_available(p: str) -> [str]: + with open(p, 'r') as file: + return [x.strip() for x in file.readlines()] + + +def validate_word(input: str, letter_dir: str) -> bool: + letters_available = [x[0] for x in listdir(letter_dir)] + has_required_letters = all([x in letters_available for x in input]) + + return has_required_letters + + +def get_letter_positions(letter: str, letter_dir: str) -> [int]: + filename = [f for f in listdir(letter_dir) if f[0] == letter][0] + with open(path.join(letter_dir, filename), 'r') as file: + return [int(x.strip()) for x in file.readlines()] + + +if __name__ == "__main__": + main() diff --git a/verso_spelling/spell.txt b/verso_spelling/spell.txt new file mode 100644 index 0000000..aad85b9 --- /dev/null +++ b/verso_spelling/spell.txt @@ -0,0 +1,98 @@ +import json +from sys import argv +from os import path, listdir +from dataclasses import dataclass + + +@dataclass(frozen=True) +class Tube: + barcode: str + row: int + col: int + + +@dataclass(frozen=True) +class LetterTube: + barcode: str + index: int + group: int + + +def main(): + # ARGV[1] Should be path to Ziath Output + # ARGV[2] Should be path to Letter sequences + # ARGV[3] Should be path to output + # ARGV[4] Should be word + + available_barcodes = argv[1] + letter_dir = argv[2] + output_path = argv[3] + input = argv[4] + + if not validate_word(input, letter_dir): + print("Failed to validate word") + exit(1) + + available_tubes = read_available(available_barcodes) + letters = [] + for letter in input: + x = get_tubes_for_letter(letter, + len(letters) + 1, + available_tubes, + letter_dir) + available_tubes = available_tubes[len(x):] + letters += x + + output = letter_tubes_to_obj(letters) + with open(output_path, 'w') as file: + json.dump(output, file) + + +def letter_tubes_to_obj(x: [LetterTube]) -> dict: + output = {} + output["Items"] = [{"BarcodeValue": y.barcode} for y in x] + output["TargetPositions"] = [{"PositionIndex": y.index, + "GroupIndex": y.group} + for y in x] + + return output + + +def get_tubes_for_letter(letter: str, + letter_index: int, + available_tubes: [Tube], + letter_dir: str) -> [LetterTube]: + positions = get_letter_positions(letter, letter_dir) + + if len(positions) > len(available_tubes): + raise Exception("Insufficient tubes to fill order") + + pixels = [] + for i, position in enumerate(positions): + pixel = LetterTube(available_tubes[i], + position, + letter_index) + pixels.append(pixel) + return pixels + + +def read_available(p: str) -> [str]: + with open(p, 'r') as file: + return [x.strip() for x in file.readlines()] + + +def validate_word(input: str, letter_dir: str) -> bool: + letters_available = [x[0] for x in listdir(letter_dir)] + has_required_letters = all([x in letters_available for x in input]) + + return has_required_letters + + +def get_letter_positions(letter: str, letter_dir: str) -> [int]: + filename = [f for f in listdir(letter_dir) if f[0] == letter][0] + with open(path.join(letter_dir, filename), 'r') as file: + return [int(x.strip()) for x in file.readlines()] + + +if __name__ == "__main__": + main()