From bcefb72a2d6539d5319da1652819216b57aa9fc2 Mon Sep 17 00:00:00 2001 From: Emilia Allison Date: Thu, 24 Oct 2024 13:40:13 -0500 Subject: [PATCH] Spelling --- util/picklist_to_locations.py | 28 ++++++---- verso_spelling/letters.zip | Bin 0 -> 1505 bytes verso_spelling/letters/E | 60 +++++++++++++++++++++ verso_spelling/letters/H | 56 +++++++++++++++++++ verso_spelling/letters/O | 64 ++++++++++++++++++++++ verso_spelling/letters/R | 60 +++++++++++++++++++++ verso_spelling/letters/S | 60 +++++++++++++++++++++ verso_spelling/spell.py | 98 ++++++++++++++++++++++++++++++++++ verso_spelling/spell.txt | 98 ++++++++++++++++++++++++++++++++++ 9 files changed, 514 insertions(+), 10 deletions(-) create mode 100644 verso_spelling/letters.zip create mode 100644 verso_spelling/letters/E create mode 100644 verso_spelling/letters/H create mode 100644 verso_spelling/letters/O create mode 100644 verso_spelling/letters/R create mode 100644 verso_spelling/letters/S create mode 100644 verso_spelling/spell.py create mode 100644 verso_spelling/spell.txt 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 0000000000000000000000000000000000000000..97b073fd1f04bf891ba30ecdf6464020a1a8c97e GIT binary patch literal 1505 zcmWIWW@Zs#0D&{TVUb`4l;B`cV8}@=DM>9V)(;KgWnedul}I-MVh~+g!Og(P0#XSk z0>GwlFmNy&K{91KP?{6T6o0TW3PA0)<`U^38qFBq-jkdR20VxV&01zT_s#x@&xRfx zI>)ho=L6oUA*&N9C1!+s;mj{X6J|%I`%Oh=q`}k5UxIk(HwDjN@_s!c92KFn1Gb~5`) zmhu>&qd*QrI2k#*(4FiGk1t0>tnmd5Xqb~NJ-@}Tscf8(^Q1!1&C2pg(9sUwZ;2<( zdfA_CS?ty*Ci(bCfTzu(nQE@~-&ju1ld#S+T+Dm7#uXgUl2K0c6L%MUrLH)`5 zf(;Ma*nxuCJH%^JEQXs8A_en&v|#oCyIBetynaA8gJ_Ik-pR}0$iwt`<+BZY>we|G z@eo)bxMalx+p--`>_TELXB4PSDvvvfN9+Fe*qSA=~rI4w4H zO>d>*Io7Hci7hRckBhuroXA`M2jp1Jlj`1KK<9v*gb3ghNRC~H=Gb7cV>N+}v;(GO z5RK_rK?Vbk!&Sb*afknPw_dV(2~5Zamrg29*K&Jvcv7wuzu5k_kN`Fe5$exa=6SJy z@4p(I4M%&-?ns7gxnR&~u4uHPyF2Px#l~Yd+cq2&R{i$kw}>z}NhBMc(~SnY3FNK- zZ$>5&X54ugs00lDJAx?Ub2P+MSe{1CH=sNX1KS$ikW3|*!(omE84JpE$Y~qZ*gr_d z63l|g#)2{ia`Hnpc0D5^3 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()