import re
from typing import NamedTuple, Optional, List, Iterator, Callable

import numpy as np
import pandas as pd
import plotly.graph_objs as go
from plotly.offline import plot

from lexos.helpers.definitions import get_words_with_right_boundary, \
    get_single_word_count_in_text
from lexos.models.base_model import BaseModel
from lexos.models.filemanager_model import FileManagerModel
from lexos.models.matrix_model import FileIDContentMap
from lexos.receivers.rolling_windows_receiver import RWAFrontEndOptions, \
    RollingWindowsReceiver, WindowUnitType, RWATokenType, RWARatioTokenOptions,\
    RWAAverageTokenOptions, RWAWindowOptions
from lexos.models.rolling_windows_model import RollingWindowsModel, \
    RWATestOptions


# --------------------test by ratio count-----------------------------------
test_option_one = RWATestOptions(file_id_content_map=
                                 {0: "ha ha ha ha la ta ha",
                                  2: "la la ta ta da da ha",
                                  3: "ta da ha"
                                  },
                                 rolling_windows_options=RWAFrontEndOptions
                                 (ratio_token_options=RWARatioTokenOptions
                                  (token_type=RWATokenType("string"),
                                   numerator_token="ta",
                                   denominator_token="ha"),
                                  average_token_options=RWAAverageTokenOptions
                                  (token_type=RWATokenType(None), tokens=
                                   List[None]), passage_file_id=1,
                                  window_options=RWAWindowOptions
                                  (window_size=3, window_unit=
                                   WindowUnitType("letter")), milestone=None))

@@ -593,16 +593,17 @@
 Options,
+ 
 %5C%0A    RW
@@ -731,17 +731,16 @@
 ptions%0A%0A
-%0A
 # ------
@@ -813,22 +813,27 @@
 --%0Atest_
-option
+ratio_count
 _one = R
@@ -900,16 +900,21 @@
         
+     
 %7B0: %22ha 
@@ -967,16 +967,21 @@
         
+     
 2: %22la l
@@ -1033,16 +1033,21 @@
         
+     
 3: %22ta d
@@ -1052,16 +1052,21 @@
  da ha%22%0A
+     
         
@@ -1127,16 +1127,21 @@
         
+     
 rolling_
@@ -1156,16 +1156,55 @@
 options=
+%0A                                      
 RWAFront
@@ -1247,16 +1247,21 @@
         
+     
 (ratio_t
@@ -1286,32 +1286,36 @@
 tioTokenOptions%0A
+    
                 
@@ -1403,16 +1403,20 @@
         
+    
 numerato
@@ -1464,16 +1464,20 @@
         
+    
 denomina
@@ -1527,16 +1527,21 @@
         
+     
 average_
@@ -1558,152 +1558,1140 @@
 ons=
-RWAAverageTokenOptions%0A                                  (token_type=RWATokenType(None), tokens=%0A                                   List%5BNone%5D),
+None,%0A                                       passage_file_id=1,%0A                                       window_options=RWAWindowOptions%0A                                       (window_size=3, window_unit=%0A                                       WindowUnitType(%22letter%22)),%0A                                       milestone=None))%0A%0Arw_ratio_model_one = RollingWindowsModel(test_option=test_ratio_count_one)%0A#---------------------------------------------------------------------------%0A%0A# --------------------test by average count-----------------------------------%0Atest_average_count_one = RWATestOptions(file_id_content_map=%0A                                      %7B0: %22ha ha ha ha la ta ha%22,%0A                                       2: %22la la ta ta da da ha%22,%0A                                       3: %22ta da ha%22%0A                                       %7D,%0A                                      rolling_windows_options=%0A                                      RWAFrontEndOptions%0A                                      (ratio_token_options=None,%0A                                       average_token_options=,%0A                                      
  pas
@@ -2698,32 +2698,37 @@
 sage_file_id=1,%0A
+     
                 
@@ -2803,32 +2803,37 @@
                 
+     
 (window_size=3, 
@@ -2872,32 +2872,36 @@
                 
+    
 WindowUnitType(%22
@@ -2910,26 +2910,283 @@
 tter%22)),
- milestone=None))
+%0A                                       milestone=None))%0A%0Arw_average_model_one = RollingWindowsModel(test_option=test_average_count_one)%0A#---------------------------------------------------------------------------%0A%0Aprint(%22DONE%22)%0A%0Aclass TestRW:%0A    def test_get_rw_from_list:
 %0A

test average count for rolling window