import pandas as pd
import numpy as np

march = pd.read_csv('march.csv', names = ['region', 'day', 'rec', 'work'])
april = pd.read_csv('april.csv', names = ['region', 'day', 'rec', 'work'])
may = pd.read_csv('may.csv', names = ['region', 'day', 'rec', 'work'])
june = pd.read_csv('june.csv', names = ['region', 'day', 'rec', 'work'])

print(np.shape(march))
print(np.shape(april))
print(np.shape(may))
print(np.shape(june))

print(np.shape(march.region))
print(357./7.)

i=0

marrecavgs = []
marworkavgs = []
aprrecavgs = []
aprworkavgs = []
mayworkavgs = []
mayrecavgs = []
junrecavgs = []
junworkavgs = []

marrecstate = []
marworkstate = []
aprrecstate = []
aprworkstate = []
mayrecstate = []
mayworkstate = []
junrecstate = []
junworkstate = []

zerolow = 0.
onelow = -26.
twolow = -53.


while i < np.shape(march)[0]:
    marwk = march.iloc[i:i+7]
    marrecavg = np.mean(marwk.rec)
    marworkavg = np.mean(marwk.work)
    marrecavgs.append(marrecavg)
    marworkavgs.append(marworkavg)
    if marrecavg > zerolow:
        marrecstate.append(3)
    elif (marrecavg < zerolow) & (marrecavg > onelow):
        marrecstate.append(2)
    elif (marrecavg < onelow) & (marrecavg > twolow):
        marrecstate.append(1)
    elif marrecavg < twolow:
        marrecstate.append(0)
    if marworkavg > zerolow:
        marworkstate.append(3)
    elif (marworkavg < zerolow) & (marworkavg > onelow):
        marworkstate.append(2)
    elif (marworkavg < onelow) & (marworkavg > twolow):
        marworkstate.append(1)
    elif marworkavg < twolow:
        marworkstate.append(0)
        
    aprwk = april.iloc[i:i+7]
    aprrecavg = np.mean(aprwk.rec)
    aprworkavg = np.mean(aprwk.work)
    aprrecavgs.append(aprrecavg)
    aprworkavgs.append(aprworkavg)
    if aprrecavg >= zerolow:
        aprrecstates.append(3)
    elif (aprrecavg < zerolow) & (aprrecavg >= onelow):
        aprrecstate.append(2)
    elif (aprrecavg < onelow) & (aprrecavg >= twolow):
        aprrecstate.append(1)
    elif aprrecavg < twolow:
        aprrecstate.append(0)
    if aprworkavg >= zerolow:
        aprworkstate.append(3)
    elif (aprworkavg < zerolow) & (aprworkavg >= onelow):
        aprworkstate.append(2)
    elif (aprworkavg < onelow) & (aprworkavg >= twolow):
        aprworkstate.append(1)
    elif aprworkavg < twolow:
        aprworkstate.append(0)
    
    maywk = may.iloc[i:i+7]
    mayrecavg = np.mean(maywk.rec)
    mayworkavg = np.mean(maywk.work)
    mayrecavgs.append(mayrecavg)
    mayworkavgs.append(mayworkavg)
    if mayrecavg > zerolow:
        mayrecstate.append(3)
    elif (mayrecavg < zerolow) & (mayrecavg > onelow):
        mayrecstate.append(2)
    elif (mayrecavg < onelow) & (mayrecavg > twolow):
        mayrecstate.append(1)
    elif mayrecavg < twolow:
        mayrecstate.append(0)
    if mayworkavg > zerolow:
        mayworkstate.append(3)
    elif (mayworkavg < zerolow) & (mayworkavg > onelow):
        mayworkstate.append(2)
    elif (mayworkavg < onelow) & (mayworkavg > twolow):
        mayworkstate.append(1)
    elif mayworkavg < twolow:
        mayworkstate.append(0)
    
    junwk = june.iloc[i:i+7]
    junrecavg = np.mean(junwk.rec)
    junworkavg = np.mean(junwk.work)
    junrecavgs.append(junrecavg)
    junworkavgs.append(junworkavg)
    if junrecavg > zerolow:
        junrecstate.append(3)
    elif (junrecavg < zerolow) & (junrecavg > onelow):
        junrecstate.append(2)
    elif (junrecavg < onelow) & (junrecavg > twolow):
        junrecstate.append(1)
    elif junrecavg < twolow:
        junrecstate.append(0)
    if junworkavg > zerolow:
        junworkstate.append(3)
    elif (junworkavg < zerolow) & (junworkavg > onelow):
        junworkstate.append(2)
    elif (junworkavg < onelow) & (junworkavg > twolow):
        junworkstate.append(1)
    elif junworkavg < twolow:
        junworkstate.append(0)
    i += 7

print(len(marrecavgs))
print(len(aprrecavgs))
print(len(mayrecavgs))
print(len(junrecavgs))
print(len(marworkavgs))
print(len(aprworkavgs))
print(len(mayworkavgs))
print(len(junworkavgs))

print(len(marrecstate))
print(len(aprrecstate))
print(len(mayrecstate))
print(len(junrecstate))
print(len(marworkstate))
print(len(aprworkstate))
print(len(mayworkstate))
print(len(junworkstate))

    

mobility_data_andstates = pd.DataFrame(data={'marrec': marrecavgs, 'aprrec' : aprrecavgs, 'mayrec':mayrecavgs, 'junrec':junrecavgs
                                            ,'marwork':marworkavgs, 'aprwork':aprworkavgs, 'maywork':mayworkavgs, 'junwork':junworkavgs
                                            ,'marrecstates':marrecstate, 'aprrecstates':aprrecstate, 'mayrecstates':mayrecstate, 'junrecstates':junrecstate
                                            ,'marworkstates':marworkstate, 'aprworkstates':aprworkstate, 'mayworkstates':mayworkstate, 'junworkstates':junworkstate})
print(mobility_data_andstates)

#mobility_data_andstates.to_csv('mobility_data_andstates.csv')

