def _construct_result_object(self, currentErrors, currentMeanError, oldErrors, oldMeanError): currentErrors = map(lambda x, y: [x, y], list(xrange(len(currentErrors))), currentErrors) currentMeanError = [[0, currentMeanError], [len(currentErrors) - 1, currentMeanError]] oldErrors = map(lambda x, y: [x, y], list(xrange(len(oldErrors))), oldErrors) oldMeanError = [[0, oldMeanError], [len(oldErrors) - 1, oldMeanError]] plotData = [] plotData.append( moduleUtilities.construct_single_plotdata(data=currentErrors, legend="currentErrors", subtype="lines")) plotData.append( moduleUtilities.construct_single_plotdata( data=currentMeanError, legend="currentMeanError", subtype="lines")) plotData.append( moduleUtilities.construct_single_plotdata(data=oldErrors, legend="oldErrors", subtype="lines")) plotData.append( moduleUtilities.construct_single_plotdata(data=oldMeanError, legend="oldMeanError", subtype="lines")) plotResult = [ moduleUtilities.construct_plotresult(title="Peak errors", plotDatas=plotData, priority=1, x_label="Time", y_label="Weight (kg)") ] return moduleUtilities.construct_results_object(plotResult)
def analyse(self, username, configParams, dbHandler, logger): logger.info("Starting analysis scatter... " + username) varX = configParams[PARAM_DIAGRAM_X_AXIS_VARIABLE] varY = configParams[PARAM_DIAGRAM_Y_AXIS_VARIABLE] gender = configParams[PARAM_REHAB_SET_SELECTION_GENDER] birthYear = configParams[PARAM_REHAB_SET_SELECTION_BIRTH_YEAR] weight = configParams[PARAM_REHAB_SET_SELECTION_WEIGHT] height = configParams[PARAM_REHAB_SET_SELECTION_HEIGHT] progress = configParams[PARAM_REHAB_SET_SELECTION_PROGRESS] condition = configParams[PARAM_REHAB_SET_SELECTION_CONDITION] exercise = configParams[PARAM_REHAB_SET_SELECTION_EXERCISE] duration = configParams[PARAM_REHAB_SET_SELECTION_DURATION] birthYearMin = 1900 birthYearMax = 2015 if (birthYear != ""): minusIndex = birthYear.find('-') if (minusIndex != -1): birthYearMin = int(birthYear[:minusIndex]) birthYearMax = int(birthYear[minusIndex + 1:]) else: birthYearMin = int(birthYear) birthYearMax = int(birthYear) if (birthYearMin > birthYearMax): tmp = birthYearMin birthYearMin = birthYearMax birthYearMax = tmp weightMin = 0 weightMax = 200 if (weight != ""): minusIndex = weight.find('-') if (minusIndex != -1): weightMin = int(weight[:minusIndex]) weightMax = int(weight[minusIndex + 1:]) else: weightMin = int(weight) weightMax = int(weight) if (weightMin > weightMax): tmp = weightMin weightMin = weightMax weightMax = tmp heightMin = 0 heightMax = 250 if (height != ""): minusIndex = height.find('-') if (minusIndex != -1): heightMin = int(height[:minusIndex]) heightMax = int(height[minusIndex + 1:]) else: heightMin = int(height) heightMax = int(height) if (heightMin > heightMax): tmp = heightMin heightMin = heightMax heightMax = tmp progressMin = 0 progressMax = 100 if (progress != ""): minusIndex = progress.find('-') if (minusIndex != -1): progressMin = int(progress[:minusIndex]) progressMax = int(progress[minusIndex + 1:]) else: progressMin = int(progress) progressMax = int(progress) if (progressMin > progressMax): tmp = progressMin progressMin = progressMax progressMax = tmp durationMin = 0 durationMax = 10000 if (duration != ""): minusIndex = duration.find('-') if (minusIndex != -1): durationMin = int(duration[:minusIndex]) durationMax = int(duration[minusIndex + 1:]) else: durationMin = int(duration) durationMax = int(duration) if (durationMin > durationMax): tmp = durationMin durationMin = durationMax durationMax = tmp rehabSetResult = json.loads( dbHandler.list_rehabilitationsets(username)) rehabSets = [] if rehabSetResult.get("status_code") == "200": rehabSetArray = rehabSetResult.get("RehabilitationSets") for rehabSet in rehabSetArray: rehabSetId = rehabSet.get("rehabilitationSetID") _rehabSet = self.createRehabSet(rehabSetId) rehabSets.append(_rehabSet) patientInfoID = rehabSet.get("patientInformationID") patientInfoResult = json.loads( dbHandler.get_patientinformation(username, patientInfoID)) if patientInfoResult.get("status_code") == "200": patientInfoArray = patientInfoResult.get( "PatientInformation") for patientInfo in patientInfoArray: _rehabSet['gender'] = patientInfo.get("gender") _rehabSet['height'] = int( patientInfo.get("bodyHeight")) _rehabSet['weight'] = int( patientInfo.get("bodyWeight")) _rehabSet['birthYear'] = int( patientInfo.get("birthYear")) patientCondIDs = rehabSet.get("patientConditionIDs").split(";") for patientCondID in patientCondIDs: patientCondResult = json.loads( dbHandler.get_patientcondition(username, patientCondID)) if patientCondResult.get("status_code") == "200": patientCondArray = patientCondResult.get( "PatientCondition") for patientCond in patientCondArray: _rehabSet['condition'] = patientCond.get("label") exerciseCount = 0 _rehabSet['nrOfExercises'] = 0 _rehabSet['progressIncr'] = 0 _rehabSet['duration'] = 0 exerciseResultIdsStr = rehabSet.get("exerciseResultIDs") if (exerciseResultIdsStr != ""): latestExerciseTime = 0 earliestProgress = 0 latestProgress = 0 earliestExerciseTime = 0 exerciseResultIdsArr = exerciseResultIdsStr.split(";") _rehabSet['nrOfExercises'] = len(exerciseResultIdsArr) for exerciseId in exerciseResultIdsArr: exerciseResult = json.loads( dbHandler.get_exerciseresult(username, exerciseId)) if exerciseResult.get("status_code") == "200": exerciseDataArr = exerciseResult.get( "ExerciseResult") for exerciseData in exerciseDataArr: _rehabSet['exercise'] = exerciseData.get( "exerciseID") started = exerciseData.get("started") if 0 == latestExerciseTime or int( started) > latestExerciseTime: latestExerciseTime = int(started) progress = exerciseData.get("progress") if progress != None and progress != "": latestProgress = int(progress) _rehabSet['progress'] = int(progress) if 0 == earliestExerciseTime or int( started) < earliestExerciseTime: earliestExerciseTime = int(started) earliestProgress = int( exerciseData.get("progress")) _rehabSet['duration'] = (latestExerciseTime - earliestExerciseTime) / (60 * 60 * 24) _rehabSet['progressIncr'] = (latestProgress - earliestProgress) else: logger.debug("ERROR - Couldn't get rehab set list!") rehabSets = self.filterRange(rehabSets, 'birthYear', birthYearMin, birthYearMax, logger) rehabSets = self.filterRange(rehabSets, 'weight', weightMin, weightMax, logger) rehabSets = self.filterRange(rehabSets, 'height', heightMin, heightMax, logger) rehabSets = self.filterRange(rehabSets, 'progress', progressMin, progressMax, logger) rehabSets = self.filterRange(rehabSets, 'duration', durationMin, durationMax, logger) rehabSets = self.filterValue(rehabSets, 'gender', gender, logger) rehabSets = self.filterValue(rehabSets, 'condition', condition, logger) rehabSets = self.filterValue(rehabSets, 'exercise', exercise, logger) variableData = [] for rehabSet in rehabSets: data = [] data.append(self.getRehabSetAttribute(rehabSet, varX)) data.append(self.getRehabSetAttribute(rehabSet, varY)) data.append(rehabSet['id'] + "<br>" + str(rehabSet['gender']) + "<br>" + str(rehabSet['birthYear']) + " / " + str(rehabSet['weight']) + " kg / " + str(rehabSet['height']) + " cm<br>" + rehabSet['condition'] + "<br>" + str(rehabSet['duration']) + " days / " + str(rehabSet['nrOfExercises']) + " exercises<br>" + str(rehabSet['progress']) + " / " + str(rehabSet['progressIncr']) + " incr") variableData.append(data) plotData = [] plotData.append( moduleUtilities.construct_single_plotdata(data=variableData, legend="", subtype="points")) plotResult = [ moduleUtilities.construct_plotresult(title="", plotDatas=plotData, priority=1, x_label=varX, y_label=varY) ] result = moduleUtilities.construct_results_object(plotResult) return result
def analyse(self, username, configParams, dbHandler, logger): logger.info("Starting group analysis ... " + username) rehabSetId = configParams[PARAM_DIAGRAM_REHABLITATION_SET] varY = configParams[PARAM_DIAGRAM_Y_AXIS_VARIABLE] gender = configParams[PARAM_REHAB_SET_SELECTION_GENDER] birthYear = configParams[PARAM_REHAB_SET_SELECTION_BIRTH_YEAR] weight = configParams[PARAM_REHAB_SET_SELECTION_WEIGHT] height = configParams[PARAM_REHAB_SET_SELECTION_HEIGHT] condition = configParams[PARAM_REHAB_SET_SELECTION_CONDITION] exercise = configParams[PARAM_REHAB_SET_SELECTION_EXERCISE] duration = configParams[PARAM_REHAB_SET_SELECTION_DURATION] progressStart = configParams[PARAM_REHAB_SET_SELECTION_START_PROGRESS] birthYearMin = 1900 birthYearMax = 2015 if (birthYear != ""): minusIndex = birthYear.find('-') if (minusIndex != -1): birthYearMin = int(birthYear[:minusIndex]) birthYearMax = int(birthYear[minusIndex + 1:]) else: birthYearMin = int(birthYear) birthYearMax = int(birthYear) if (birthYearMin > birthYearMax): tmp = birthYearMin birthYearMin = birthYearMax birthYearMax = tmp weightMin = 0 weightMax = 200 if (weight != ""): minusIndex = weight.find('-') if (minusIndex != -1): weightMin = int(weight[:minusIndex]) weightMax = int(weight[minusIndex + 1:]) else: weightMin = int(weight) weightMax = int(weight) if (weightMin > weightMax): tmp = weightMin weightMin = weightMax weightMax = tmp heightMin = 0 heightMax = 250 if (height != ""): minusIndex = height.find('-') if (minusIndex != -1): heightMin = int(height[:minusIndex]) heightMax = int(height[minusIndex + 1:]) else: heightMin = int(height) heightMax = int(height) if (heightMin > heightMax): tmp = heightMin heightMin = heightMax heightMax = tmp progressStartMin = 0 progressStartMax = 100 if (progressStart != ""): minusIndex = progressStart.find('-') if (minusIndex != -1): progressStartMin = int(progressStart[:minusIndex]) progressStartMax = int(progressStart[minusIndex + 1:]) else: progressStartMin = int(progressStart) progressStartMax = int(progressStart) if (progressStartMin > progressStartMax): tmp = progressStartMin progressStartMin = progressStartMax progressStartMax = tmp rehabSetResult = json.loads( dbHandler.list_rehabilitationsets(username)) rehabSetDatas = [] rehabsSetData = [] if rehabSetResult.get("status_code") == "200": rehabSetArray = rehabSetResult.get("RehabilitationSets") for rehabSet in rehabSetArray: doFilter = True patientInfoID = rehabSet.get("patientInformationID") if rehabSetId == rehabSet.get("rehabilitationSetID"): doFilter = False patientInfoResult = json.loads( dbHandler.get_patientinformation(username, patientInfoID)) rehabSetOk = True progressStart = self.getRehabilitationProgressStart( dbHandler, username, rehabSet) if doFilter and True != self.filterRange( progressStart, progressStartMin, progressStartMax, logger): continue patientWeight = 0 if patientInfoResult.get("status_code") == "200": patientInfoArray = patientInfoResult.get( "PatientInformation") for patientInfo in patientInfoArray: if doFilter and True != self.filterRange( int(patientInfo.get("birthYear")), birthYearMin, birthYearMax, logger): rehabSetOk = False break patientWeight = int(patientInfo.get("bodyWeight")) if doFilter and True != self.filterRange( patientWeight, weightMin, weightMax, logger): rehabSetOk = False break if doFilter and True != self.filterRange( int(patientInfo.get("bodyHeight")), heightMin, heightMax, logger): rehabSetOk = False break if doFilter and True != self.filterValue( patientInfo.get("gender"), gender, logger): rehabSetOk = False break if True != rehabSetOk: continue patientCondIDs = rehabSet.get("patientConditionIDs").split(";") for patientCondID in patientCondIDs: patientCondResult = json.loads( dbHandler.get_patientcondition(username, patientCondID)) if patientCondResult.get("status_code") == "200": patientCondArray = patientCondResult.get( "PatientCondition") for patientCond in patientCondArray: if doFilter and True != self.filterValue( patientCond.get("label"), condition, logger): rehabSetOk = False break if True != rehabSetOk: continue data = self.gatherExerciseResultDatas(dbHandler, username, rehabSet, varY) if varY == VARIABLE_TARGET or varY == VARIABLE_PEAK_MEAN: data = self.divideDataValues(data, patientWeight / 100.0, logger) if rehabSetId == rehabSet.get("rehabilitationSetID"): rehabSetData = data else: rehabSetDatas.append(data) else: logger.debug("ERROR - Couldn't get rehab set list!") meanData = [] exerciseNumber = 1 doContinue = True while (doContinue): valueTot = 0.0 rehabSetsTot = 0 for data in rehabSetDatas: for tuple in data: if tuple[0] == exerciseNumber: valueTot = valueTot + tuple[1] rehabSetsTot = rehabSetsTot + 1 break if rehabSetsTot > 0: valueMean = valueTot / rehabSetsTot meanData.append( [exerciseNumber, valueMean, "value=" + str(valueMean)]) else: doContinue = False exerciseNumber = exerciseNumber + 1 plotData = [] plotData.append( moduleUtilities.construct_single_plotdata( data=rehabSetData, legend="set", subtype="lines_and_points")) plotData.append( moduleUtilities.construct_single_plotdata( data=meanData, legend="mean", subtype="lines_and_points")) plotResult = [ moduleUtilities.construct_plotresult(title="", plotDatas=plotData, priority=1, x_label="exercise", y_label=varY) ] result = moduleUtilities.construct_results_object(plotResult) return result