Skip to content

Commit 0aa45cf

Browse files
committed
df 필드 수정, df 처리 프로세스 수정
1 parent 1a5d6bb commit 0aa45cf

File tree

4 files changed

+21
-27
lines changed

4 files changed

+21
-27
lines changed

Diff for: collector/spot-dataset/azure/lambda/current_collector/lambda_function_sps.py

+17-12
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,15 @@ def lambda_handler(event, _):
3232
return handle_response(200, "Executed successfully. Scheduled time skipped.", action, event_time_utc)
3333

3434
sps_res_df = load_sps.collect_spot_placement_score(desired_count=desired_count)
35+
3536
else:
3637
raise ValueError(f"Invalid lambda action.")
3738

3839

39-
# price_if_df = S3.read_file(AZURE_CONST.S3_LATEST_PRICE_IF_GZIP_SAVE_PATH, 'pkl.gz')
40-
price_if_df = pd.DataFrame(S3.read_file(AZURE_CONST.LATEST_FILENAME, 'json'))
41-
price_eviction_sps_df = merge_price_eviction_sps_df(price_if_df, sps_res_df)
42-
4340
if sps_res_df is None: raise ValueError("sps_res_df is None")
44-
if price_if_df is None: raise ValueError("price_if_df is None")
45-
if price_eviction_sps_df is None: raise ValueError("price_eviction_sps_df is None")
4641

47-
if not update_and_save_res_df(price_eviction_sps_df, event_time_utc):
48-
raise RuntimeError("Failed to update or save price_eviction_sps_df data")
42+
if not handle_res_df(sps_res_df, event_time_utc):
43+
raise RuntimeError("Failed to handle_res_df")
4944

5045
return handle_response(200, "Executed Successfully!", action, event_time_utc)
5146

@@ -56,11 +51,21 @@ def lambda_handler(event, _):
5651
return handle_response(500, "Execute Failed!", action, event_time_utc, str(e))
5752

5853

59-
def update_and_save_res_df(price_eviction_sps_df, event_time_utc):
54+
def handle_res_df(sps_res_df, event_time_utc):
6055
try:
61-
update_result = update_latest_sps(price_eviction_sps_df, event_time_utc)
62-
save_result = save_raw_sps(price_eviction_sps_df, event_time_utc)
63-
return update_result and save_result
56+
sps_res_df['time'] = event_time_utc.strftime("%Y-%m-%d %H:%M:%S")
57+
sps_res_df['AvailabilityZone'] = sps_res_df['AvailabilityZone'].where(pd.notna(sps_res_df['AvailabilityZone']), None)
58+
59+
60+
# price_if_df = S3.read_file(AZURE_CONST.S3_LATEST_PRICE_IF_GZIP_SAVE_PATH, 'pkl.gz')
61+
price_if_df = pd.DataFrame(S3.read_file(AZURE_CONST.LATEST_FILENAME, 'json'))
62+
price_eviction_sps_df = merge_price_eviction_sps_df(price_if_df, sps_res_df)
63+
64+
if price_if_df is None: raise ValueError("price_if_df is None")
65+
if price_eviction_sps_df is None: raise ValueError("price_eviction_sps_df is None")
66+
67+
return update_latest_sps(price_eviction_sps_df) and save_raw_sps(price_eviction_sps_df, event_time_utc)
68+
6469

6570
except Exception as e:
6671
logger.error(f"Error in handle_res_df function: {e}")

Diff for: collector/spot-dataset/azure/lambda/current_collector/load_sps.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ def execute_spot_placement_score_task_by_parameter_pool_df(api_calls_df, availab
162162
score_data = {
163163
"DesiredCount": desired_count,
164164
"AvailabilityZone": score.get("availabilityZone", None),
165-
# "RegionCodeSPS": score.get("region", None),
165+
"RegionCodeSPS": score.get("region", None),
166166
"Region": SS_Resources.region_map_and_instance_map_tmp['region_map'].get(
167167
score.get("region", ""), ""),
168-
# "InstanceTypeSPS": score.get("sku", None),
168+
"InstanceTypeSPS": score.get("sku", None),
169169
"InstanceTier": SS_Resources.region_map_and_instance_map_tmp['instance_map'].get(
170170
score.get("sku", ""), {}).get("InstanceTier", None),
171171
"InstanceType": SS_Resources.region_map_and_instance_map_tmp['instance_map'].get(

Diff for: collector/spot-dataset/azure/lambda/current_collector/utils/merge_df.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def merge_price_eviction_df(price_df, eviction_df):
1717
def merge_price_eviction_sps_df(price_eviction_df, sps_df):
1818
join_df = pd.merge(price_eviction_df, sps_df, on=['InstanceTier', 'InstanceType', 'Region'], how='outer')
1919
join_df.rename(columns={'time_x': 'PriceEviction_Update_Time', 'time_y': 'SPS_Update_Time'}, inplace=True)
20-
join_df.drop(columns=['id_x', 'id_y'], inplace=True)
20+
join_df.drop(columns=['id', 'InstanceTypeSPS', 'RegionCodeSPS'], inplace=True)
2121
join_df = join_df[["InstanceTier", "InstanceType", "Region", "OndemandPrice", "SpotPrice", "Savings", "IF",
2222
"PriceEviction_Update_Time", "DesiredCount", "AvailabilityZone", "Score", "SPS_Update_Time"]]
2323

Diff for: collector/spot-dataset/azure/lambda/current_collector/utils/upload_data.py

+1-12
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,9 @@ def upload_cloudwatch(data, timestamp):
161161
)
162162

163163

164-
def update_latest_sps(dataframe, time_utc):
164+
def update_latest_sps(dataframe):
165165
try:
166-
formatted_time = time_utc.strftime("%Y-%m-%d %H:%M:%S")
167-
168-
dataframe['id'] = dataframe.index + 1
169-
dataframe['time'] = formatted_time
170-
dataframe = dataframe[['id', 'InstanceTier', 'InstanceType', 'Region', 'DesiredCount', 'AvailabilityZone', 'Score', 'InstanceTypeSPS', 'RegionCodeSPS', 'time']]
171-
dataframe['AvailabilityZone'] = dataframe['AvailabilityZone'].where(pd.notna(dataframe['AvailabilityZone']), None)
172-
173166
json_data = dataframe.to_dict(orient="records")
174-
175167
S3.upload_file(json_data, f"{AZURE_CONST.LATEST_SPS_FILENAME}", "json", set_public_read=True)
176168
return True
177169

@@ -182,9 +174,6 @@ def update_latest_sps(dataframe, time_utc):
182174

183175
def save_raw_sps(dataframe, time_utc):
184176
try:
185-
dataframe['Time'] = time_utc
186-
dataframe = dataframe[['Time','InstanceTier','InstanceType', 'Region', 'DesiredCount', 'AvailabilityZone', 'Score', 'InstanceTypeSPS', 'RegionCodeSPS']]
187-
188177
s3_dir_name = time_utc.strftime("%Y/%m/%d")
189178
s3_obj_name = time_utc.strftime("%H-%M-%S")
190179
S3.upload_file(dataframe, f"sps-collector/azure/result/rawdata/{s3_dir_name}/{s3_obj_name}.csv.gz", "df_to_csv.gz", set_public_read=True)

0 commit comments

Comments
 (0)