Skip to content

Commit

Permalink
s
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanAdamovNeon committed Aug 10, 2024
1 parent 2795521 commit ccd5426
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 39 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dapps_reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,8 @@ jobs:
run: |
ARTIFACT_NAME="cost_reports"
ARTIFACT_INFO=$(gh api -X GET "/repos/${{ github.repository }}/actions/artifacts" | jq -r ".artifacts[] | select(.name==\"${ARTIFACT_NAME}\") | {id: .id, run_id: .workflow_run.id}")
ARTIFACT_ID=$(echo "${ARTIFACT_INFO}" | jq -r '.id')
RUN_ID=$(echo "${ARTIFACT_INFO}" | jq -r '.run_id')
ARTIFACT_ID=$(echo "${ARTIFACT_INFO}" | jq -r '.id' | head -n 1)
RUN_ID=$(echo "${ARTIFACT_INFO}" | jq -r '.run_id' | head -n 1)
ARTIFACT_URL="https://github.com/${{ github.repository }}/actions/runs/${RUN_ID}/artifacts/${ARTIFACT_ID}"
echo "🔗[Cost report](${ARTIFACT_URL})" > cost_reports.md
- name: "Add cost reports to summary"
Expand Down
2 changes: 1 addition & 1 deletion clickfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ def compare_and_save_dapp_results(
docker_tag_ = f", Docker image tag {docker_image_tag}" if not tag else ""
test_results_handler.generate_and_save_plots_pdf(
historical_data=historical_data,
title_end=f"{repo},{branch_}{tag_}{docker_tag_}",
title_end=f"{repo}{branch_}{tag_}{docker_tag_}",
output_pdf="cost_reports.pdf",
)

Expand Down
1 change: 0 additions & 1 deletion deploy/cli/dapps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import pathlib
from collections import Counter

import tabulate
import pandas as pd

from deploy.cli.infrastructure import get_solana_accounts_in_tx
Expand Down
92 changes: 57 additions & 35 deletions deploy/test_results_db/test_results_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ def generate_and_save_plots_pdf(
latest_report_data = historical_data[historical_data["timestamp"] == latest_timestamp]
dapp_names = latest_report_data["dapp_name"].unique()
metrics = ["fee_in_eth", "fee_in_usd", "acc_count", "trx_count", "gas_estimated", "gas_used", "used_%_of_EG"]
historical_data = historical_data.sort_values(by=["timestamp"])

unique_timestamps = historical_data["timestamp"].unique().tolist()
unique_tags = historical_data["tag"].unique().tolist()

if unique_tags:
x_tick_labels = unique_tags
else:
x_tick_labels = [historical_data["branch"].unique()[0]] * len(unique_timestamps)

with PdfPages(output_pdf) as pdf:
for dapp_name in dapp_names:
Expand All @@ -96,6 +105,7 @@ def generate_and_save_plots_pdf(
action_data = dapp_data[dapp_data["action"] == action]
y_limits = {}

# define y limits
for metric in metrics:
metric_data = action_data[metric]
min_val = metric_data.min()
Expand All @@ -115,57 +125,69 @@ def generate_and_save_plots_pdf(
ax = axes[action_idx, metric_idx] if num_rows > 1 else axes[metric_idx]
data_subset = dapp_data[dapp_data["action"] == action].copy()

# normalize data
need_to_add_rows = len(unique_timestamps) - len(data_subset)
if need_to_add_rows:
for i, unique_timestamp in enumerate(unique_timestamps):
if unique_timestamp not in data_subset["timestamp"].values:
new_row = pd.DataFrame(
data=[{
"timestamp": unique_timestamp,
"branch": data_subset["branch"].unique()[0],
"tag": unique_tags[i] if unique_tags else None,
"dapp_name": data_subset.iloc[0]["dapp_name"],
"action": data_subset.iloc[0]["action"],
}],
columns=data_subset.columns,
)
data_subset = pd.concat([data_subset, new_row], ignore_index=True)

data_subset = data_subset.sort_values(by='timestamp').reset_index(drop=True)

if not data_subset.empty:
# Convert timestamps to evenly spaced numeric values
data_subset["time_numeric"] = range(len(data_subset))
data_subset = data_subset.sort_values(by=["timestamp"])
prev_value = None
prev_is_valid = True

# Plot blue lines before scatter
ax.plot(
data_subset["time_numeric"], data_subset[metric], color="blue", linestyle="-", linewidth=1
)

for i, (x, y) in enumerate(zip(data_subset["time_numeric"], data_subset[metric])):
if prev_value is not None and y != prev_value:
ax.scatter(x, y, color="red")
ax.annotate(
f"{y}",
(x, y),
textcoords="offset points",
xytext=(25, 5),
ha="center",
color="red",
rotation=45,
)
# Plot grey lines before scatter
ax.plot(data_subset.index, data_subset[metric], color="darkgrey", linestyle="-", linewidth=1)

if prev_is_valid:
# Plot blue or red dots
for x, y in zip(data_subset.index, data_subset[metric]):
if not pd.isna(y):
if prev_value is not None and y != prev_value:
ax.scatter(x, y, color="red")
ax.annotate(
f"{prev_value}",
(prev_x, prev_y),
f"{y}",
(x, y),
textcoords="offset points",
xytext=(25, 5),
ha="center",
color="blue",
color="red",
rotation=45,
)
prev_is_valid = False
else:
ax.scatter(x, y, color="blue")
prev_is_valid = True

prev_value = y
prev_x, prev_y = x, y
if prev_is_valid:
ax.annotate(
f"{prev_value}",
(prev_x, prev_y),
textcoords="offset points",
xytext=(25, 5),
ha="center",
color="blue",
rotation=45,
)
prev_is_valid = False
else:
ax.scatter(x, y, color="blue")
prev_is_valid = True

prev_value = y
prev_x, prev_y = x, y

# Formatting x-axis to show evenly spaced points
ax.set_xticks(range(len(data_subset)))
ax.set_xticks(range(len(x_tick_labels)))

# set tick labels
if data_subset["tag"].notna().any():
x_tick_labels = data_subset["tag"]
else:
x_tick_labels = data_subset["branch"]
ax.set_xticklabels(x_tick_labels, rotation=45)
ax.tick_params(axis="y", labelsize=8)

Expand Down

0 comments on commit ccd5426

Please sign in to comment.