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):
row = Workout.objects.get(id=id)
f1 = row.csvfilename
rowdata = rdata(f1)
try:
rowdata = rdata(f1)
l1 = len(rowdata.df)
except AttributeError:
rowdata = 0
l1 = 0
engine = create_engine(database_url, echo=False)
@@ -300,7 +301,7 @@ def compare_data(id):
engine.dispose()
lfile = l1
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
# don't exist)
@@ -315,21 +316,31 @@ def repair_data(verbose=False):
print w.id,lfile,ldb
try:
rowdata = rdata(w.csvfilename)
if rowdata:
if rowdata and len(rowdata.df):
update_strokedata(w.id,rowdata.df)
except IOError, AttributeError:
pass
if not lfile:
if lfile==0:
# if not ldb - delete workout
try:
data = read_df_sql(w.id)
data.rename(columns = columndict,inplace=True)
res = data.to_csv(w.csvfilename+'.gz',
index_label='index',
compression='gzip')
print 'adding csv file'
try:
datalength = len(data)
except AttributeError:
datalength = 0
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:
print 'failed'
print str(sys.exc_info()[0])
@@ -339,10 +350,10 @@ def repair_data(verbose=False):
def rdata(file,rower=rrower()):
try:
res = rrdata(file,rower=rower)
except IOError:
except IOError,IndexError:
try:
res = rrdata(file+'.gz',rower=rower)
except IOError:
except IOError,IndexError:
res = 0
return res
@@ -445,7 +456,7 @@ def prepmultipledata(ids,verbose=False):
rowdata,row = getrowdata(id=id)
if verbose:
print id
if rowdata:
if rowdata and len(rowdata.df):
data = dataprep(rowdata.df,id=id,bands=True,barchart=True,otwpower=True)
return res

View File

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