def MergePlusMissing(MergedFile, ValidPRE_File, ValidPOST_File, CompleteFileName): """Add students that only took one survey to merged file. Keyword arguments: MergedFile -- file name of merged dataset ValidPRE_File -- file name of all valid pretest surveys corresponding to merged dataset ValidPOST_File -- file name of all valid posttest surveys corresponding to merged dataset CompleteFileName -- file name of merged dataset with additional one survey students to write to """ Merged_df = pd.read_csv('Collective_Surveys/Merged/' + MergedFile) PRE_df = pd.read_csv('Collective_Surveys/PRE_Valid/' + ValidPRE_File) POST_df = pd.read_csv('Collective_Surveys/POST_Valid/' + ValidPOST_File) PRE_df_S = Scoring.CalcScore(PRE_df, Weights).rename(columns = {'TotalScores':'PreScores'}) POST_df_S = Scoring.CalcScore(POST_df, Weights).rename(columns = {'TotalScores':'PostScores'}) Unmatched_PRE = PRE_df_S[~PRE_df_S['V1'].isin(Merged_df['V1_x'])] Unmatched_POST = POST_df_S[~POST_df_S['V1'].isin(Merged_df['V1_y'])] Unmatched_PRE.columns = [c + '_x' if c != 'Class_ID' and c != 'PreScores' else c for c in Unmatched_PRE.columns] Unmatched_POST.columns = [c + '_y' if c != 'Class_ID' and c != 'PostScores' else c for c in Unmatched_POST.columns] Complete_df = pd.concat([Merged_df, Unmatched_PRE, Unmatched_POST], axis = 0, join = 'outer') Complete_df = Complete_df[Merged_df.columns] Complete_df.to_csv('Collective_Surveys/Complete/' + CompleteFileName, index = False) return(Complete_df)
def Network_finish(self, data): other = self.get_client(data["gameid"], data["player"]) cont = data["cont"] gameid = data["gameid"] game = self._server.games_dct[gameid] if cont: # wants to carry on playing other.channel.Send({"action": "clear"}) # clears on player 2 side, as only has cleared for player 1. game["score"] += data["score"] # tally score so far game["level"] += 1 # add 1 level self._server.begin(game["p1"], game["p2"], game["score"], game["level"]) elif not cont: # wants to quit p1 = game["p1"] p2 = game["p2"] p1.channel.Send({"action": "quit"}) p2.channel.Send({"action": "quit"}) # sends p2 the quit signal Scoring.add_score(data["name"], data["score"]) # adds score to json db del self._server.games_dct[gameid] # deletes game del self._server.players[p1.p_id] # deletes players from lists del self._server.players[p2.p_id]
def score_data(self): for term, doc_freq in self.term2DocIDFreq.items(): for doc, freq in doc_freq.items(): titleTF = Scoring.calculate_TF(int(freq[0])) textTF = Scoring.calculate_TF(int(freq[1])) idf = Scoring.calculate_IDF(self.corpus_count, len(doc_freq)) TFIDF = Scoring.calculate_overall_score(titleTF, "title") * idf + Scoring.calculate_overall_score(textTF, "text") * idf self.term2TFIDF[term][doc] = TFIDF
def simulateRound(game): if game.phase == 5: return Scoring.scoreRound(game) cardsNeeded = 5 - game.phase game.community += game.deck.deal(cardsNeeded) winners = Scoring.scoreRound(game) game.deck.deck += game.community[-cardsNeeded:] game.community = game.community[:-cardsNeeded] return winners
def CF_Boosted_Trees(model, Data, config, name, location, states=3): # train_data, test_data """ Input: train_data ... list-of-lists """ train_data, test_data = dat.PrepareCrossFold(Data.H_alpha) train_labels, test_labels = dat.PrepareCrossFold(Data.labels) K = len(train_data) score_tab = Scoring.ScoringTable(location=location, name=name, n_states=states) feat = FE.Features(config=config, normalize=True) start = time() for cross in range(K): clf = copy(model) train_matrix = feat.fit_transform(Data=train_data[cross]) test_matrix = feat.fit_transform_batch(Data=test_data[cross]) target = dat.merge_labels(train_labels[cross]) # print(np.shape(train_matrix), np.shape(target)) # print(np.shape(test_matrix), np.shape(test_labels[cross])) pred = train_and_predict(model=clf, train=train_matrix, test=test_matrix, labels=target, unsupervised=False) score = Scoring.score(states=pred, results=test_labels[cross], unsupervised=False, pocet_stavu=states) # print("score", score) score_tab.add(scores=score) print("{} section done. Time taken from start {}".format( cross + 1, time() - start)) score_tab.save_table() config["n_estimators"] = model.n_estimators with open(location + name + '_config.pickle', 'wb') as f: pickle.dump(config, f) return score_tab.return_table()
def CF_HMM_modif(model, Data, configg, transmat, startprob, name, location, states): score_tab = Scoring.ScoringTable(location=location, name=name, n_states=states) df = PM.CreateDataFrame(Data=Data, config=configg) KFold = FE.KFold(Data.shape[2]) history = {"TM": [], "Mean": [], "Cov": []} start = time() for cross in range(Data.shape[0]): clf_un = copy(model) X_train, y_train, X_test, y_test = KFold.fit_transform( x=df, kFoldIndex=cross) lengths = np.copy(Data.shape[2]) lengths = np.delete(lengths, cross) clf = PM.train_HMM_modif(model=clf_un, train=X_train, transmat=transmat, startprob=startprob, lengths=lengths, labels=y_train, n_states=states) pred = clf.predict(X_test) score = Scoring.score(states=pred, results=np.array(y_test), unsupervised=False, pocet_stavu=states) #print("score", score) score_tab.add(scores=score) print("{} section done. Time elapsed from start {}".format( cross + 1, np.around(time() - start, decimals=2))) history["Mean"].append(clf.means_) history["Cov"].append(clf.covars_) history["TM"].append(clf.transmat_) score_tab.save_table() info = copy(configg) info["trasition_matrix"] = history["TM"] info["means"] = history["Mean"] info["covariance_matrix"] = history["Cov"] with open(location + name + '_config.pickle', 'wb') as f: pickle.dump(info, f) return score_tab.return_table()
def Checkstate(self): if self.rb1.isChecked()==True: self.list1.clear() connection=sqlite3.connect("Cricket.db") result2=connection.execute("SELECT Player from Stats WHERE Category='BAT';") record2=result2.fetchall() a=0 for i in record2: self.list1.addItem(i[0]) a+=Scoring.batscoring(i[0]) self.label_11.setText(str(a)) self.label_6.setText("4") self.label_13.setText("0") elif self.rb2.isChecked()==True: self.list1.clear() connection=sqlite3.connect("Cricket.db") result4=connection.execute("SELECT Player from Stats WHERE Category='BWL';") record4=result4.fetchall() b=0 for i in record4: self.list1.addItem(i[0]) b+=Scoring.bowlscoring(i[0]) self.label_11.setText(str(b)) self.label_4.setText("4") self.label_13.setText("0") elif self.rb3.isChecked()==True: self.list1.clear() connection=sqlite3.connect("Cricket.db") point_2=connection.execute("SELECT Player from Stats WHERE Category='AR';") record_2=point_2.fetchall() e=0 for i in record_2: self.list1.addItem(i[0]) e+=Scoring.AllRounder(i[0]) self.label_11.setText(str(e)) self.label_3.setText("5") self.label_13.setText("0") elif self.rb4.isChecked()==True: self.list1.clear() connection=sqlite3.connect("Cricket.db") result=connection.execute("SELECT Match.Player,Match.Scored,Match.Fours,Match.Sixes,Match.Faced,Match.RunOut,Match.Catches,Match.Stumping from Stats,Match WHERE Stats.Player=Match.Player AND Stats.Category='WK';") record=result.fetchall() f=0 for i in record: self.list1.addItem(i[0]) f+= Scoring.WicketKeeping(i[0]) self.label_11.setText(str(f)) self.label_8.setText("2") self.label_13.setText("0")
def Identify(file, header_file, file_out, Class_ID = None): """Create identifiable data file to be sent to instructor or uploaded to PLIC dashboard. Keyword arguments: file -- master csv file containing matched students' pre and posttest scores header_file -- csv file containing header information file_out -- name of outputted csv file Class_ID -- Class_ID of specific class that idenntifiable data is requested for; if retrieving data for dashboard, set as None """ Questions = ['Q1B', 'Q1D', 'Q1E', 'Q2B', 'Q2D', 'Q2E', 'Q3B', 'Q3D', 'Q3E', 'Q4B'] df = pd.read_csv(file) if(Class_ID is not None): df = df.loc[df['Class_ID'] == Class_ID, :] dfOther = pd.read_csv(file) dfOther_Pre = dfOther.loc[dfOther['Survey_x'] == 'C', [col + 's_x' for col in Questions]] dfOther_Post = dfOther.loc[dfOther['Survey_y'] == 'C', [col + 's_y' for col in Questions]] dfOther_Pre.columns = dfOther_Pre.columns.str.replace(r's_x$', 's') dfOther_Post.columns = dfOther_Post.columns.str.replace(r's_y$', 's') dfOther = pd.concat([dfOther_Pre, dfOther_Post], axis = 0, join = 'inner').reset_index(drop = True) df_Pre = df.loc[df['Survey_x'] == 'C', [col + 's_x' for col in Questions]].reset_index() df_Post = df.loc[df['Survey_y'] == 'C', [col + 's_y' for col in Questions]].reset_index() df_Pre.columns = df_Pre.columns.str.replace(r's_x$', 's') df_Post.columns = df_Post.columns.str.replace(r's_y$', 's') pre_scores = Scoring.CalcFactorScores(dfOther, df_Pre).rename(columns = {'models':'models_PRE', 'methods':'methods_PRE', 'actions':'actions_PRE'}).set_index(pd.Index(df_Pre['index'])) post_scores = Scoring.CalcFactorScores(dfOther, df_Post).rename(columns = {'models':'models_POST', 'methods':'methods_POST', 'actions':'actions_POST'}).set_index(pd.Index(df_Post['index'])) df = pd.concat([df, pre_scores, post_scores], axis = 1, join = 'outer') df['ID'] = df['Q5a_y'].fillna(df['Q5a_x']) df['LastName'] = df['Q5b_y'].fillna(df['Q5b_x']) df['FirstName'] = df['Q5c_y'].fillna(df['Q5c_x']) df = SetGender(df) df = SetURM(df) df = SetMajor(df) df = SetClassStanding(df) df.columns = df.columns.str.replace(r's_x$', '_PRE') df.columns = df.columns.str.replace(r's_y$', '_POST') if(Class_ID is None): df.columns = df.columns.str.replace(r'_x$', '_PRE') df.columns = df.columns.str.replace(r'_y$', '_POST') df = df.rename(columns = {'PreScores':'TotalScores_PRE', 'PostScores':'TotalScores_POST'}) if(Class_ID is not None): df = df.drop(columns = ['Gender', 'Major', 'URM_Status', 'Class_Standing']) df.headers = pd.read_csv(header_file) df = pd.concat([df.headers, df], join = 'inner') df.to_csv(file_out, index = False) return df
def PointsUsed_2(self,txt): connection=sqlite3.connect("Cricket.db") point_2=connection.execute("SELECT Category from Stats WHERE Player='"+txt+"';") record_2=point_2.fetchall() for i in record_2: if i[0]=='BAT': Num=int(self.label_6.text()) text_2=int(self.label_13.text()) text=int(self.label_11.text()) a=int(Scoring.batscoring(txt)) f=text+a g=text_2-a Num+=1 self.label_11.setText(str(f)) self.label_13.setText(str(g)) self.label_6.setText(str(Num)) elif i[0]=='BWL': Num=int(self.label_4.text()) text_2=int(self.label_13.text()) text=int(self.label_11.text()) b=int(Scoring.bowlscoring(txt)) Num+=1 m=text+b p=text_2-b self.label_11.setText(str(m)) self.label_13.setText(str(p)) self.label_4.setText(str(Num)) elif i[0]=='AR': Num=int(self.label_3.text()) text_2=int(self.label_13.text()) text=int(self.label_11.text()) c=int(Scoring.AllRounder(txt)) j=text+c y=text_2-c Num+=1 self.label_11.setText(str(j)) self.label_13.setText(str(y)) self.label_3.setText(str(Num)) elif i[0]=='WK': Num=int(self.label_8.text()) text_2=int(self.label_13.text()) text=int(self.label_11.text()) d=int(Scoring.WicketKeeping(txt)) h=text+d l=text_2-d Num+=1 self.label_11.setText(str(h)) self.label_13.setText(str(l)) self.label_8.setText(str(Num))
def main(sa): a = "ATGCGAATGCGA" b = "TGCGAATGCGAT" a = [a[i:i + 3] for i in range(len(a))] b = [b[i:i + 3] for i in range(len(b))] filename = sa[0] blosum = Scoring.Blosum(filename) blosum_scores = blosum.to_dict() blosum.close() print(a, b) scores = Scoring.convert_aa_to_nt_scores(blosum_scores) #a_build, b_build = MutAlign.MutAlignDFS.align(a, b, scores, False) a_build, b_build = MutAlign.MutAlignGreedy().greedy_mut(a, b, False) print(a_build, b_build)
def GridSearch(estimator, params, Data, config, name, location, states=3): df = CreateDataFrame(Data=Data, config=config) KFold = FE.KFold(Data.shape[2]) start = time() GRID = ParameterGrid(params) combinations = len(list(GRID)) print("Number of combinations {}".format(combinations)) bar = progressbar.ProgressBar(maxval=combinations * 10, widgets=[ progressbar.Bar('#', '[', ']'), ' ', progressbar.Percentage() ]) combo = 0 bar.start() for i, g in enumerate(GRID): score_tab = Scoring.ScoringTable(location=location, name=name + str(g) + str(i), n_states=states) for cross in range(Data.shape[0]): clf = copy(estimator) X_train, y_train, X_test, y_test = KFold.fit_transform( x=df, kFoldIndex=cross) clf.set_params(**g) pred = train_and_predict(model=clf, train=X_train, test=X_test, labels=y_train, unsupervised=False) score = Scoring.score(states=pred, results=np.array(y_test), unsupervised=False, pocet_stavu=states) score_tab.add(scores=score) combo += 1 bar.update(combo) score_tab.save_table() del score_tab info = copy(config) info["params"] = g with open(location + name + str(g) + str(i) + '_config.pickle', 'wb') as f: pickle.dump(info, f) bar.finish() print('Celý proces trval: {} vteřin'.format( np.around(time() - start, decimals=0))) print('Hotovo!!') return
def runModel(imgFilePathLst, resize): """ 运行模式 - 多照片运行 这个函数必须在模型已经初始化完毕之后才能使用 :param imgFilePathLst: :param resize: :return: """ global model, hasModelInit if model == None or (not hasModelInit): log.error('Failed to calculate aes score : model is not initialized!') return with tf.device('/CPU:0'): scoreLst = [] for imgPath in imgFilePathLst: log.info('Now processing img -> %s' % (imgPath)) # 预处理 imgArr = _preImgProcess(imgPath, resize) # 预测 scores = model.predict(imgArr, batch_size=1, verbose=0)[0] aesScore = score.calculateAesScore(scores) aesScore = aesScore * 10 # log.success('The aes score for img -> %s is %0.3f' % (imgPath, aesScore)) _, imgName = os.path.split(imgPath) scoreLst.append((imgName, aesScore)) # 进行排序 sortedScoreLst = sorted(scoreLst, key=lambda s: s[1], reverse=True) return sortedScoreLst
def runModelForSingleImg(imgFilePath, resize): """ 运行模式 - 单照片运行 这个函数必须在模型已经初始化完毕之后才能使用 :param imgFilePathLst: :param resize: :return: :param imgFilePath: :param resize: :return: """ global model, hasModelInit, graph if model == None or (not hasModelInit): log.error('Failed to calculate aes score : model is not initialized!') return with tf.device('/CPU:0'): with graph.as_default(): log.info('Now processing img -> %s' % (imgFilePath)) # 预处理 imgArr = _preImgProcess(imgFilePath, resize) # 预测 scores = model.predict(imgArr, batch_size=1, verbose=0)[0] aesScore = score.calculateAesScore(scores) aesScore = aesScore * 10 return aesScore
def create_assignment_matrix(self): mentors, mentees, person_dict = ds.load_data( "initial_data_{}".format(ROUND)) # mentors, mentees = loader.load_data("initial_data.csv") self.mentors = mentors self.mentees = mentees self.no_mentors = len(mentors) no_mentees = len(mentees) matrix = [[self.no_mentors] * no_mentees for i in range(self.no_mentors)] self.score_matrix = score.score_evaluation_5(matrix, mentors, mentees, person_dict) self.no_mentors = len(self.score_matrix) no_mentees = len(self.score_matrix[0]) if self.no_mentors != no_mentees: diff = no_mentees - self.no_mentors for _ in range(diff): dummy_mentor = [0 for _ in self.score_matrix[0]] self.score_matrix.append(dummy_mentor) return mentors, mentees
def test_progressbar(max_val, sleep_time=2): bar = Scoring.Bar(max_val) bar.start() for i in range(max_val): bar.update(i + 1) sleep(sleep_time) bar.finish() print("all is good")
def change_combo(self): txt=ui.label_14.text() connection=sqlite3.connect("Cricket.db") connection.execute("INSERT INTO Teams (Name) VALUES ('%s')" %(txt)) result2=connection.execute("SELECT Name from Teams;") record2=result2.fetchall() for i in record2: self.comboBox_2.addItem(i[0]) self.comboBox.addItem("Match") for i in range(ui.list2.count()): self.listWidget_2.addItem(ui.list2.item(i).text()) for j in range(ui.list2.count()): txt=ui.list2.item(j).text() connection=sqlite3.connect("Cricket.db") point_2=connection.execute("SELECT Match.Wickets,Match.RunOut,Match.Bowled,Match.Given,Match.Catches,Match.Stumping,Match.Scored,Match.Fours,Match.Sixes,Match.Faced ,Stats.Category from Match,Stats WHERE Match.Player=Stats.Player AND Stats.Player='"+txt+"';") record_2=point_2.fetchall() for p in record_2: if p[10]=='AR': points_bowl=int(Scoring.bowling(p[0],p[1],p[2],p[3],p[4],p[5])) points_bat=int(Scoring.batting(p[6],p[7],p[8],p[9],0,0,0)) c=points_bowl d=points_bat e=c+d self.listWidget.addItem(str(e)) elif p[10]=='BAT': points_bat=int(Scoring.batting(p[6],p[7],p[8],p[9],p[1],p[4],p[5])) g=points_bat self.listWidget.addItem(str(g)) elif p[10]=='BWL': points_bowl=int(Scoring.bowling(p[0],p[1],p[2],p[3],p[4],p[5])) h=points_bowl self.listWidget.addItem(str(h)) elif p[10]=='WK': points_bat=int(Scoring.batting(p[6],p[7],p[8],p[9],p[1],p[4],p[5])) y=points_bat self.listWidget.addItem(str(y)) sums=0 for i in range(self.listWidget.count()): a=int(self.listWidget.item(i).text()) sums+=a self.label_5.setText(str(sums))
def fast_CF_Boosted_Trees(model, Data, config, name, location, states=3): """ Input: Data ... musí být Bunch z load_dataset() Output: score_tab ... hotová tabulka pd.DataFrame """ score_tab = Scoring.ScoringTable(location=location, name=name, n_states=states) feature = FE.Features(config=config, normalize=True) df = feature.CreateDataFrame(Data=Data) # df = CreateDataFrame(Data=Data, config=config) KFold = FE.KFold(Data.shape[2]) start = time() for cross in range(Data.shape[0]): clf = copy(model) X_train, y_train, X_test, y_test = KFold.fit_transform( x=df, kFoldIndex=cross) y_pred = train_and_predict(model=clf, train=X_train, test=X_test, labels=y_train, unsupervised=False) score = Scoring.score(states=y_pred, results=np.array(y_test), unsupervised=False, pocet_stavu=states) # print("score", score) score_tab.add(scores=score) print("{} section done. Time elapsed from start {}".format( cross + 1, np.around(time() - start, decimals=2))) score_tab.save_table() info = copy(config) info["n_estimators"] = model.n_estimators info["learning_rate"] = model.learning_rate with open(location + name + '_config.pickle', 'wb') as f: pickle.dump(info, f) return score_tab.return_table()
def MergeSurveys(PRE_Matched_File, POST_Matched_File, FileName): """Merge pre and post matched files together. Keyword arguments: PRE_Matched_File -- file name of matched pre file POST_Matched_File -- file name of matched post file FileName -- file name of merged matched file to write to """ PRE_df = pd.read_csv(PRE_Matched_File, dtype = {'Q5a':'object'}) POST_df = pd.read_csv(POST_Matched_File, dtype = {'Q5a':'object'}) PRE_df_S = Scoring.CalcScore(PRE_df, Weights) POST_df_S = Scoring.CalcScore(POST_df, Weights) PRE_df_S = PRE_df_S.rename(columns = {'TotalScores':'PreScores'}) POST_df_S = POST_df_S.rename(columns = {'TotalScores':'PostScores'}) PRE_df_S['FullName'] = PRE_df_S['Q5b'].str.lower().str.replace(' ', '') + PRE_df_S['Q5c'].str.lower().str.replace(' ', '') POST_df_S['FullName'] = POST_df_S['Q5b'].str.lower().str.replace(' ', '') + POST_df_S['Q5c'].str.lower().str.replace(' ', '') POST_df_S['BackName'] = POST_df_S['Q5c'].str.lower().str.replace(' ', '') + POST_df_S['Q5b'].str.lower().str.replace(' ', '') # merge on forward and backwards names, and IDs, then drop duplicate matches Full_df = pd.merge(left = PRE_df_S, right = POST_df_S, how = 'inner', on = ['Class_ID', 'FullName']) Back_df = pd.merge(left = PRE_df_S, right = POST_df_S, how = 'inner', left_on = ['Class_ID', 'FullName'], right_on = ['Class_ID', 'BackName']) ID_df = pd.merge(left = PRE_df_S, right = POST_df_S, how = 'inner', on = ['Class_ID', 'Q5a']).rename(columns = {'Q5a':'Q5a_x'}) ID_df['Q5a_y'] = ID_df['Q5a_x'] # create duplicate ID column for merging with names dataframes Merged_df = pd.concat([Full_df, Back_df, ID_df], axis = 0, join = 'inner').drop_duplicates().drop(columns = ['BackName']).reset_index(drop = True) if('Q4b' in Merged_df.columns): # if there are open-response surveys in one of pre or post, then they'll be in pre Merged_df = Merged_df.rename(columns = {'Q1b':'Q1b_x', 'Q1d':'Q1d_x', 'Q1e':'Q1e_x', 'Q2b':'Q2b_x', 'Q2d':'Q2d_x', 'Q2e':'Q2e_x', 'Q3b':'Q3b_x', 'Q3d':'Q3d_x', 'Q3e':'Q3e_x', 'Q4b':'Q4b_x'}) Merged_df.to_csv('Collective_Surveys/Merged/' + FileName, index = False) return(Merged_df)
def playRound(self): self.newRound() self.ante() self.betAction() self.flop() self.betAction() self.turn() self.betAction() self.river() self.betAction() self.roundOver = True winners = Scoring.scoreRound(self) self.awardPot(winners) self.elmination()
def start(self): self.add_text("Converting video to frames...") self.eval_id = video_to_frames_with_db.convert_video_to_frames( self.user_name, self.video_name, "", self.video_type) self.add_text("FaceDetection...") results_folder = self.user_name + "_" + str( self.video_type) + "_" + str(self.eval_id) FaceDetection.face_detect_main(self.eval_id, results_folder, results_folder) self.add_text("UpperBodyDetection...") UpperBodyDetection.upperbody_detect_main(self.eval_id, results_folder, results_folder) self.add_text("LowerBodyDetection...") LowerBodyDetection.lowerbody_detect_main(self.eval_id, results_folder, results_folder) self.report_card = Scoring.score(self.user_name, self.video_type)
def BuildDuplicatedDataset(dir='C:/Users/Cole/Documents/DATA/PLIC_DATA/'): """Create dataframe of students who completed the PLIC multiple times (validly) in the same semester at the same timepoint. Keyword arguments: dir -- base directory where PLIC data are stored """ os.chdir(dir) Weights = pd.read_excel('Weights_May2019.xlsx').transpose()[0] Basedf = pd.read_csv('PLIC_May2019.csv', nrows=1) MainSurveys_Folder = 'SurveysMay2019/' Questions = [ 'Q1b', 'Q1d', 'Q1e', 'Q2b', 'Q2d', 'Q2e', 'Q3b', 'Q3d', 'Q3e', 'Q4b' ] dfs = [] files = glob('SurveysMay2019/**/*May2019.csv', recursive=True) for f in files: df = pd.read_csv(f, skiprows=[1]).dropna(subset=['Q5b', 'Q5c']) df = Valid_Matched.Validate(df, 'PRE') if 'Survey' in df.columns: df = df.loc[df['Survey'] != 'F'].dropna(subset=['Q3c']) if df.empty: continue df['Q5b'] = df['Q5b'].apply(str).str.lower().str.replace('\W', '') df['Q5c'] = df['Q5c'].apply(str).str.lower().str.replace('\W', '') df = df.loc[df.duplicated(subset=['Q5b', 'Q5c'], keep=False), :] if not df.empty: df['Time'] = f.split('_')[-4] df['Class_ID'] = '_'.join(f.split('_')[-3:-1]) dfs.append(df) df = pd.concat(dfs, axis=0) df['anon_student_id'] = ( df['Q5b'] + df['Q5c'] + df['Time']).astype(str).astype('category').cat.codes df = Scoring.CalcScore(df, Weights) df.to_csv('Collective_Surveys/DuplicatedSurveys.csv', index=False) return df
def runModelForSingleImg(self, imgFilePath, resize): """ 运行模式 - 单照片运行 这个函数必须在模型已经初始化完毕之后才能使用 注意,此函数线程安全,进程不安全 :param imgFilePathLst: :param resize: :return: :param imgFilePath: :param resize: :return: """ if not self.initFinish: log.error( 'Failed to calculate aes score : model is not initialized!') return # with tf.device('/CPU:0'): # with graph.as_default(): with self.graph.as_default(): log.info('Now processing img -> %s' % (imgFilePath)) # 预处理 imgArr = self._preImgProcess(imgFilePath, resize) try: self.lock.acquire() log.info('Now preprocessing img -> %s' % (imgFilePath)) # 预测 scores = self.model.predict(imgArr, batch_size=1, verbose=0)[0] aesScore = score.calculateAesScore(scores) aesScore = aesScore * 10 log.info('The score for img -> %s is %.2f' % (imgFilePath, aesScore)) finally: self.lock.release() return str(aesScore)
def GenerateGraph(OtherPreFile, OtherPostFile, Level, ID, Weightsdf, **Dataframes): """Generate graphs of students' scores and responses on the Explicitly Keyword arguments: OtherPreFile -- csv file of all students previous pretest responses OtherPostFile -- csv file of all students previous posttest responses Level -- course level students taking the assessment were enrolled in ID -- ResponseID on the course information survey corresponding to the class Weightsdf -- pandas series of weights applied to PLIC item response choices when scoring Dataframes -- pandas dataframes of students responses to the PRE, MID, and/or POST survey """ global NValidPost, N_Other, dfYour_Post dfOther_Pre = pd.read_csv(OtherPreFile) dfOther_Post = pd.read_csv(OtherPostFile) dfOther = pd.concat([dfOther_Pre, dfOther_Post], axis=0, join='inner').reset_index(drop=True) dfOther_Pre_Level = dfOther_Pre[dfOther_Pre['Course_Level'] == Level].reset_index(drop=True) dfOther_Pre_Level = dfOther_Pre_Level.assign(Survey='PRE', Data='Other') dfOther_Post_Level = dfOther_Post[dfOther_Post['Course_Level'] == Level].reset_index(drop=True) dfOther_Post_Level = dfOther_Post_Level.assign(Survey='POST', Data='Other') N_Other = len(dfOther_Post_Level) if ( 'MID' in Dataframes.keys() ): # conditions handle dataframe for YOUR class, its easier when things are in one dataframe in long form NValidPre, NValidMid, NValidPost, dfYour_Pre, dfYour_Mid, dfYour_Post = Valid_Matched.ValMat( PRE=Dataframes['PRE'], MID=Dataframes['MID'], POST=Dataframes['POST']) dfYour_PreS = Scoring.CalcScore(dfYour_Pre, Weightsdf) dfYour_PreS = dfYour_PreS.assign(Survey='PRE', Data='Yours', Class_ID=ID) dfYour_MidS = Scoring.CalcScore(dfYour_Mid, Weightsdf) dfYour_MidS = dfYour_MidS.assign(Survey='MID', Data='Yours', Class_ID=ID) dfYour_PostS = Scoring.CalcScore(dfYour_Post, Weightsdf) dfYour_PostS = dfYour_PostS.assign(Survey='POST', Data='Yours', Class_ID=ID) df_Concat = pd.concat([ dfYour_PreS, dfYour_MidS, dfYour_PostS, dfOther_Pre_Level, dfOther_Post_Level ], axis=0, join='inner').reset_index(drop=True) elif ('PRE' in Dataframes.keys()): NValidPre, NValidPost, dfYour_Pre, dfYour_Post = Valid_Matched.ValMat( PRE=Dataframes['PRE'], POST=Dataframes['POST']) dfYour_PreS = Scoring.CalcScore(dfYour_Pre, Weightsdf) dfYour_PreS = dfYour_PreS.assign(Survey='PRE', Data='Yours', Class_ID=ID) dfYour_PostS = Scoring.CalcScore(dfYour_Post, Weightsdf) dfYour_PostS = dfYour_PostS.assign(Survey='POST', Data='Yours', Class_ID=ID) df_Concat = pd.concat( [dfYour_PreS, dfYour_PostS, dfOther_Pre_Level, dfOther_Post_Level], axis=0, join='inner').reset_index(drop=True) else: NValidPost, dfYour_Post = Valid_Matched.ValMat(POST=Dataframes['POST']) dfYour_PostS = Scoring.CalcScore(dfYour_Post, Weightsdf) dfYour_PostS = dfYour_PostS.assign(Survey='POST', Data='Yours', Class_ID=ID) df_Concat = pd.concat( [dfYour_PostS, dfOther_Pre_Level, dfOther_Post_Level], axis=0, join='inner').reset_index(drop=True) df_Factors = Scoring.CalcFactorScores( dfOther, df_Concat ) # Factor scores offer further information beyond just total scores # putting those scores back in the same dataframe is also easiest. We don't store factor scores since they're dynamic with changing models df_Concat = pd.concat([df_Concat, df_Factors], axis=1, join='inner') GenerateTotalScoresGraph(df_Concat) GenerateQuestionsGraph(df_Concat) if ( 'PRE' in Dataframes.keys() ): # put the data from YOUR class back together with the national dataset dfYour_PreS['Course_Level'] = Level dfOther_Pre = pd.concat([dfOther_Pre, dfYour_PreS], join='inner', axis=0) dfOther_Pre.to_csv(OtherPreFile, index=False) dfYour_PostS['Course_Level'] = Level dfOther_Post = pd.concat([dfOther_Post, dfYour_PostS], join='inner', axis=0) dfOther_Post.to_csv(OtherPostFile, index=False) if ('MID' in Dataframes.keys()): return NValidPre, NValidMid, NValidPost, dfYour_Pre, dfYour_Mid, dfYour_Post else: return NValidPre, NValidPost, dfYour_Pre, dfYour_Post else: return NValidPost, dfYour_Post
endpId = req[1] endp = endpoints[endpId] serverLatencies = sorted(endp[1], key=itemgetter(1)) # cacheId, cacheLatency if len(serverLatencies) == 0: continue serverDetails = [caches[s[0]] for s in serverLatencies] if videoSize > getMaxCapacity(serverDetails): continue found = False for s in serverLatencies: if videoId in caches[s[0]][1]: found = True break if found: continue for s in serverLatencies: sid = s[0] cacheObj = caches[sid] if cacheObj[0] > videoSize: cacheObj[0] = cacheObj[0] - videoSize cacheObj[1].append(videoId) break Sc.output(caches) print "Done"
def menu_setup(self, channel): score_list = Scoring.get_scores() channel.Send({"action": "give_scores", "scores": score_list})
def Network_get_names(self, data): player = self._server.players[data["id"]] names = Scoring.get_names() player.channel.Send({"action": "get_names", "names": names})
woe_merge_dict['call_2way_bnk_time_min_j5m'] = [[7,]] woe_merge_dict['sms_out_bank_dsst_max_j4m'] = [[113, ]] woe_merge_dict['call_2way_htaxi_time_max_j6m'] = [[378, ]] woe_merge_dict['call_in_adfd_itv_sum_j4m'] = [[2, 101]] woe_merge_dict['call_out_stop3_itv_max_j1m'] = [[1,6], [21,]] #woe_merge_dict['call_in_clct_time_max_j1m'] = [[79,97]] woe_merge_dict['call_in_rel1_time_avg_j2m'] = [[68.4444, 71.5]] updated_woe_bin_dict = update_woe(woe_merge_dict, woe_bin_dict) #Update the woe pickle pd.to_pickle(updated_woe_bin_dict, tgt + '/woe_files/{0}_s{1}_woe_bin_py.pickle'.format(prefix, seg)) dev_df = pd.read_csv(tgt + '/s{0}_dev.gz'.format(seg), compression = 'gzip', nrows = None) oot_df = pd.read_csv(tgt + '/s{0}_oot.gz'.format(seg), compression = 'gzip', nrows = None) dev_df['time_window'] = 'DEV' oot_df['time_window'] = 'OOT' dev_df = dev_df[dev_df[target_var].isin([0,1])][[id_var, unit_weight, doll_weight, target_var, 'time_window'] + list(model_var_df['varname'])] oot_df = oot_df[oot_df[target_var].isin([0,1])][[id_var, unit_weight, doll_weight, target_var, 'time_window'] + list(model_var_df['varname'])] dev_df_woe = Scoring(df_in = dev_df, woe_dict = woe_bin_dict, model_obj = None, mdl_var_df = model_var_df) oot_df_woe = Scoring(df_in = oot_df, woe_dict = woe_bin_dict, model_obj = None, mdl_var_df = model_var_df) modeling(dev_df = dev_df, oot_df = oot_df, preselected_df = model_var_df, forced_var_list = forced_var_list, exclude_var_list = exclude_var_list, modeling_weight = unit_weight, target_var = target_var, model_var_lmt = 40, max_iter = max_iter, max_coef = max_coef, corr_threshold = corr_threshold, dr = tgt, seg = seg)
def play_single_game(game_name: str, players: list, should_load_from_input: bool = False, should_log_results: bool = True): deck = create_deck(should_load_from_input) num_of_players = len(players) cards_per_player = 12 - num_of_players total_scores = [0 for _ in range(num_of_players)] total_pudding_counts = [0 for _ in range(num_of_players)] game_history = {'players': [player.get_name() for player in players], 'rounds': []} for round_index in range(3): plates = [[] for _ in range(num_of_players)] round_moves_history = [] round_history = { 'roundMoves': round_moves_history, 'plates': plates } game_history['rounds'].append(round_history) hands = draw_hands(deck, num_of_players, cards_per_player) while len(hands[0]) > 0: move_history = [] for player_index in range(num_of_players): player_move_history = {} player = players[player_index] hand = hands[player_index] plate = plates[player_index] player_move_history['beforeAction'] = { 'hand': Logging.cards_to_names(hand), 'plate': Logging.cards_to_names(plate), } chosen_card_indices = player.play( KnowledgeFilter.filter_game_knowledge(game_history, player_index, hand, plate)) chosen_card_indices = validate_chosen_card_indices(hand, plate, chosen_card_indices) player_move_history['chosenCardIndices'] = chosen_card_indices if len(chosen_card_indices) == 1: chosen_card_index = chosen_card_indices[0] plate.append(hand[chosen_card_index]) del hand[chosen_card_index] else: chopsticks_index = find_chopsticks_index(plate) del plate[chopsticks_index] plate.append(hand[chosen_card_indices[0]]) plate.append(hand[chosen_card_indices[1]]) for chosen_card_index in sorted(chosen_card_indices, reverse=True): del hand[chosen_card_index] hand.append(Cards.Chopsticks) player_move_history['afterAction'] = { 'hand': Logging.cards_to_names(hand), 'plate': Logging.cards_to_names(plate), } move_history.append(player_move_history) hands = rotate_hands(hands) round_moves_history.append(move_history) round_scores = Scoring.get_player_scores(plates) total_scores = [sum(scores) for scores in zip(total_scores, round_scores)] round_pudding_counts = Scoring.get_round_pudding_counts(plates) total_pudding_counts = [sum(counts) for counts in zip(total_pudding_counts, round_pudding_counts)] round_history['roundScores'] = round_scores round_history['totalScores'] = total_scores round_history['roundPuddingCounts'] = round_pudding_counts round_history['totalPuddingCounts'] = total_pudding_counts pudding_scores = Scoring.get_pudding_scores(total_pudding_counts) final_scores = [sum(scores) for scores in zip(total_scores, pudding_scores)] game_history['puddingScores'] = pudding_scores game_history['finalScores'] = final_scores if should_log_results: Logging.log_game_output(game_history) for round in game_history['rounds']: del round['plates'] json_string = json.dumps(game_history) with open('output/' + game_name + '.json', 'w') as f: f.write(json_string) return game_history
nrows=None) oot_df = pd.read_csv(tgt + '/s{0}_oot.gz'.format(seg), compression='gzip', nrows=None) dev_df['time_window'] = 'DEV' oot_df['time_window'] = 'OOT' # df_mst = pd.concat([dev_df, oot_df])[[id_var, unit_weight, doll_weight, target_var, 'time_window',benchmark_score] + list(model_var_df['varname'])] df_mst = pd.concat([ dev_df, oot_df ])[[id_var, unit_weight, doll_weight, target_var, 'time_window'] + list(model_var_df['varname'])] df_mst_scr = Scoring(df_in=df_mst, woe_dict=woe_bin_dict, model_obj=mdl, mdl_var_df=model_var_df, prob_scr_name=prefix + '_prob_scr') df_mst_scr[prefix + '_aligned_score'] = df_mst_scr[ prefix + '_prob_scr'].apply(score_align).apply(np.int) print( df_mst_scr.groupby(['time_window'], as_index=False)[[ unit_weight, target_var, prefix + '_prob_scr', prefix + '_aligned_score' ]].agg({ unit_weight: 'sum', target_var: ['sum', 'mean'], prefix + '_prob_scr': 'mean', prefix + '_aligned_score': 'mean'
import Scoring def openfile(filename): file = open(filename) text = file.read() return text text = openfile("scamtest.txt") Threshold = 0 if Threshold < 80: if Scoring.emailanalysis(text) is not None: Threshold = Threshold + 80
def main(): global falling_piece global shadow_piece global falling_sprites running = True new_piece_pending = False new_piece_pending_elapsed = 0 # ms # # Text displays # level = Level.startLevel() level_surf = None total_elapsed = 0 zero_time = datetime.timedelta(seconds=0) time_surf = None points = 0 point_surf = None if display_level: lines = Level.lines(level) else: lines = start_lines # from Settings lines_surf = None if display_level: level_surf = createText(level_x, level_y, 'Level: ') updateText(level_surf, level) if display_time: time_surf = createText(time_x, time_y) updateText(time_surf, timeObj(time_limit, 0)[1]) if display_points: point_surf = createText(points_x, points_y, 'Points: ') updateText(point_surf, points) if display_lines: lines_surf = createText(lines_x, lines_y, 'Remaining: ') updateText(lines_surf, lines) # # Delayed auto shift variables: # last_movement = 0 # tracks when last manual movement was das_triggered = False # tracks if DAS has been triggered # # The goal for hard drops is the piece to hit the bottom as fast as # possible. We want the user to be able to hold the hard drop button down # to continuously drop pieces too. BUT there needs to be a delay otherwise # they'll be forced to press the button for only one frame, otherwise # there's a good chance 2+ pieces will drop since we're running at 60 fps. # # SO, this is a delay that extends into the next piece. # hard_drop_repeat_wait = 0 hard_drop_repeat_wait_elapsed = 0 # # Initialize invisible pieces that occupy the well. well_rows and # well_sheets are lists of sprite groups with one entry per row. # # well_rows: In order to detect when a row is complete we need 10 (width) # surfaces per row to check when all of them are colliding with # pieces on the screen. # # well_sheets: In order to move pieces down when a row is completed we # need to be able to determine which blocks are *above* the # row that is completed. Therefore these surfaces will stretch # the width of the well and get longer and longer the farther # down they are (stretching upward). These could be avoided # if surfaces gave info about their position on the screen? # for y in range(0, well_length): # Initialize the sprites for each column for x in range(0, well_width): curr = Piece(clock, x_coord=x, y_coord=y).getSprites() well.add(curr) well_rows[y].add(curr) # Initialize the sheet. well_sheets.append(Sheet(y, well_width)) # Initialize invisible pieces that line the outside of the well. In order: # top, right, bottom, left. border_coords = [(x,-1) for x in range(-1, well_width)] border_coords += [(well_width,y) for y in range(-1, well_length)] border_coords += [(x,well_length) for x in range(well_width, -1, -1)] border_coords += [(-1,y) for y in range(well_length, -1, -1)] for (x,y) in border_coords: curr = Piece(clock, x_coord=x, y_coord=y) sprites = curr.getSprites() border.add(sprites) if not (y < 0 and x >= 0 and x < well_width): border_U.add(sprites) # shaped like a U if x < 0: border_l.add(sprites) if x == well_width: border_r.add(sprites) # Set up first piece all_drawable.add([piece.getSprites() for piece in manager.getPieces()]) gravity = Level.gravity(level) # starts at 1 second per drop falling_piece = newPiece(gravity) saved_piece = None last_line_animation = lines # Draw countdown for i in range(countdown_secs, 0, -1): animations.append(Animation(i, clock, screen)) while animations: clock.tick(fps) updateScreen() # Flush input buffer - applicable if countdown happened pygame.event.get() # # MAIN LOOP # while running: clock.tick(fps) total_elapsed += clock.get_time() if display_time: if time_counts_up: time_obj, time_string = timeObj(0, total_elapsed) else: time_obj, time_string = timeObj(time_limit, -total_elapsed) updateText(time_surf, time_string) if time_obj <= zero_time: updateText(time_surf, zero_time) print(points) gameOver() last_movement += clock.get_time() reverted_downward_move = False # See explanation in Settings.py, under MISC. if level_enabled: new_piece_pending_period = Level.nppp(level) else: new_piece_pending_period = hard_drop_wait if new_piece_pending: new_piece_pending_elapsed += clock.get_time() if hard_drop_repeat_wait: hard_drop_repeat_wait_elapsed += clock.get_time() if hard_drop_repeat_wait_elapsed > 200: hard_drop_repeat_wait = False ####################################################################### # KEY PRESSES # ####################################################################### events = pygame.event.get() # Artificially add an arrow key to the events queue. Without this code, # holding a key down does nothing. if not events: keys = pygame.key.get_pressed() for key in hard_drop_key, left_key, right_key: if keys[key]: if last_movement > 150 or das_triggered: das_triggered = True events.append(pygame.event.Event(KEYDOWN, {'key': key})) for event in events: if event.type == KEYDOWN: key = event.key # Quit if key in quit_keys: running = False # Store piece and restart loop. elif key == hold_key: falling_piece, saved_piece = hold(falling_piece, saved_piece, gravity) # NOTE: not sure if these are necessary but they could save # the game from a few bugs. new_piece_pending = False das_triggered = False last_movement = 0 updateScreen() continue # Code related to user moving or rotating piece else: last_movement = 0 # Code for downward movement - does not affect shadow. if key in down_keys: if key in hard_drop_keys: if hard_drop_repeat_wait: continue lines_down = well_length else: lines_down = 1 successful_drops = 0 for i in range(lines_down): falling_piece.move(hard_drop_key) if needToRevert(falling_piece): falling_piece.move(cheat_key) # Override normal detection if key in hard_drop_no_wait_keys: new_piece_pending = True new_piece_pending_period = 0 hard_drop_repeat_wait = True hard_drop_repeat_wait_elapsed = 0 break successful_drops += 1 if display_points: points += Scoring.drop_points(successful_drops) updateText(point_surf, points) # Other movement else: # Let player move piece even around the bottom #new_piece_pending = False falling_piece.dispatch(key) shadow_moved = shadowMove(shadow_piece, key) # Try wall/floor kicks if a rotation was illegal. if needToRevert(falling_piece) and key in rotate_keys: kick(falling_piece) # Revert movement if it was illegal and can't be done. # shadowMove usually takes care of reverting itself but # since the dection is different we need to double # check here. if needToRevert(falling_piece): falling_piece.dispatch(opposite[key]) if shadow_moved: shadow_moved = shadowMove(shadow_piece, opposite[key]) if not shadow_moved: print('no revert = bad?') # If we just moved the piece left/right and it's now # over a gap, reset the new piece pending variables. #if key in left_right_keys: if True: falling_piece.move(hard_drop_key) if not needToRevert(falling_piece): new_piece_pending = False falling_piece.move(cheat_key) elif event.type == KEYUP: das_triggered = False if event.key in hard_drop_keys: hard_drop_repeat_wait = False elif event.type == QUIT: running = False ####################################################################### # PIECE MOVEMENT # ####################################################################### # Auto movement if not new_piece_pending and falling_piece.handleGravity(needToRevert): #reverted_downward_move = checkDownwardRevert(falling_piece) reverted_downward_move = True # If the shadow and the falling piece overlap completely, we're at the # bottom so let's just kill off the shadow. This is really just because # shadow movement is buggy and this avoids some corner cases. if len(groupcollide(falling_sprites, shadow_sprites)) >= \ len(falling_piece.getSprites()): resetShadow() # The piece can't move down farther if it just collided with another # piece or is currently colliding with the bottom row of invisible # blocks. if not new_piece_pending and ( reverted_downward_move or groupcollide(falling_sprites, well_rows[-1]) ): new_piece_pending = True new_piece_pending_elapsed = 0 # Piece is locked in. Check for row completion and eventually spawn a # new piece. if new_piece_pending and \ new_piece_pending_elapsed >= new_piece_pending_period: new_piece_pending = False # Transfer falling_sprites to piece_sprites and reset variables # related to the falling piece. piece_sprites.add(falling_sprites) falling_sprites = pygame.sprite.Group() resetShadow() # Check all rows for completion. rows_completed = 0 for i, row_sprites in enumerate(well_rows): sheet = well_sheets[i] # idx 0 will be None # 'collisions' will be a dict of Block objects that are in # 'piece_sprites'. collisions = groupcollide(piece_sprites, row_sprites) # Completed row! if len(collisions) == well_width: rows_completed += 1 # Delete the row for block in collisions: for piece in pieces: if block in piece.getSprites(): piece.remove(block) # We don't need to keep empty Piece objects around. if not piece.getSprites(): pieces.remove(piece) # Move other pieces down. for piece in pieces: piece.downIfCollide(sheet) # Check for new level or game over, depending on the mode. if display_lines: lines -= rows_completed updateText(lines_surf, lines) if lines <= 0: # New level if level_enabled: level += 1 lines, new_piece_pending_period, gravity = \ Level.updateLevel(level) updateText(level_surf, level) updateText(lines_surf, lines) # User cleared all the lines else: updateText(lines_surf, 0) print(timeObj(0, total_elapsed)[1]) gameOver() # Handle animations if display_lines and not level_enabled: if lines <= 10 and lines != last_line_animation: last_line_animation = lines animations.append(Animation(lines, clock, screen)) if display_points: points += Scoring.line_points(rows_completed) updateText(point_surf, points) falling_piece = newPiece(gravity) updateScreen()