import matplotlib.pyplot as plt
from resistics.decimate import DecimatedLevelMetadata
from resistics.sampling import to_datetime, to_timedelta
from resistics.window import get_win_table
ref_time = to_datetime("2021-01-01 00:00:00")
fs = 10
n_samples = 1000
first_time = to_datetime("2021-01-01 01:00:00")
last_time = first_time + to_timedelta((n_samples-1)/fs)
metadata = DecimatedLevelMetadata(fs=10, n_samples=1000, first_time=first_time, last_time=last_time)
print(metadata.fs, metadata.first_time, metadata.last_time)
# Expected:
## 10.0 2021-01-01 01:00:00 2021-01-01 01:01:39.9
win_size = 100
olap_size = 25
df = get_win_table(ref_time, metadata, win_size, olap_size)
print(df.to_string())
# Expected:
##     global  local  from_sample  to_sample               win_start                 win_end
## 0      480      0            0         99 2021-01-01 01:00:00.000 2021-01-01 01:00:09.900
## 1      481      1           75        174 2021-01-01 01:00:07.500 2021-01-01 01:00:17.400
## 2      482      2          150        249 2021-01-01 01:00:15.000 2021-01-01 01:00:24.900
## 3      483      3          225        324 2021-01-01 01:00:22.500 2021-01-01 01:00:32.400
## 4      484      4          300        399 2021-01-01 01:00:30.000 2021-01-01 01:00:39.900
## 5      485      5          375        474 2021-01-01 01:00:37.500 2021-01-01 01:00:47.400
## 6      486      6          450        549 2021-01-01 01:00:45.000 2021-01-01 01:00:54.900
## 7      487      7          525        624 2021-01-01 01:00:52.500 2021-01-01 01:01:02.400
## 8      488      8          600        699 2021-01-01 01:01:00.000 2021-01-01 01:01:09.900
## 9      489      9          675        774 2021-01-01 01:01:07.500 2021-01-01 01:01:17.400
## 10     490     10          750        849 2021-01-01 01:01:15.000 2021-01-01 01:01:24.900
## 11     491     11          825        924 2021-01-01 01:01:22.500 2021-01-01 01:01:32.400
## 12     492     12          900        999 2021-01-01 01:01:30.000 2021-01-01 01:01:39.900
#
# Plot six windows to illustrate the overlap
#
plt.figure(figsize=(8, 3)) # doctest: +SKIP
for idx, row in df.iterrows():
    color = "red" if idx%2 == 0 else "blue"
    plt.axvspan(row.loc["win_start"], row.loc["win_end"], alpha=0.5, color=color) # doctest: +SKIP
    if idx > 5:
        break
plt.tight_layout() # doctest: +SKIP
plt.show() # doctest: +SKIP
