def get(self): applications = ApplicationModel.find_all() print(type(applications)) list_of_applications = [] for application in applications: list_of_applications.append(application.json()) return list_of_applications
def getAnswerTable(self, experimentId): Experiment = ExperimentModel.find_by_id(experimentId) ExperimentDetailes = ExperimentDetaileModel.find_all_ExperimentDetailes_by_ExperimentID( experimentId) users = UserModel.find_all_user() table = [] Application = ApplicationModel.find_all() Questions = QuestionModel.find_all_Question() dictApp = unionModel.getApplictionsDict(Application) dictUser = unionModel.getUsersDict(users) dictQustion = unionModel.getQustionDict(Questions) Securties = SecurtyModel.find_all_SecurtyFeature() SecurtyDict = unionModel.getSecurtyDict(Securties) generalReports = generalReportModel.find_by_experimentId(experimentId) column = {} column['user'] = '******' column['Traditional_summary_old'] = '-' column['Traditional_summary_new'] = '-' for Securty in Securties: column[SecurtyDict[Securty.id]] = '-' # run on all grop exp j = 0 for i in range(0, Experiment.numberParti): groupExpDict = {} for ExperimentDetaile in ExperimentDetailes: if ExperimentDetaile.groupExp != i: continue j += 1 dictExp = {} strType = "" if ExperimentDetaile.questionDisplay == 1: strType = 'new traditional summary => Security features' else: if ExperimentDetaile.questionDisplay == 2: strType = 'Security features => new traditional summary' else: if ExperimentDetaile.questionDisplay == 3: strType = 'Security features' else: if ExperimentDetaile.questionDisplay == 4: strType = 'old traditional summary' else: strType = 'new traditional summary' key = dictApp[ExperimentDetaile.applicationId] + ': ' + strType dictExp[key] = {} Reports = ReportModel.find_all_report_by_experimentDetailes( ExperimentDetaile.id) for Question in Questions: if (Question.section == 1): columnCopy = column.copy() if (ExperimentDetaile.userID != 0): columnCopy['user'] = dictUser[ ExperimentDetaile.userID] for Report in Reports: if (Report.questionID == Question.id): if Report.part == 1: columnCopy[ 'Traditional_summary_old'] = Report.answer else: if Report.part == 2 and int( Report.securityId) == 0: columnCopy[ 'Traditional_summary_new'] = Report.answer else: columnCopy[SecurtyDict[int( Report.securityId )]] = Report.answer dictExp[key][dictQustion[Question.id]] = columnCopy groupExpDict[j] = dictExp table.append(groupExpDict) # generalReport columnGeneral = {} for Question in Questions: if (Question.section == 2): columnGeneral[dictQustion[Question.id]] = '-' generalDict = {} generalDict['general report'] = {} lastUser = -1 for generalReport in generalReports: if (lastUser == -1 or (lastUser != -1 and lastUser != generalReport.userID)): generalDict['general report'][dictUser[ generalReport.userID]] = copy.deepcopy(columnGeneral) lastUser = generalReport.userID generalDict['general report'][dictUser[generalReport.userID]][ dictQustion[generalReport.questionID]] = generalReport.answer table.append(generalDict) return table
def getExperimentTable(self): Experiments = ExperimentModel.find_all_Experiment() ExperimentApps = ExperimentAppModel.find_all_ExperimentApp() Application = ApplicationModel.find_all() ExperimentDetailes = ExperimentDetaileModel.find_all_ExperimentDetailes( ) users = UserModel.find_all_user() table = [] dictApp = unionModel.getApplictionsDict(Application) dictUser = unionModel.getUsersDict(users) for Experiment in Experiments: column = {} column['id'] = str(Experiment.id) if (str(Experiment.type) == '1'): column['type'] = 'Type 1 experiment' else: if (str(Experiment.type) == '2'): column['type'] = 'Type 2 experiment' else: column['type'] = 'Type 3 experiment' column['Number of participants'] = str(Experiment.numberParti) if (Experiment.run == 1): column['done'] = 'no' else: column['done'] = 'yes' column['app in experiment'] = [] for ExperimentApp in ExperimentApps: if (ExperimentApp.ExperimentId == Experiment.id): column['app in experiment'].append( dictApp[ExperimentApp.applicationId]) column['ExperimentDetaile'] = {} for ExperimentDetaile in ExperimentDetailes: if ExperimentDetaile.ExperimentId == Experiment.id: column['ExperimentDetaile'][ ExperimentDetaile.groupExp] = {} column['ExperimentDetaile'][ ExperimentDetaile.groupExp]['user'] = '******' column['ExperimentDetaile'][ ExperimentDetaile.groupExp]['order'] = [] for ExperimentDetaile in ExperimentDetailes: if ExperimentDetaile.ExperimentId == Experiment.id: if ExperimentDetaile.userID != 0: column['ExperimentDetaile'][ ExperimentDetaile.groupExp]['user'] = dictUser[ ExperimentDetaile.userID] if ExperimentDetaile.questionDisplay == 1: column['ExperimentDetaile'][ExperimentDetaile.groupExp][ 'questionDisplay'] = 'new traditional summary => Security features' else: if ExperimentDetaile.questionDisplay == 2: column['ExperimentDetaile'][ ExperimentDetaile.groupExp][ 'questionDisplay'] = 'Security features => new traditional summary' else: if ExperimentDetaile.questionDisplay == 3: column['ExperimentDetaile'][ ExperimentDetaile.groupExp][ 'questionDisplay'] = 'Security features' else: if ExperimentDetaile.questionDisplay == 4: column['ExperimentDetaile'][ ExperimentDetaile.groupExp][ 'questionDisplay'] = 'old traditional summary' else: column['ExperimentDetaile'][ ExperimentDetaile.groupExp][ 'questionDisplay'] = 'new traditional summary' column['ExperimentDetaile'][ ExperimentDetaile.groupExp]['order'].append( dictApp[ExperimentDetaile.applicationId]) table.append(column) return table