Commit dee55040 authored by Avisek Naug's avatar Avisek Naug 🎨
Browse files

Update change way date is parsed from excel files

parent 6fa38e3c
......@@ -4,6 +4,7 @@ measurements database.
import json
import os
import re
from datetime import datetime, timedelta
from glob import glob
from urllib.parse import urlencode
......@@ -110,7 +111,17 @@ def weeklysolardata(datafolder: str = './energyfreqanalysis/', weeks: int = 4):
# the controller would create a new file to store measurements for the week
# beginning on monday. The sunday data will belong to the earlier calandar week.
data_files = glob(os.path.join(datafolder, '*store.csv'))
flist = sorted(data_files, key=os.path.getctime, reverse=True)[:weeks+1]
#flist = sorted(data_files, key=os.path.getctime, reverse=True)[:weeks+1]
t1 = [re.findall(r'\d+', t) for t in data_files]
cod = {}
for i in range(len(t1)):
cod[int(t1[i][0]+t1[i][1])]= data_files[i]
for i in [392019,402019,412019, 422019, 432019,442019]:
del cod[i]
t2 = list(cod.keys())
t3 = sorted(t2,reverse=True)
flist = [cod[i] for i in t3[:weeks+1]]
if len(flist) == 0:
warnings.warn('No *store.csv files found containing historical measurements.')
......@@ -123,11 +134,18 @@ def weeklysolardata(datafolder: str = './energyfreqanalysis/', weeks: int = 4):
for filename in flist:
dfr = read_csv(filename,
parse_dates={'Dates': [0]},
names=['Time', 'OAT', 'ORH', 'Ghi', 'Alumni_SAT', 'RL_SAT'],
names=['Dates', 'OAT', 'ORH', 'Ghi', 'Alumni_SAT', 'RL_SAT'],
na_values=['nan', ' nan'],
timelist = []
for i in dfr['Dates']:
temp = to_datetime(i,format='%d-%b-%y %I:%M %p CDT')
temp = to_datetime(i,format='%d-%b-%y %I:%M %p CST')
dfr['Dates'] = np.array(timelist)
df = merge_df_rows(dflist)
......@@ -142,7 +160,7 @@ def weeklysolardata(datafolder: str = './energyfreqanalysis/', weeks: int = 4):
def weeklyrelearndata(solardatapath: str, weeks: int = 4, log: Logger=None):
df1 = weeklybdxdata(weeks = weeks)
df2 = weeklysolardata(datafolder=solardatapath)
df2 = weeklysolardata(datafolder=solardatapath, weeks = weeks)
if df2 is None:
raise FileNotFoundError('Solar data could not be extracted.')
dfrelearn = merge_df_columns([df1, df2])
  • I do not understand what the code is trying to do here with date parsing. Can you comment the code @nauga ?

    It seems you have hardcoded some week numbers where the date format was WW-YYYY instead of the newer YYYY-WW. That is fine but we must make a note to remove that once we are past that period.

Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment