Private
Public Access
1
0

completed cleanup routines

This commit is contained in:
Sander Roosendaal
2017-01-24 17:01:38 +01:00
parent f4108ee40f
commit 800934e12a
2 changed files with 25 additions and 15 deletions

View File

@@ -280,10 +280,11 @@ def new_workout_from_file(r,f2,
def compare_data(id): def compare_data(id):
row = Workout.objects.get(id=id) row = Workout.objects.get(id=id)
f1 = row.csvfilename f1 = row.csvfilename
rowdata = rdata(f1)
try: try:
rowdata = rdata(f1)
l1 = len(rowdata.df) l1 = len(rowdata.df)
except AttributeError: except AttributeError:
rowdata = 0
l1 = 0 l1 = 0
engine = create_engine(database_url, echo=False) engine = create_engine(database_url, echo=False)
@@ -300,7 +301,7 @@ def compare_data(id):
engine.dispose() engine.dispose()
lfile = l1 lfile = l1
ldb = l2 ldb = l2
return l1==l2,ldb,lfile return l1==l2 and l1 != 0,ldb,lfile
# Repair data for workouts where the CSV file is lost (or the DB entries # Repair data for workouts where the CSV file is lost (or the DB entries
# don't exist) # don't exist)
@@ -315,21 +316,31 @@ def repair_data(verbose=False):
print w.id,lfile,ldb print w.id,lfile,ldb
try: try:
rowdata = rdata(w.csvfilename) rowdata = rdata(w.csvfilename)
if rowdata: if rowdata and len(rowdata.df):
update_strokedata(w.id,rowdata.df) update_strokedata(w.id,rowdata.df)
except IOError, AttributeError: except IOError, AttributeError:
pass pass
if not lfile: if lfile==0:
# if not ldb - delete workout # if not ldb - delete workout
try: try:
data = read_df_sql(w.id) data = read_df_sql(w.id)
data.rename(columns = columndict,inplace=True) try:
res = data.to_csv(w.csvfilename+'.gz', datalength = len(data)
index_label='index', except AttributeError:
compression='gzip') datalength = 0
print 'adding csv file'
if datalength != 0:
data.rename(columns = columndict,inplace=True)
res = data.to_csv(w.csvfilename+'.gz',
index_label='index',
compression='gzip')
print 'adding csv file'
else:
print w.id,' No stroke records anywhere'
w.delete()
except: except:
print 'failed' print 'failed'
print str(sys.exc_info()[0]) print str(sys.exc_info()[0])
@@ -339,10 +350,10 @@ def repair_data(verbose=False):
def rdata(file,rower=rrower()): def rdata(file,rower=rrower()):
try: try:
res = rrdata(file,rower=rower) res = rrdata(file,rower=rower)
except IOError: except IOError,IndexError:
try: try:
res = rrdata(file+'.gz',rower=rower) res = rrdata(file+'.gz',rower=rower)
except IOError: except IOError,IndexError:
res = 0 res = 0
return res return res
@@ -445,7 +456,7 @@ def prepmultipledata(ids,verbose=False):
rowdata,row = getrowdata(id=id) rowdata,row = getrowdata(id=id)
if verbose: if verbose:
print id print id
if rowdata: if rowdata and len(rowdata.df):
data = dataprep(rowdata.df,id=id,bands=True,barchart=True,otwpower=True) data = dataprep(rowdata.df,id=id,bands=True,barchart=True,otwpower=True)
return res return res

View File

@@ -143,10 +143,10 @@ def error403_view(request):
def rdata(file,rower=rrower()): def rdata(file,rower=rrower()):
try: try:
res = rrdata(file,rower=rower) res = rrdata(file,rower=rower)
except IOError: except IOError, IndexError:
try: try:
res = rrdata(file+'.gz',rower=rower) res = rrdata(file+'.gz',rower=rower)
except IOError: except IOError, IndexError:
res = 0 res = 0
return res return res
@@ -3047,7 +3047,6 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
f1 = row.csvfilename f1 = row.csvfilename
u = request.user u = request.user
r = Rower.objects.get(user=u) r = Rower.objects.get(user=u)
rowdata = rdata(f1) rowdata = rdata(f1)
hascoordinates = 1 hascoordinates = 1
if rowdata != 0: if rowdata != 0: