in scripts/figs.py [0:0]
def plot_weekly_traffic(week_id: int, yugong: bool = False, c: int = 30):
# Compute start date of the given week (week_id=2 starts on 2024-10-22)
base_date = datetime(2024, 10, 29)
start_date = base_date + timedelta(days=7 * (week_id - 2))
print("Start date:", start_date)
traffic_rates = []
# Iterate through the 7 days of the given week
for i in range(7):
current_date = start_date + timedelta(days=i)
file_date_str = current_date.strftime('%Y%m%d')
# Construct file path
if yugong:
traffic_file = f"../yugong_results_rep0.002/c{c}/traffic_{file_date_str}.csv"
else:
traffic_file = f"../sample_1.000_rep0.001/c{c}/traffic_{file_date_str}.csv"
# Read traffic data if the file exists
if os.path.exists(traffic_file):
df = pd.read_csv(traffic_file)
df['traffic_rate'] = (df['egress_rate_presto_bps'] + df['egress_rate_spark_bps'] +
df['ingress_rate_presto_bps'] + df['ingress_rate_spark_bps'])
traffic_rates.extend(df['traffic_rate'].tolist())
else:
print(f"Traffic file not found: {traffic_file}")
# Plot the traffic rate over the week
plt.figure(figsize=(10, 5))
plt.plot(traffic_rates, linestyle='-', color='blue')
plt.xlabel("Minute bucket")
plt.ylabel("Traffic Rate (bps)")
plt.ylim(0, 2*10**12)
plt.title(f"Traffic Rate Over Week {week_id}")
plt.grid(True)
plt.tight_layout()
plt.savefig(f'traffic_week_{week_id}.png')