def setReportPart2(self, userID, request): # one part => Traditional approach - total image questionID,answer,experimentId allQuestions = QuestionModel.find_all_Question() questions = [] for question in allQuestions: if question.section == 2: questions.append(question) type1Ids = [] type2Ids = [] type3Ids = [] for question in questions: if (question.type == 1): type1Ids.append(question.id) else: if (question.type == 2): type2Ids.append(question.id) else: type3Ids.append(question.id) tempStr = '$answer[0][]' answers = request.form.getlist(tempStr) if (len(answers) == 0): return indexAnswer = 0 ExperimentId = UserModel.find_by_id(userID).ExperimentId for j in range(0, len(type1Ids)): questionId = type1Ids[j] answer = answers[indexAnswer] indexAnswer += 1 generalReport = generalReportModel(questionId, answer, ExperimentId, userID) generalReport.save_to_db() for j in range(0, len(type2Ids)): questionId = type2Ids[j] answer = answers[indexAnswer] indexAnswer += 1 generalReport = generalReportModel(questionId, answer, ExperimentId, userID) generalReport.save_to_db() for j in range(0, len(type3Ids)): questionId = type3Ids[j] answer = answers[indexAnswer] indexAnswer += 1 generalReport = generalReportModel(questionId, answer, ExperimentId, userID) generalReport.save_to_db()
def setReport(self, userID, expId, request): ExperimentDetaile = saverModel.getExperimentDetaile(userID, expId) allQuestions = QuestionModel.find_all_Question() questions = [] for question in allQuestions: if question.section == 1: questions.append(question) type1Ids = [] type2Ids = [] type3Ids = [] for question in questions: if (question.type == 1): type1Ids.append(question.id) else: if (question.type == 2): type2Ids.append(question.id) else: type3Ids.append(question.id) if (ExperimentDetaile.questionDisplay == 1): # first part => Traditional approach tempStr = '$answer[0][]' answers = request.form.getlist(tempStr) indexAnswer = 0 ExperimentDetaileID = ExperimentDetaile.id for j in range(0, len(type1Ids)): questionId = type1Ids[j] answer = answers[indexAnswer] part = 2 securtyID = 0 indexAnswer += 1 report = ReportModel(ExperimentDetaileID, questionId, answer, part, securtyID) report.save_to_db() for j in range(0, len(type2Ids)): questionId = type2Ids[j] answer = answers[indexAnswer] part = 2 securtyID = 0 indexAnswer += 1 report = ReportModel(ExperimentDetaileID, questionId, answer, part, securtyID) report.save_to_db() for j in range(0, len(type3Ids)): questionId = type3Ids[j] answer = answers[indexAnswer] part = 2 securtyID = 0 indexAnswer += 1 report = ReportModel(ExperimentDetaileID, questionId, answer, part, securtyID) report.save_to_db() # secind part => Contextual approach - fitzer image rowsNum = len(helper.getAppImage( ExperimentDetaile.applicationId)) - 2 SecurtyIds = helper.getSecurtyIds(ExperimentDetaile.applicationId) i = 1 for SecurtyId in SecurtyIds: tempStr = '$answer[' + str(i) + '][]' answers = request.form.getlist(tempStr) indexAnswer = 0 ExperimentDetaileID = ExperimentDetaile.id for j in range(0, len(type1Ids)): questionId = type1Ids[j] answer = answers[indexAnswer] part = 2 securtyID = SecurtyId indexAnswer += 1 report = ReportModel(ExperimentDetaileID, questionId, answer, part, securtyID) report.save_to_db() for j in range(0, len(type2Ids)): questionId = type2Ids[j] answer = answers[indexAnswer] part = 2 securtyID = SecurtyId indexAnswer += 1 report = ReportModel(ExperimentDetaileID, questionId, answer, part, securtyID) report.save_to_db() for j in range(0, len(type3Ids)): questionId = type3Ids[j] answer = answers[indexAnswer] part = 2 securtyID = SecurtyId indexAnswer += 1 report = ReportModel(ExperimentDetaileID, questionId, answer, part, securtyID) report.save_to_db() i += 1 else: if (ExperimentDetaile.questionDisplay == 2): # first part => Contextual approach SecurtyIds = helper.getSecurtyIds( ExperimentDetaile.applicationId) i = 0 for SecurtyId in SecurtyIds: tempStr = '$answer[' + str(i) + '][]' answers = request.form.getlist(tempStr) indexAnswer = 0 ExperimentDetaileID = ExperimentDetaile.id for j in range(0, len(type1Ids)): questionId = type1Ids[j] answer = answers[indexAnswer] part = 2 securtyID = SecurtyId indexAnswer += 1 report = ReportModel(ExperimentDetaileID, questionId, answer, part, securtyID) report.save_to_db() for j in range(0, len(type2Ids)): questionId = type2Ids[j] answer = answers[indexAnswer] part = 2 securtyID = SecurtyId indexAnswer += 1 report = ReportModel(ExperimentDetaileID, questionId, answer, part, securtyID) report.save_to_db() for j in range(0, len(type3Ids)): questionId = type3Ids[j] answer = answers[indexAnswer] part = 2 securtyID = SecurtyId indexAnswer += 1 report = ReportModel(ExperimentDetaileID, questionId, answer, part, securtyID) report.save_to_db() i += 1 # secind part => Traditional approach tempStr = '$answer[' + str(i) + '][]' answers = request.form.getlist(tempStr) indexAnswer = 0 ExperimentDetaileID = ExperimentDetaile.id for j in range(0, len(type1Ids)): questionId = type1Ids[j] answer = answers[indexAnswer] part = 2 securtyID = 0 indexAnswer += 1 report = ReportModel(ExperimentDetaileID, questionId, answer, part, securtyID) report.save_to_db() for j in range(0, len(type2Ids)): questionId = type2Ids[j] answer = answers[indexAnswer] part = 2 securtyID = 0 indexAnswer += 1 report = ReportModel(ExperimentDetaileID, questionId, answer, part, securtyID) report.save_to_db() for j in range(0, len(type3Ids)): questionId = type3Ids[j] answer = answers[indexAnswer] part = 2 securtyID = 0 indexAnswer += 1 report = ReportModel(ExperimentDetaileID, questionId, answer, part, securtyID) report.save_to_db() else: if (ExperimentDetaile.questionDisplay == 3): # first part => Contextual approach SecurtyIds = helper.getSecurtyIds( ExperimentDetaile.applicationId) i = 0 for SecurtyId in SecurtyIds: tempStr = '$answer[' + str(i) + '][]' answers = request.form.getlist(tempStr) indexAnswer = 0 ExperimentDetaileID = ExperimentDetaile.id for j in range(0, len(type1Ids)): questionId = type1Ids[j] answer = answers[indexAnswer] part = 2 securtyID = SecurtyId indexAnswer += 1 report = ReportModel(ExperimentDetaileID, questionId, answer, part, securtyID) report.save_to_db() for j in range(0, len(type2Ids)): questionId = type2Ids[j] answer = answers[indexAnswer] part = 2 securtyID = SecurtyId indexAnswer += 1 report = ReportModel(ExperimentDetaileID, questionId, answer, part, securtyID) report.save_to_db() for j in range(0, len(type3Ids)): questionId = type3Ids[j] answer = answers[indexAnswer] part = 2 securtyID = SecurtyId indexAnswer += 1 report = ReportModel(ExperimentDetaileID, questionId, answer, part, securtyID) report.save_to_db() i += 1 else: if (ExperimentDetaile.questionDisplay == 4): # first part => Traditional approach tempStr = '$answer[0][]' answers = request.form.getlist(tempStr) indexAnswer = 0 ExperimentDetaileID = ExperimentDetaile.id for j in range(0, len(type1Ids)): questionId = type1Ids[j] answer = answers[indexAnswer] part = 1 securtyID = 0 indexAnswer += 1 report = ReportModel(ExperimentDetaileID, questionId, answer, part, securtyID) report.save_to_db() for j in range(0, len(type2Ids)): questionId = type2Ids[j] answer = answers[indexAnswer] part = i securtyID = 0 indexAnswer += 1 report = ReportModel(ExperimentDetaileID, questionId, answer, part, securtyID) report.save_to_db() for j in range(0, len(type3Ids)): questionId = type3Ids[j] answer = answers[indexAnswer] part = i securtyID = 0 indexAnswer += 1 report = ReportModel(ExperimentDetaileID, questionId, answer, part, securtyID) report.save_to_db() else: # first part => Traditional approach tempStr = '$answer[0][]' answers = request.form.getlist(tempStr) indexAnswer = 0 ExperimentDetaileID = ExperimentDetaile.id part = 2 for j in range(0, len(type1Ids)): questionId = type1Ids[j] answer = answers[indexAnswer] securtyID = 0 indexAnswer += 1 report = ReportModel(ExperimentDetaileID, questionId, answer, part, securtyID) report.save_to_db() for j in range(0, len(type2Ids)): questionId = type2Ids[j] answer = answers[indexAnswer] securtyID = 0 indexAnswer += 1 report = ReportModel(ExperimentDetaileID, questionId, answer, part, securtyID) report.save_to_db() for j in range(0, len(type3Ids)): questionId = type3Ids[j] answer = answers[indexAnswer] securtyID = 0 indexAnswer += 1 report = ReportModel(ExperimentDetaileID, questionId, answer, part, securtyID) report.save_to_db() return saverModel.removeExperimentDetaile(userID, expId)
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