-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph_Maker.py
59 lines (51 loc) · 1.72 KB
/
graph_Maker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import matplotlib.pyplot as plt
import numpy as np
# Read data from the file
file_path = "time_logs/windows_program_log.txt"
with open(file_path, "r") as file:
# Read lines and convert data to float
data = [float(line.strip()) for line in file.readlines()]
# Convert data to NumPy array
data_array = np.array(data)
# Calculate mean, median, and standard deviation
std_dev = np.std(data_array)
mean = np.mean(data_array)
two_std = std_dev * 1
filtered_data = data_array[abs(data_array - mean) < two_std]
median = np.median(filtered_data)
window = 86
moving_avg = np.convolve(filtered_data, np.ones(window) / window, mode="valid")
# Sort data and get the lowest value
lowest_value = np.min(filtered_data)
# Create a figure and plot the data
plt.figure(figsize=(8, 6))
plt.scatter(
range(len(filtered_data)), filtered_data, color="red", label="Filtered Data"
)
plt.plot(
range(window - 1, len(filtered_data)),
moving_avg,
color="blue",
label="Moving Average",
)
plt.axhline(y=median, color="purple", linestyle="--", label=f"Median: {median:.2f}")
# plt.axhline(y=mean, color="yellow", linestyle="--", label=f"Mean: {mean:.2f}")
plt.axhline(y=mean + two_std, color="orange", linestyle="--", label="+1 SD")
# plt.scatter(
# np.where(filtered_data == lowest_value),
# lowest_value,
# color="green",
# label="Lowest Value",
# )
plt.xlabel("Index")
plt.ylabel("Value")
plt.title("Data with Moving Average and Outliers Removed")
plt.legend()
plt.grid(True)
plt.savefig(f"time_logs/graphImages/program_time_trials{data_array.size}.png")
plt.show()
print(f"Mean: {mean:.2f}")
print(f"Median: {median:.2f}")
print(f"Standard Deviation: {std_dev:.2f}")
print(f"Lowest Value: {lowest_value:.2f}")
print(moving_avg[-1])