Skip to content

Commit 5ff4295

Browse files
authored
performance month is moved to global and local loading (#470)
1 parent 8d3cbba commit 5ff4295

File tree

6 files changed

+38
-33
lines changed

6 files changed

+38
-33
lines changed

bulk-up/src/bulk_up/log_to_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import pandas as pd
66
from rdflib import RDF, RDFS, Graph, URIRef
7-
from scaffold.utils.utils import get_performance_month
87

98
module_path = ".." # run this script from the bulk-up folder. This will add the directory above (which is precision-feedback-pipeline/) to system path to be able to import pipeline modules
109
sys.path.append(module_path)
@@ -104,7 +103,8 @@ def generate_response(output_message, input_message):
104103

105104

106105
def add_signal_properties(row, output_message, input_message):
107-
performance_month = get_performance_month(input_message)
106+
performance_month = input_message["performance_month"]
107+
108108
performance_df = pd.DataFrame(
109109
input_message["Performance_data"][1:],
110110
columns=input_message["Performance_data"][0],

scaffold/cli.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,29 +120,29 @@ def batch_csv(
120120
),
121121
] = False,
122122
):
123-
startup.startup(performance_data_path)
123+
startup.startup(
124+
performance_data_path=performance_data_path, performance_m=performance_month
125+
)
124126

125127
success_count = 0
126128
failure_count = 0
127129
for staff_number in (
128130
startup.performance_data["staff_number"].drop_duplicates().head(max_files)
129131
):
130132
try:
131-
context.from_global(staff_number, performance_month)
133+
context.from_global(staff_number)
132134
try:
133135
full_message = pipeline()
134136
# full_message["message_instance_id"] = input_data["message_instance_id"]
135-
full_message["performance_data"] = performance_month
137+
full_message["performance_data"] = context.performance_month
136138
except Exception as e:
137139
# e.detail["message_instance_id"] = input_data["message_instance_id"]
138140
raise e
139141
if not stats_only:
140142
directory = performance_data_path.parent / "messages"
141143
os.makedirs(directory, exist_ok=True)
142144

143-
new_filename = (
144-
f"Provider_{staff_number} - message for {performance_month}.json"
145-
)
145+
new_filename = f"Provider_{staff_number} - message for {context.performance_month}.json"
146146
output_path = directory / new_filename
147147

148148
output_path.write_bytes(

scaffold/context.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from rdflib import Graph
33

44
from scaffold import startup
5-
from scaffold.utils.utils import get_performance_month
65

76
preferences_dict = {}
87
history_dict = {}
@@ -28,7 +27,11 @@ def from_req(req_info):
2827
except Exception:
2928
pass
3029

31-
performance_month = get_performance_month(req_info, performance_df["month"].max())
30+
performance_month = startup.performance_month
31+
if req_info["performance_month"]:
32+
performance_month = req_info["performance_month"]
33+
if not performance_month:
34+
performance_month = performance_df["month"].max()
3235

3336
staff_number = int(performance_df.at[0, "staff_number"])
3437

@@ -48,7 +51,7 @@ def from_req(req_info):
4851
subject_graph += startup.base_graph
4952

5053

51-
def from_global(staff_num, perf_month):
54+
def from_global(staff_num):
5255
global \
5356
preferences_dict, \
5457
history_dict, \
@@ -58,28 +61,32 @@ def from_global(staff_num, perf_month):
5861
subject_graph
5962

6063
staff_number = int(staff_num)
61-
history_dict = {}
64+
65+
try:
66+
performance_df = startup.performance_data[
67+
startup.performance_data["staff_number"] == staff_number
68+
].reset_index(drop=True)
69+
except Exception:
70+
pass
71+
72+
performance_month = startup.performance_month
73+
if not performance_month:
74+
performance_month = performance_df["month"].max()
75+
6276
preferences_dict = {}
63-
performance_month = perf_month
6477
try:
6578
p = startup.preferences.loc[staff_number, "preferences"]
6679
preferences_dict = set_preferences(p)
6780
except Exception:
6881
return set_preferences({})
6982

83+
history_dict = {}
7084
try:
7185
staff_data = startup.history[startup.history["staff_number"] == staff_number]
7286
history_dict = staff_data.set_index("month")["history"].to_dict()
7387
except Exception:
7488
pass
7589

76-
try:
77-
performance_df = startup.performance_data[
78-
startup.performance_data["staff_number"] == staff_number
79-
].reset_index(drop=True)
80-
except Exception:
81-
pass
82-
8390
subject_graph = Graph()
8491
subject_graph += startup.base_graph
8592

scaffold/startup.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@
2727
columns=["staff_number", "month", "history"], index=["staff_number"]
2828
)
2929
performance_data = pd.DataFrame()
30+
performance_month = ""
3031

3132
# Set up request session as se, config to handle file URIs with FileAdapter
3233
se = requests.Session()
3334
se.mount("file://", FileAdapter())
3435

3536

36-
def startup(performance_data_path: pathlib.Path = None):
37+
def startup(performance_data_path: pathlib.Path = None, performance_m: str = ""):
3738
## Log of instance configuration
3839
logger.debug("Startup configuration for this instance:")
3940
for attribute in dir(settings):
@@ -48,7 +49,8 @@ def startup(performance_data_path: pathlib.Path = None):
4849
default_preferences, \
4950
preferences, \
5051
history, \
51-
performance_data
52+
performance_data, \
53+
performance_month
5254

5355
mpm = load_mpm()
5456

@@ -76,6 +78,12 @@ def startup(performance_data_path: pathlib.Path = None):
7678
if performance_data_path:
7779
performance_data = pd.read_csv(performance_data_path, parse_dates=["month"])
7880

81+
if settings.performance_month:
82+
performance_month = settings.settings.performance_month
83+
84+
if performance_m:
85+
performance_month = performance_m
86+
7987
except Exception as e:
8088
print("Startup aborted, see traceback:")
8189
raise e

scaffold/utils/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __init__(self):
5454
"outputs", cast=bool, default=False
5555
) # Logging of intermediate files
5656
self.performance_month = config(
57-
"performance_month", default=None
57+
"performance_month", cast=str, default=""
5858
) # performance_month for instance
5959
self.use_mi = config("use_mi", cast=bool, default=True) # use mi
6060
self.use_preferences = config(

scaffold/utils/utils.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,3 @@ def set_logger():
143143
logger.at_least = (
144144
lambda lvl: logger.level(lvl).no >= logger.level(settings.log_level).no
145145
)
146-
147-
148-
def get_performance_month(req_info, max_month):
149-
performance_month = req_info["performance_month"]
150-
if settings.performance_month:
151-
performance_month = settings.settings.performance_month
152-
153-
if not performance_month:
154-
performance_month = max_month
155-
return performance_month

0 commit comments

Comments
 (0)