-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathdata_loader.py
More file actions
43 lines (34 loc) · 1.04 KB
/
data_loader.py
File metadata and controls
43 lines (34 loc) · 1.04 KB
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
import json
from typing import List
import config
from model import Issue
# Store issues as singleton to avoid reloads
_ISSUES:List[Issue] = None
class DataLoader:
"""
Loads the issue data into a runtime object.
"""
def __init__(self):
"""
Constructor
"""
self.data_path:str = config.get_parameter('ENPM611_PROJECT_DATA_PATH')
def get_issues(self):
"""
This should be invoked by other parts of the application to get access
to the issues in the data file.
"""
global _ISSUES # to access it within the function
if _ISSUES is None:
_ISSUES = self._load()
print(f'Loaded {len(_ISSUES)} issues from {self.data_path}.')
return _ISSUES
def _load(self):
"""
Loads the issues into memory.
"""
with open(self.data_path,'r') as fin:
return [Issue(i) for i in json.load(fin)]
if __name__ == '__main__':
# Run the loader for testing
DataLoader().get_issues()