code reuse
This commit is contained in:
@@ -1089,82 +1089,37 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
|
||||
|
||||
return (w.id, message)
|
||||
|
||||
parsers = {
|
||||
'xls': ExcelTemplate,
|
||||
'rp': RowProParser,
|
||||
'tcx':TCXParser,
|
||||
'mystery':MysteryParser,
|
||||
'ritmotime':RitmoTimeParser,
|
||||
'quiske': QuiskeParser,
|
||||
'rowperfect3': RowPerfectParser,
|
||||
'coxmate': CoxMateParser,
|
||||
'bcmike': BoatCoachAdvancedParser,
|
||||
'boatcoach': BoatCoachParser,
|
||||
'boatcoachotw': BoatCoachOTWParser,
|
||||
'painsleddesktop': painsledDesktopParser,
|
||||
'speedcoach': speedcoachParser,
|
||||
'speedcoach2': SpeedCoach2Parser,
|
||||
'ergstick': ErgStickParser,
|
||||
'fit': FITParser,
|
||||
'ergdata': ErgDataParser,
|
||||
}
|
||||
|
||||
def parsenonpainsled(fileformat,f2,summary):
|
||||
# handle RowPro:
|
||||
if (fileformat == 'xls'):
|
||||
row = ExcelTemplate(f2)
|
||||
hasrecognized = True
|
||||
|
||||
|
||||
if (fileformat == 'rp'):
|
||||
row = RowProParser(f2)
|
||||
hasrecognized = True
|
||||
|
||||
# handle TCX
|
||||
if (fileformat == 'tcx'):
|
||||
row = TCXParser(f2)
|
||||
hasrecognized = True
|
||||
|
||||
# handle Mystery
|
||||
if (fileformat == 'mystery'):
|
||||
row = MysteryParser(f2)
|
||||
try:
|
||||
row = parsers[fileformat](f2)
|
||||
hasrecognized = True
|
||||
except KeyError:
|
||||
hasrecognized = False
|
||||
|
||||
# handle ritmo
|
||||
if (fileformat == 'ritmotime'):
|
||||
row = RitmoTimeParser(f2)
|
||||
hasrecognized = True
|
||||
|
||||
# handle Quiske
|
||||
if (fileformat == 'quiske'):
|
||||
row = QuiskeParser(f2)
|
||||
hasrecognized = True
|
||||
|
||||
# handle RowPerfect
|
||||
if (fileformat == 'rowperfect3'):
|
||||
row = RowPerfectParser(f2)
|
||||
hasrecognized = True
|
||||
|
||||
# handle ErgData
|
||||
if (fileformat == 'ergdata'):
|
||||
row = ErgDataParser(f2)
|
||||
hasrecognized = True
|
||||
|
||||
# handle CoxMate
|
||||
if (fileformat == 'coxmate'):
|
||||
row = CoxMateParser(f2)
|
||||
hasrecognized = True
|
||||
|
||||
# handle Mike
|
||||
if (fileformat == 'bcmike'):
|
||||
row = BoatCoachAdvancedParser(f2)
|
||||
hasrecognized = True
|
||||
|
||||
# handle BoatCoach
|
||||
if (fileformat == 'boatcoach'):
|
||||
row = BoatCoachParser(f2)
|
||||
hasrecognized = True
|
||||
|
||||
# handle BoatCoach OTW
|
||||
if (fileformat == 'boatcoachotw'):
|
||||
row = BoatCoachOTWParser(f2)
|
||||
hasrecognized = True
|
||||
|
||||
# handle painsled desktop
|
||||
if (fileformat == 'painsleddesktop'):
|
||||
row = painsledDesktopParser(f2)
|
||||
hasrecognized = True
|
||||
|
||||
# handle speed coach GPS
|
||||
if (fileformat == 'speedcoach'):
|
||||
row = speedcoachParser(f2)
|
||||
hasrecognized = True
|
||||
|
||||
# handle speed coach GPS 2
|
||||
if (fileformat == 'speedcoach2'):
|
||||
row = SpeedCoach2Parser(f2)
|
||||
hasrecognized = True
|
||||
|
||||
oarlength, inboard = get_empower_rigging(f2)
|
||||
empowerfirmware = get_empower_firmware(f2)
|
||||
if empowerfirmware != '':
|
||||
@@ -1174,15 +1129,8 @@ def parsenonpainsled(fileformat,f2,summary):
|
||||
summary = row.allstats()
|
||||
|
||||
|
||||
# handle ErgStick
|
||||
if (fileformat == 'ergstick'):
|
||||
row = ErgStickParser(f2)
|
||||
hasrecognized = True
|
||||
|
||||
# handle FIT
|
||||
if (fileformat == 'fit'):
|
||||
row = FITParser(f2)
|
||||
hasrecognized = True
|
||||
try:
|
||||
s = fitsummarydata(f2)
|
||||
s.setsummary()
|
||||
@@ -1318,13 +1266,11 @@ def new_workout_from_file(r, f2,
|
||||
fileformat,
|
||||
summary=summary
|
||||
)
|
||||
print f2,'noot'
|
||||
if not f2:
|
||||
message = 'Something went wrong'
|
||||
return (0, message, '')
|
||||
except Exception as e:
|
||||
errorstring = str(sys.exc_info()[0])
|
||||
print e.message
|
||||
message = 'Something went wrong: ' + e.message
|
||||
return (0, message, '')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user