import numpy as np
import matplotlib.pyplot as plt
fs = 10
n_samples = 24
win_size = 8
olap_size = 2
times = np.arange(0, n_samples) * (1/fs)
#
# The first window
#
start_win1 = 0
end_win1 = win_size
win1_times = times[start_win1:end_win1]
#
# The second window
#
start_win2 = end_win1 - olap_size
end_win2 = start_win2 + win_size
win2_times = times[start_win2:end_win2]
#
# The third window
#
start_win3 = end_win2 - olap_size
end_win3 = start_win3 + win_size
win3_times = times[start_win3:end_win3]
#
# The fourth window
#
start_win4= end_win3 - olap_size
end_win4 = start_win4 + win_size
win4_times = times[start_win4:end_win4]
#
# Let's look at the actual window times for each window
#
win1_times
# Expected:
## array([0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7])
win2_times
# Expected:
## array([0.6, 0.7, 0.8, 0.9, 1. , 1.1, 1.2, 1.3])
win3_times
# Expected:
## array([1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9])
win4_times
# Expected:
## array([1.8, 1.9, 2. , 2.1, 2.2, 2.3])
#
# The duration and increments of windows can be calculated using provided
# methods
#
from resistics.window import win_duration, inc_duration
print(win_duration(win_size, fs))
# Expected:
## 0:00:00.7
print(inc_duration(win_size, olap_size, fs))
# Expected:
## 0:00:00.6
#
# Plot the windows to give an illustration of how it works
#
plt.plot(win1_times, np.ones_like(win1_times), "bo", label="window1") # doctest: +SKIP
plt.plot(win2_times, np.ones_like(win2_times)*2, "ro", label="window2") # doctest: +SKIP
plt.plot(win3_times, np.ones_like(win3_times)*3, "go", label="window3") # doctest: +SKIP
plt.plot(win4_times, np.ones_like(win4_times)*4, "co", label="window4") # doctest: +SKIP
plt.xlabel("Time [s]") # doctest: +SKIP
plt.legend() # doctest: +SKIP
plt.grid() # doctest: +SKIP
plt.tight_layout() # doctest: +SKIP
plt.show() # doctest: +SKIP
