Initial lists populated with pre-defined quality attributes and QA categories.
Source code in mlte/store/custom_list/initial_custom_lists.py
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 | class InitialCustomLists:
"""Initial lists populated with pre-defined quality attributes and QA categories."""
@staticmethod
def setup_custom_list_store(
stores_uri: StoreURI,
) -> CustomListStore:
"""
Sets up a custom list store with the initial custom lists.
:param stores_uri: The URI of the store being used (i.e., base folder, base DB, etc).
:return: A custom list store populated with the initial entries.
"""
# Create the initial custom lists.
print(f"Creating initial custom lists at URI: {stores_uri.uri}")
custom_list_store = create_custom_list_store(stores_uri)
with ManagedCustomListSession(custom_list_store.session()) as session:
# Load all of the custom lists as default lists.
InitialCustomLists._load_resources_to_list(
session, classification_entries, CustomListName.CLASSIFICATION
)
InitialCustomLists._load_resources_to_list(
session, problem_type_entries, CustomListName.PROBLEM_TYPES
)
InitialCustomLists._load_resources_to_list(
session, tags_entries, CustomListName.TAGS
)
InitialCustomLists._load_resources_to_list(
session, qa_category_entries, CustomListName.QA_CATEGORIES
)
InitialCustomLists._load_resources_to_list(
session,
quality_attribute_entries,
CustomListName.QUALITY_ATTRIBUTES,
)
return custom_list_store
@staticmethod
def _load_resources_to_list(
store_session: CustomListStoreSession,
module: ModuleType,
list_name: CustomListName,
):
"""
Loads all JSON resources from the given module into the store for the given list.
:param store_session: The CustomList store session to store things to.
:param module: The module where the JSON resources with the entries are in.
:param list_name: The CustomListName that the entries will be associated to.
"""
num_entries = 0
for json_data in get_json_resources(module):
entry = CustomListEntryModel(**json_data)
try:
store_session.custom_list_entry_mapper.create(entry, list_name)
except error.ErrorAlreadyExists:
# If default values are already there we dont want to overwrite any changes
pass
num_entries += 1
print(f"Loaded {num_entries} {list_name.value} for initial list")
|
setup_custom_list_store(stores_uri)
staticmethod
Sets up a custom list store with the initial custom lists.
Parameters:
| Name |
Type |
Description |
Default |
stores_uri
|
StoreURI
|
The URI of the store being used (i.e., base folder, base DB, etc).
|
required
|
Returns:
| Type |
Description |
CustomListStore
|
A custom list store populated with the initial entries.
|
Source code in mlte/store/custom_list/initial_custom_lists.py
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 | @staticmethod
def setup_custom_list_store(
stores_uri: StoreURI,
) -> CustomListStore:
"""
Sets up a custom list store with the initial custom lists.
:param stores_uri: The URI of the store being used (i.e., base folder, base DB, etc).
:return: A custom list store populated with the initial entries.
"""
# Create the initial custom lists.
print(f"Creating initial custom lists at URI: {stores_uri.uri}")
custom_list_store = create_custom_list_store(stores_uri)
with ManagedCustomListSession(custom_list_store.session()) as session:
# Load all of the custom lists as default lists.
InitialCustomLists._load_resources_to_list(
session, classification_entries, CustomListName.CLASSIFICATION
)
InitialCustomLists._load_resources_to_list(
session, problem_type_entries, CustomListName.PROBLEM_TYPES
)
InitialCustomLists._load_resources_to_list(
session, tags_entries, CustomListName.TAGS
)
InitialCustomLists._load_resources_to_list(
session, qa_category_entries, CustomListName.QA_CATEGORIES
)
InitialCustomLists._load_resources_to_list(
session,
quality_attribute_entries,
CustomListName.QUALITY_ATTRIBUTES,
)
return custom_list_store
|