#code to calculate flux of membranes
import csv
import datetime as dt
from datetime import date, timedelta, datetime
import os



yesterday = date.today() - timedelta(days=1)
year = yesterday.year
month = yesterday.month
day = yesterday.day
#for day in range(1,7):
#print(day)
power1 = "flow"
power2 = "pressure"

## /home/addotson/data_AWSC/raw/

filename1 = "/home/addotson/data_AWSC/raw/{0}_{1}_{2}_conex-{3}".format(year, $
filename2 = "/home/addotson/data_AWSC/raw/{0}_{1}_{2}_conex-{3}".format(year, $

#filename1 = "/users/EnvEngineering/flux/{0}_{1}_{2}_conex-{3}".format(year, m$
#filename2 = "/users/EnvEngineering/flux/{0}_{1}_{2}_conex-{3}".format(year, m$
i=1
csv_reader1 = csv.reader(open(filename1+".csv"))
next(csv_reader1) #ignore headers
for line in csv_reader1:
    i=i+1
i=i+40
intpf=[0 for j in range(i)]
gwrf=[0 for j in range(i)]
intrf=[0 for j in range(i)]
wwpf=[0 for j in range(i)]
y=[0 for j in range(i)]
ddayroflux=0
dayroflow=0
dayropress=0
daynfflux=0
daynfflow=0
daynfpress=0
pf1=0
pf2=0
pf3=0
j=0
csv_reader1 = csv.reader(open(filename1+".csv"))
next(csv_reader1)
for line in csv_reader1:
    #print(j)
    gwrf[j]=(float(line[1]))
    intrf[j]=(float(line[2]))
    intpf[j]=(float(line[3]))
    wwpf[j]=(float(line[4]))
    y[j]=(line[0])
    j=j+1
############## pressure reading
#csv_reader1 = csv.reader(open(filename2+".csv"))
############## pressure reading
#csv_reader1 = csv.reader(open(filename2+".csv"))
i1=1
csv_reader1 = csv.reader(open(filename1+".csv"))
next(csv_reader1) #ignore headers
for line in csv_reader1:
    i1=i1+1
i1=i1+40
feed=[0 for j in range(i1)]
gwrp=[0 for j in range(i1)]
intrp=[0 for j in range(i1)]
fltr1=[0 for j in range(i1)]
fltr2=[0 for j in range(i1)]
y1=[0 for j in range(i1)]
j=0
csv_reader1 = csv.reader(open(filename2+".csv"))
next(csv_reader1)
for line in csv_reader1:
    #print(j)
    feed[j]=(float(line[1]))
    gwrp[j]=(float(line[2]))
    intrp[j]=(float(line[3]))
    fltr1[j]=(float(line[4]))
    fltr2[j]=(float(line[5]))
    y1[j]=(line[0])
    j=j+1
j=0
if y1[j]==y[j]:#make sure timestamps are equal
    err=0
    err1=0
else: