This commit is contained in:
Emilia Allison 2024-10-24 13:40:13 -05:00
parent 63925ec0ba
commit bcefb72a2d
Signed by: emilia
GPG Key ID: 05D5D1107E5100A1
9 changed files with 514 additions and 10 deletions

View File

@ -1,6 +1,6 @@
import json import json
from sys import argv from sys import argv, exit
from os import path, kill from os import path
from dataclasses import dataclass from dataclasses import dataclass
@ -13,17 +13,25 @@ class Location:
def main(): def main():
input_file = argv[1] input_file = argv[1]
output_file = argv[2] output_file = argv[2]
alternate_mode = len(argv) == 4 and argv[3] == "alt"
if not test_file(input_file): if not test_file(input_file):
print("Input file does not exist") print("Input file does not exist")
kill(1) exit(1)
if test_file(output_file): if test_file(output_file):
print("Output file already exists") print("Output file already exists")
kill(1) exit(1)
locations = read_input_csv_to_wells(input_file) locations = read_input_csv_to_wells(input_file)
json_obj = tubes_to_tubes_json(locations) 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: with open(output_file, 'w') as file:
json.dump(json_obj, file) json.dump(json_obj, file)

BIN
verso_spelling/letters.zip Normal file

Binary file not shown.

60
verso_spelling/letters/E Normal file
View File

@ -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

56
verso_spelling/letters/H Normal file
View File

@ -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

64
verso_spelling/letters/O Normal file
View File

@ -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

60
verso_spelling/letters/R Normal file
View File

@ -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

60
verso_spelling/letters/S Normal file
View File

@ -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

98
verso_spelling/spell.py Normal file
View File

@ -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()

98
verso_spelling/spell.txt Normal file
View File

@ -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()