# -*- coding: utf-8 -*-
"""
Created on Mon Jun 10 13:32:29 2024

@author: chuffard
"""

import numpy as np

import pandas as pd

from datetime import datetime

import statistics

import statsmodels.tsa.stattools as sts

from statsmodels.tsa.stattools import acf

import pyflakes as pyf

from pandas import read_csv

import itertools

import re

from scipy import stats


#TRIGGERS ONCE< AT END
# read in data; use first line as header
#Main_Hourly_SES_MARS = pd.read_csv('G:/Analyses/MainSES_fluoro_atn_moon_sun_current.csv', parse_dates=True, index_col="datetime")

# read in data; use first line as header
MOCK_data_Trigger = pd.read_csv('G:/Analyses/triggering/trigger testing TT/SESdata_MOCK_TRIGGER_TRIM.csv', parse_dates=True, index_col="Date_time")

#find the rolling mean= 150 samples, minimum sample size 23.
MOCK_data_Trigger['rm150'] = MOCK_data_Trigger['atn'].rolling(150, min_periods=23).mean()

#Find the difference (slope)
MOCK_data_Trigger['Slope_rm_150'] = MOCK_data_Trigger['rm150'].diff()

#drop the first 150 samples
MOCK_data_Trigger_USE = MOCK_data_Trigger.iloc[151:, ]

trigger = 0.01110322671999997

#make that new max the trigger
MOCK_data_Trigger_USE["trigger150slopeAdf"] = np.where(MOCK_data_Trigger_USE['Slope_rm_150'] >= trigger, 'TriggerSlope', 'WaitSlope')


#DOESN"T TRIGGER 
# read in data; use first line as header
#Main_Hourly_SES_MARS = pd.read_csv('G:/Analyses/MainSES_fluoro_atn_moon_sun_current.csv', parse_dates=True, index_col="datetime")

# read in data; use first line as header
MOCK_data_NO_Trigger = pd.read_csv('G:/Analyses/triggering/trigger testing TT/SESdata_MOCK_NO_TRIGGER_TRIM.csv', parse_dates=True, index_col="Date_time")

#find the rolling mean= 150 samples, minimum sample size 23.
MOCK_data_NO_Trigger['rm150'] = MOCK_data_NO_Trigger['atn'].rolling(150, min_periods=23).mean()

#Find the difference (slope)
MOCK_data_NO_Trigger['Slope_rm_150'] = MOCK_data_NO_Trigger['rm150'].diff()

#drop the first 150 samples
MOCK_data_NO_Trigger_USE = MOCK_data_NO_Trigger.iloc[151:, ]

trigger = 0.01110322671999997

#make that new max the trigger
MOCK_data_NO_Trigger_USE["trigger150slopeAdf"] = np.where(MOCK_data_NO_Trigger_USE['Slope_rm_150'] >= trigger, 'TriggerSlope', 'WaitSlope')
