-
Notifications
You must be signed in to change notification settings - Fork 1
/
label_generator.py
137 lines (126 loc) · 4.89 KB
/
label_generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import re
import config
def get_label_parts(label):
# print(label)
match = re.search(r'\d', label)
if match:
index = match.start()
chars = label[:index]
numbers = label[index:]
return chars, numbers
else:
return label, False
# def generate_alphanumeric_sequence():
# current_char = 'A'
# num_iteration = 0
# config.last_label_before_return = 'A'
# while True:
# if len(config.deleted_labels) > 0:
# current_char = config.deleted_labels.pop()
#
# chars, numbers = get_label_parts(current_char)
# if chars < config.last_label_before_return:
# current_char = f'{config.last_label_before_return}'
# current_char = chr(ord(current_char) + 1)
# num_iteration = config.last_turn_before_return
# else:
#
#
# # if num_iteration != 0:
# # yield current_char + str(num_iteration)
# # else:
# # pass
# yield current_char + str(num_iteration)
# if current_char == 'C':
# current_char = 'A'
# num_iteration += 1
#
# else:
# current_char = chr(ord(current_char) + 1)
# def generate_alphanumeric_sequence():
# current_char = 'A'
# num_iteration = 0
# config.last_label_before_return = 'A'
# config.last_turn_before_return = 0
# while True:
# if len(config.deleted_labels) > 0:
# # Use any previously deleted labels before generating new ones
# tmp = config.deleted_labels.pop(0)
# chars, numbers = get_label_parts(tmp)
# if chars == config.last_label_before_return:
# num_iteration = int(numbers)
# else:
# current_char = chars
# num_iteration = int(numbers)
# else:
# if current_char < config.last_label_before_return:
# current_char = chr(ord(config.last_label_before_return) + 1)
# num_iteration = config.last_turn_before_return
# label = current_char + str(num_iteration)
# while label in config.deleted_labels:
# num_iteration += 1
# label = current_char + str(num_iteration)
# yield label
# if current_char == 'Z':
# current_char = 'A'
# num_iteration += 1
# else:
# current_char = chr(ord(current_char) + 1)
# def generate_alphanumeric_sequence():
# current_char = 'A'
# num_iteration = 0
# config.last_label_before_return = 'A'
# config.last_turn_before_return = 0
# while True:
# if len(config.deleted_labels) > 0:
# # Use any previously deleted labels before generating new ones
# tmp = config.deleted_labels.pop(0)
# chars, numbers = get_label_parts(tmp)
# if not chars == config.last_label_before_return:
# num_iteration = int(numbers)
# current_char = chars + str(num_iteration)
# print(current_char)
#
# elif len(config.deleted_labels) == 0:
# if current_char < config.last_label_before_return:
# current_char = chr(ord(config.last_label_before_return) + 1)
# num_iteration = config.last_turn_before_return
# label = current_char + str(num_iteration)
# while label in config.deleted_labels:
# config.deleted_labels.remove(label)
# num_iteration += 1
# label = current_char + str(num_iteration)
# yield label
# if current_char == 'Z':
# current_char = 'A'
# num_iteration += 1
# else:
# current_char = chr(ord(current_char) + 1)
def generate_alphanumeric_sequence():
current_char = 'A'
num_iteration = 0
config.last_label_before_return = 'A'
config.last_turn_before_return = 0
while True:
if len(config.deleted_labels) > 0:
tmp = config.deleted_labels.pop(0)
chars, numbers = get_label_parts(tmp)
if chars != config.last_label_before_return:
yield chars + str(numbers)
else:
if chars == 'Z':
yield chars + str(numbers)
current_char = 'A'
num_iteration = numbers + 1
else:
yield current_char + str(num_iteration)
current_char = chr(ord(config.last_label_before_return) + 1)
num_iteration = numbers
else:
if current_char == 'Z':
yield current_char + str(num_iteration)
current_char = 'A'
num_iteration += 1
else:
yield current_char + str(num_iteration)
current_char = chr(ord(current_char) + 1)