Skip to content

Commit a2606e4

Browse files
committed
Generate Product IDs
1 parent 5de2a4e commit a2606e4

File tree

5 files changed

+188
-1
lines changed

5 files changed

+188
-1
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
4. [Workflow](#workflow)
2222
5. [Swagger](#swagger)
2323
6. [ETL](#etl)
24+
7. [Administration](#administration)
2425

2526
---
2627

@@ -429,6 +430,18 @@ and
429430
make etl--clear-state WORKSPACE=dev SET_CHANGELOG_NUMBER=540210
430431
```
431432

433+
## Administration
434+
435+
### Generating Ids
436+
437+
In order to generate a persistent list of Ids across environments then run... (The example given will generate 100 ids.)
438+
439+
```
440+
make admin--generate-ids--product SET_GENERATOR_COUNT=100
441+
```
442+
443+
Any previously generated ids will not be overwritten.
444+
432445
### Documentation
433446

434447
We have several locations for the Swagger to keep things as visible as possible
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SET_GENERATOR_COUNT :=
2+
3+
admin--generate-ids--product: ## Generate product Ids
4+
poetry run python scripts/administration/id_generator.py --count="$(SET_GENERATOR_COUNT)"
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import argparse
2+
import json
3+
import os
4+
5+
from domain.core.cpm_system_id import ProductId
6+
7+
ID_FILE_MAP = {
8+
"product": f"{os.getcwd()}/src/layers/domain/core/cpm_system_id/generated_ids/product_ids.json",
9+
}
10+
11+
ID_CLASS_MAP = {
12+
"product": ProductId,
13+
}
14+
15+
16+
def save_to_set(id, ids):
17+
if id in ids:
18+
return False
19+
20+
ids.add(id)
21+
return ids
22+
23+
24+
def generator(id_type="product"):
25+
id_class = ID_CLASS_MAP.get(id_type)
26+
generator = id_class.create()
27+
return generator.__root__
28+
29+
30+
def open_file(id_type="product"):
31+
if os.path.exists(ID_FILE_MAP.get(id_type)):
32+
with open(ID_FILE_MAP.get(id_type), "r") as file:
33+
return set(json.load(file))
34+
return set()
35+
36+
37+
def save_file(ids, id_type="product"):
38+
with open(ID_FILE_MAP.get(id_type), "w") as file:
39+
json.dump(list(ids), file)
40+
41+
42+
def bulk_generator(id_count=1, id_type="product"):
43+
ids = open_file(id_type=id_type)
44+
for _ in range(id_count):
45+
saved = False
46+
while not saved:
47+
generated_id = generator()
48+
saved = save_to_set(generated_id, ids)
49+
ids = saved
50+
51+
save_file(ids, id_type)
52+
return ids
53+
54+
55+
if __name__ == "__main__":
56+
parser = argparse.ArgumentParser(description="Generate unique Product Ids.")
57+
parser.add_argument(
58+
"--count", type=int, default=1, help="Number of Product Ids to generate."
59+
)
60+
args = parser.parse_args()
61+
ids = bulk_generator(args.count)
62+
id_type = "product"
63+
print(f"Generated {id_type.capitalize()} Ids...") # noqa
64+
print("========================") # noqa
65+
for id in ids:
66+
print(id) # noqa
67+
68+
print("========================") # noqa
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .v1 import * # noqa: F403, F401
1+
from .v1 import * # noqa
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
[
2+
"P.RKK-P46",
3+
"P.MNE-V6V",
4+
"P.HPM-9MC",
5+
"P.PLT-9YV",
6+
"P.46W-MHJ",
7+
"P.7JD-MUC",
8+
"P.3GG-DW6",
9+
"P.AE9-96P",
10+
"P.K6N-D4X",
11+
"P.RVC-APA",
12+
"P.JFX-3M4",
13+
"P.HKM-MGU",
14+
"P.NXD-R7N",
15+
"P.66R-VWJ",
16+
"P.D3Y-H7J",
17+
"P.T46-YEE",
18+
"P.XTW-LG3",
19+
"P.WTJ-FJT",
20+
"P.XWA-VFF",
21+
"P.6YL-D93",
22+
"P.CPY-J4W",
23+
"P.JNH-MWV",
24+
"P.K7C-X7D",
25+
"P.MLH-97C",
26+
"P.PV9-GTU",
27+
"P.JUW-CRP",
28+
"P.HUX-WFD",
29+
"P.9RJ-VTW",
30+
"P.EGF-DHU",
31+
"P.XMX-4CN",
32+
"P.4RE-CKC",
33+
"P.HR9-9PU",
34+
"P.U9F-D3X",
35+
"P.49J-A7U",
36+
"P.JV6-H4R",
37+
"P.THY-GVT",
38+
"P.AY3-ERX",
39+
"P.6DP-3MK",
40+
"P.DUG-WPW",
41+
"P.DKM-L96",
42+
"P.CXW-CRT",
43+
"P.EKF-XRK",
44+
"P.JG7-LCA",
45+
"P.LRN-UWP",
46+
"P.9AK-LMH",
47+
"P.K96-UND",
48+
"P.YUP-T9J",
49+
"P.EJK-ACK",
50+
"P.H9X-PD4",
51+
"P.VKF-LUV",
52+
"P.HWC-GLY",
53+
"P.D3C-YW7",
54+
"P.KM7-439",
55+
"P.RK9-CKM",
56+
"P.CCW-G73",
57+
"P.RYF-MMM",
58+
"P.4CU-UKP",
59+
"P.GV7-FPE",
60+
"P.AEP-C4V",
61+
"P.CTC-UEM",
62+
"P.DYD-3RG",
63+
"P.H6K-7VL",
64+
"P.U6J-EEU",
65+
"P.EWX-ACY",
66+
"P.4HC-WJN",
67+
"P.A4C-EKV",
68+
"P.6AK-96A",
69+
"P.L9N-Y3T",
70+
"P.TVU-MVK",
71+
"P.WW7-FCD",
72+
"P.PPW-73K",
73+
"P.JPT-6AY",
74+
"P.G9T-UAR",
75+
"P.6LF-D3M",
76+
"P.4NT-EGL",
77+
"P.7JR-XAP",
78+
"P.PEH-UFM",
79+
"P.6KC-WPU",
80+
"P.464-URD",
81+
"P.3DR-EK3",
82+
"P.KG3-CHW",
83+
"P.3FL-PTA",
84+
"P.GT4-9DY",
85+
"P.9RW-9FX",
86+
"P.HTJ-YFF",
87+
"P.NMX-MHC",
88+
"P.4KJ-DHT",
89+
"P.3KL-X6F",
90+
"P.DUM-YKT",
91+
"P.F7G-GVH",
92+
"P.4H4-4FJ",
93+
"P.9XP-NX6",
94+
"P.4VH-YLN",
95+
"P.VRA-F9U",
96+
"P.97J-HN9",
97+
"P.3WF-CNA",
98+
"P.TUR-X4P",
99+
"P.DXE-FWE",
100+
"P.C9W-CLJ",
101+
"P.JVG-CA4"
102+
]

0 commit comments

Comments
 (0)