def performEventDurationTest():
    mahal_timeseries = readOutlierScores("results/outlier_scores.csv")
    global_pace_timeseries = readGlobalPace("4year_features")
    zscore_timeseries = readZScoresTimeseries("results/zscore.csv")
    
    mahal_timeseries_fine = readOutlierScores("results/link_20_normalize_outlier_scores.csv")
    
    threshold_vals = [.90,.91,.92,.93,.94,.95,.96,.97,.98,.99]
    window_sizes = [1,2,3,4,6,8,12,24]
    with open('results/threshold_experiment.csv', 'w') as f:
        w = csv.writer(f)
        w.writerow(['granularity', 'window','threshold', 'duration'])
        
        for window_size in window_sizes:
            for threshold in threshold_vals:
                print (window_size, threshold)
                events = detectWindowedEvents(mahal_timeseries, zscore_timeseries, global_pace_timeseries, 
                      "results/events_windowed.csv", window_size=window_size, threshold_quant=threshold)
                duration = getEventDuration(events, "2012-10-31")
                w.writerow(["coarse", window_size, threshold, duration])
    
    
                events= detectWindowedEvents(mahal_timeseries_fine, zscore_timeseries, global_pace_timeseries, 
                    "results/link_20_normalize_events_windowed.csv", window_size=window_size,
                    threshold_quant=threshold)      
                duration = getEventDuration(events, "2012-10-31")
                w.writerow(["fine", window_size, threshold, duration])
def performEventDurationTest():
    mahal_timeseries = readOutlierScores("results/outlier_scores.csv")
    global_pace_timeseries = readGlobalPace("4year_features")
    zscore_timeseries = readZScoresTimeseries("results/zscore.csv")

    mahal_timeseries_fine = readOutlierScores(
        "results/link_20_normalize_outlier_scores.csv")

    threshold_vals = [.90, .91, .92, .93, .94, .95, .96, .97, .98, .99]
    window_sizes = [1, 2, 3, 4, 6, 8, 12, 24]
    with open('results/threshold_experiment.csv', 'w') as f:
        w = csv.writer(f)
        w.writerow(['granularity', 'window', 'threshold', 'duration'])

        for window_size in window_sizes:
            for threshold in threshold_vals:
                print(window_size, threshold)
                events = detectWindowedEvents(mahal_timeseries,
                                              zscore_timeseries,
                                              global_pace_timeseries,
                                              "results/events_windowed.csv",
                                              window_size=window_size,
                                              threshold_quant=threshold)
                duration = getEventDuration(events, "2012-10-31")
                w.writerow(["coarse", window_size, threshold, duration])

                events = detectWindowedEvents(
                    mahal_timeseries_fine,
                    zscore_timeseries,
                    global_pace_timeseries,
                    "results/link_20_normalize_events_windowed.csv",
                    window_size=window_size,
                    threshold_quant=threshold)
                duration = getEventDuration(events, "2012-10-31")
                w.writerow(["fine", window_size, threshold, duration])
    
    
                events= detectWindowedEvents(mahal_timeseries_fine, zscore_timeseries, global_pace_timeseries, 
                    "results/link_20_normalize_events_windowed.csv", window_size=window_size,
                    threshold_quant=threshold)      
                duration = getEventDuration(events, "2012-10-31")
                w.writerow(["fine", window_size, threshold, duration])
                          
                




if(__name__=="__main__"):
    #performEventDurationTest()    
    
    mahal_timeseries = readOutlierScores("results/outlier_scores.csv")
    global_pace_timeseries = readGlobalPace("4year_features")
    zscore_timeseries = readZScoresTimeseries("results/zscore.csv")
    detectWindowedEvents(mahal_timeseries, zscore_timeseries, global_pace_timeseries, 
                          "results/events_windowed.csv", window_size=8, threshold_quant=.95)
    
    mahal_timeseries = readOutlierScores("results/link_20_normalize_outlier_scores.csv")
    global_pace_timeseries = readGlobalPace("4year_features")
    zscore_timeseries = readZScoresTimeseries("results/zscore.csv")
    detectWindowedEvents(mahal_timeseries, zscore_timeseries, global_pace_timeseries, 
                          "results/link_20_normalize_events_windowed.csv", window_size=8,
                          threshold_quant=.95)                  
                          
                          
    logMsg("done")
                events = detectWindowedEvents(
                    mahal_timeseries_fine,
                    zscore_timeseries,
                    global_pace_timeseries,
                    "results/link_20_normalize_events_windowed.csv",
                    window_size=window_size,
                    threshold_quant=threshold)
                duration = getEventDuration(events, "2012-10-31")
                w.writerow(["fine", window_size, threshold, duration])


if (__name__ == "__main__"):
    #performEventDurationTest()

    mahal_timeseries = readOutlierScores("results/outlier_scores.csv")
    global_pace_timeseries = readGlobalPace("4year_features")
    zscore_timeseries = readZScoresTimeseries("results/zscore.csv")
    detectWindowedEvents(mahal_timeseries,
                         zscore_timeseries,
                         global_pace_timeseries,
                         "results/events_windowed.csv",
                         window_size=8,
                         threshold_quant=.95)

    mahal_timeseries = readOutlierScores(
        "results/link_20_normalize_outlier_scores.csv")
    global_pace_timeseries = readGlobalPace("4year_features")
    zscore_timeseries = readZScoresTimeseries("results/zscore.csv")
    detectWindowedEvents(mahal_timeseries,
                         zscore_timeseries,