Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add id column in latest data json file #210

Merged
merged 4 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion collection/aws/ec2_collector/aws_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

current_df = build_join_df(spot_price_df, ondemand_price_df, spotinfo_df, sps_df)

update_latest(current_df) # upload current data to S3
update_latest(current_df, timestamp) # upload current data to S3
save_raw(current_df, timestamp)

if 'latest_df.pkl' not in os.listdir(f'{LOCAL_PATH}/'):
Expand Down
10 changes: 5 additions & 5 deletions collection/aws/ec2_collector/join_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ def build_join_df(spot_price_df, ondemand_price_df, spotinfo_df, sps_df):
join_df = pd.merge(join_df, spotinfo_df, how="outer")

join_df['Savings'] = 100.0 - (join_df['SpotPrice'] * 100 / join_df['OndemandPrice'])
join_df['Savings'] = join_df['Savings'].fillna(0)
join_df['SPS'] = join_df['SPS'].fillna(0)
join_df['SpotPrice'] = join_df['SpotPrice'].fillna(0)
join_df['OndemandPrice'] = join_df['OndemandPrice'].fillna(0)
join_df['IF'] = join_df['IF'].fillna(0)
join_df['Savings'] = join_df['Savings'].fillna(-1)
join_df['SPS'] = join_df['SPS'].fillna(-1)
join_df['SpotPrice'] = join_df['SpotPrice'].fillna(-1)
join_df['OndemandPrice'] = join_df['OndemandPrice'].fillna(-1)
join_df['IF'] = join_df['IF'].fillna(-1)

join_df['Savings'] = join_df['Savings'].astype('int')
join_df['SPS'] = join_df['SPS'].astype('int')
Expand Down
7 changes: 5 additions & 2 deletions collection/aws/ec2_collector/upload_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,12 @@ def upload_timestream(data, timestamp):
print(f"end : {counter}")


def update_latest(data):
def update_latest(data, timestamp):
filename = 'latest_aws.json'
result = data.to_json(f"{LOCAL_PATH}/{filename}")
data = data.drop(data[(data['AZ'].isna()) | (data['Region'].isna()) | (data['InstanceType'].isna())].index)
data['time'] = timestamp.strftime("%Y-%m-%d %H:%M:%S")
data['id'] = data.index+1
result = data.to_json(f"{LOCAL_PATH}/{filename}", orient="records")
s3_path = f'latest_data/{filename}'
session = boto3.Session()
s3 = session.client('s3')
Expand Down