def main(submissionfile, goldstandard, results, path_to_treecmp): """Get scores and write results to json Args: submissionfile: Participant submission file path goldstandard: Goldstandard file path results: File to write results to path_to_treecmp: Path to TreeCmp """ score_dict = {} prediction_file_status = "SCORED" rooted_submission_path = score.reroot_and_remap_submission(submissionfile) scores = score.get_scores(goldstandard, rooted_submission_path, "treecmp_results.out", path_to_treecmp) n = scores.T[0].loc['Common_taxa'] rf = scores.T[0].loc['R-F_Cluster'] triples = scores.T[0].loc['Triples'] triples_score = 3 * triples / (2 * scipy.special.comb(n, 3, repetition=False)) rf_score = rf / (n - 3) score_dict['RF'] = min(1, rf_score) score_dict['Triples'] = min(1, triples_score) score_dict['prediction_file_status'] = prediction_file_status with open(results, 'w') as output: output.write(json.dumps(score_dict))
def build_ranking_data(request): start_time = time.time() scores = get_scores(request.user.player.bet_room) elapsed_time = time.time() - start_time print '[build_ranking_data.1]: %.3f' % (elapsed_time) start_time = time.time() current_games = Game.get_current_games() current_games_bets = [] my_current_games_bets = [] ranking = 1 previous_score = None for score in scores: """ adding ranking to each score """ if previous_score is not None: if previous_score.total_score != score.total_score: score.ranking = ranking else: score.ranking = None else: score.ranking = ranking ranking += 1 previous_score = score score.set_games_for_variation(current_games) game_bets = [] for game in current_games: next_bet = score.get_bet(game.id) if score.player == request.user.player: my_current_games_bets.append(next_bet) else: game_bets.append(next_bet) if score.player != request.user.player: current_games_bets.append({'first_name': score.player.user.first_name, 'last_name': score.player.user.last_name, 'bets': game_bets}) elapsed_time = time.time() - start_time print '[build_ranking_data.2]: %.3f' % (elapsed_time) return current_games, current_games_bets, my_current_games_bets, scores
def main(submissionfile, goldstandard, results, path_to_treecmp): """Get scores and write results to json Args: submissionfile: Participant submission file path goldstandard: Goldstandard file path results: File to write results to path_to_treecmp: Path to TreeCmp """ score_dict = {} prediction_file_status = "SCORED" submissiondf = pd.read_csv(submissionfile, sep="\t") goldstandarddf = pd.read_csv(goldstandard, sep="\t") # Match dreamID mergeddf = submissiondf.merge(goldstandarddf, on="dreamID") rf_scores = [] triple_scores = [] scores_per_tree = [] for _, row in mergeddf.iterrows(): with open("truth.nwk", 'w') as truth: truth.write(row['ground']) with open("sub.nwk", 'w') as sub: sub.write(row['nw']) rooted_submission_path = score.reroot_and_remap_submission("sub.nwk") scores = score.get_scores("truth.nwk", rooted_submission_path, "treecmp_results.out", path_to_treecmp) tree_scores = [ str(x) for x in (row['dreamID'], min(1, scores.T[0].loc['R-F_Cluster_toYuleAvg']), min(1, scores.T[0].loc['Triples_toYuleAvg'])) ] scores_per_tree.append("\t".join(tree_scores)) rf_scores.append(min(1, scores.T[0].loc['R-F_Cluster_toYuleAvg'])) triple_scores.append(min(1, scores.T[0].loc['Triples_toYuleAvg'])) score_dict['RF_average'] = sum(rf_scores) / len(rf_scores) score_dict['Triples_average'] = sum(triple_scores) / len(triple_scores) score_dict['prediction_file_status'] = prediction_file_status print("id\tRF\ttriplet") print("\n".join(scores_per_tree)) with open(results, 'w') as o: o.write(json.dumps(score_dict))
def eval_step(eval_data_iter: Iterator[Tensor], critic: Callable[[Tensor], Tensor], generator: Callable[[Optional[Tensor]], Tensor]): # Warmup generator, to calculate appropriate batch statistics (bc of BN) generator.train() for mod in generator.modules(): try: mod.reset_running_stats() except AttributeError: pass for _ in range(1000): generator() average_cp = average_meter() average_cq = average_meter() with eval_ctx(critic, generator): # Run samples through the critic for p in eval_data_iter: q = generator() cp = critic(p) cq = critic(q) average_cp.update(cp) average_cq.update(cq) # Get generated samples from persiting test noise samples = generator(persisting_Z.to(device=device)) # Get Inception Score and Fréchet Inception Distance IS, _, _, FID = score.get_scores(generator, test_filename=stats_filename, net=inception_net) results = dict(IS=float(IS), FID=float(FID), cp=float(average_cp.avg), cq=float(average_cq.avg)) return samples, results
def autoreply(request): try: webData = request.body xmlData = ET.fromstring(webData) msg_type = xmlData.find('MsgType').text ToUserName = xmlData.find('ToUserName').text FromUserName = xmlData.find('FromUserName').text # CreateTime = xmlData.find('CreateTime').text # MsgType = xmlData.find('MsgType').text # MsgId = xmlData.find('MsgId').text toUser = FromUserName fromUser = ToUserName if msg_type == 'text': content = xmlData.find('Content').text if '成绩' == content[0:2]: content_list = re.split('[_#|+\s\t\n]', content) username = content_list[1] password = content_list[2] names, scores = get_scores(username, password) content = '' if not names: return "success" for i in range(len(scores)): if scores[i] != '': content += names[i] + '\t' + scores[i] + '\n' elif content.isdigit(): content = express(content) if content == 'error': return "success" else: return "success" replyMsg = TextMsg(toUser, fromUser, content) return replyMsg.send() elif msg_type == 'image': # content = "图片" content = "success" # replyMsg = TextMsg(toUser, fromUser, content) return content #replyMsg.send() elif msg_type == 'voice': # content = "语音" content = "success" # replyMsg = TextMsg(toUser, fromUser, content) return content #replyMsg.send() elif msg_type == 'video': # content = "视频" content = "success" # replyMsg = TextMsg(toUser, fromUser, content) return content #replyMsg.send() elif msg_type == 'shortvideo': # content = "小视频" content = "success" #replyMsg = TextMsg(toUser, fromUser, content) return content #replyMsg.send() elif msg_type == 'location': x = float(xmlData.find('Location_X').text) y = float(xmlData.find('Location_Y').text) content = get_weather(y, x) replyMsg = TextMsg(toUser, fromUser, content) return replyMsg.send() elif msg_type == 'event': event = xmlData.find('Event').text if event == "subscribe": replyMsg = EventMsg(toUser, fromUser) # replyMsg = TextMsg(toUser, fromUser, event) return replyMsg.send() else: content = "我会想你的~" replyMsg = TextMsg(toUser, fromUser, content) return replyMsg.send() # replyMsg = TextMsg(toUser, fromUser, event) # return replyMsg.send() else: # content = "链接" content = msg_type replyMsg = TextMsg(toUser, fromUser, content) return content #replyMsg.send() except Exception, Argment: replyMsg = TextMsg(toUser, fromUser, Argment) return replyMsg.send()
from score import get_scores print get_scores()
def on_draw(): global g_o_text, spr_shield_life, spr_life, shield_life, life, spr_options, Explosion_list, player_melee, game_screen, spr_player_bullets, Player_Bullets, Enemy_list, Enemy_Bullets, spr_enemy_bullets, spr_btn_continue, spr_btn_ng, spr_btn_score, spr_btn_help if game_screen == 0: game_window.clear() if stroy_index == 0: game_background.draw() spr_btn_start.draw() elif stroy_index <= len(story_text): story_background.draw() spr = pyglet.text.Label(story_text[stroy_index - 1], font_name='Times New Roman', font_size=20, x=300, y=400, width=500, anchor_x='center', anchor_y='center', multiline=True) spr.draw() pass else: game_screen = 1 elif game_screen == 1: game_window.clear() game_menu.draw() #spr_btn_continue.draw() spr_btn_ng.draw() spr_btn_score.draw() spr_btn_help.draw() elif game_screen == 2: if pause == False: game_window.clear() game_background_2.draw() spr_player.rotation = rotate_sprite(temp_x, temp_y) spr_player.scale = 0.75 spr_player.draw() #resources.bg_music.play() if player_melee: spr_sword.draw() #==================================Drawing player shield and life spr_shield_life = [] spr_life = [] for b in range(int(shield_life // 5)): spr_shield_life.append( pyglet.sprite.Sprite(img=resources.square_blue, x=20 + (b * 22), y=50, group=group_foreground)) for b in range(life): spr_life.append( pyglet.sprite.Sprite(img=resources.square_red, x=20 + (b * 22), y=30, group=group_foreground)) for b in spr_shield_life: b.draw() for b in spr_life: b.draw() #===================================Drawing Player bullets======================= spr_player_bullets = [] for b in Player_Bullets: if b.modifiers["homing"] and b.modifiers["explosive"]: spr_player_bullets.append( pyglet.sprite.Sprite(img=resources.bullet_exhoming, x=b.obj_x, y=b.obj_y, group=group_midground)) elif b.modifiers["homing"]: spr_player_bullets.append( pyglet.sprite.Sprite(img=resources.bullet_homing, x=b.obj_x, y=b.obj_y, group=group_midground)) elif b.modifiers["explosive"]: spr_player_bullets.append( pyglet.sprite.Sprite(img=resources.bullet_explosive, x=b.obj_x, y=b.obj_y, group=group_midground)) elif b.modifiers["piercing"]: spr_player_bullets.append( pyglet.sprite.Sprite(img=resources.bullet_piercing, x=b.obj_x, y=b.obj_y, group=group_midground)) else: spr_player_bullets.append( pyglet.sprite.Sprite(img=resources.bullet_player, x=b.obj_x, y=b.obj_y, group=group_midground)) for b in spr_player_bullets: b.draw() #===================================Drawing Enemy bullet============================== spr_enemy_bullets = [] for b in Enemy_Bullets: if b.modifiers["homing"] and b.modifiers["explosive"]: spr_enemy_bullets.append( pyglet.sprite.Sprite(img=resources.bullet_exhoming, x=b.obj_x, y=b.obj_y, group=group_midground)) elif b.modifiers["homing"]: spr_enemy_bullets.append( pyglet.sprite.Sprite(img=resources.bullet_homing, x=b.obj_x, y=b.obj_y, group=group_midground)) elif b.modifiers["explosive"]: spr_enemy_bullets.append( pyglet.sprite.Sprite(img=resources.bullet_explosive, x=b.obj_x, y=b.obj_y, group=group_midground)) elif b.modifiers["piercing"]: spr_enemy_bullets.append( pyglet.sprite.Sprite(img=resources.bullet_piercing, x=b.obj_x, y=b.obj_y, group=group_midground)) else: spr_enemy_bullets.append( pyglet.sprite.Sprite(img=resources.bullet_enemy, x=b.obj_x, y=b.obj_y, group=group_midground)) spr_enemy_bullets[-1].rotation = ( rotate_sprite(b.obj_vx, b.obj_vy) + 180) / 2 for b in spr_enemy_bullets: b.draw() spr_enemy_list = [] for b in Enemy_list: if b.id == "easy_1" or b.id == 'easy_0': #image of enemy row for now spr_enemy_list.append( pyglet.sprite.Sprite(img=resources.enemy_1_image, x=b.x, y=b.y, group=group_foreground)) if b.id == "easy_2": spr_enemy_list.append( pyglet.sprite.Sprite(img=resources.enemy_2_image, x=b.x, y=b.y, group=group_foreground)) if b.id == "easy_3": spr_enemy_list.append( pyglet.sprite.Sprite(img=resources.enemy_3_image, x=b.x, y=b.y, group=group_foreground)) if b.id == "easy_4": spr_enemy_list.append( pyglet.sprite.Sprite(img=resources.enemy_4_image, x=b.x, y=b.y, group=group_foreground)) if b.id == "med_1": spr_enemy_list.append( pyglet.sprite.Sprite(img=resources.enemy_5_image, x=b.x, y=b.y, group=group_foreground)) if b.id == "med_2": spr_enemy_list.append( pyglet.sprite.Sprite(img=resources.enemy_6_image, x=b.x, y=b.y, group=group_foreground)) if b.id == "med_3": spr_enemy_list.append( pyglet.sprite.Sprite(img=resources.enemy_7_image, x=b.x, y=b.y, group=group_foreground)) if b.id == "hard_1": spr_enemy_list.append( pyglet.sprite.Sprite(img=resources.enemy_8_image, x=b.x, y=b.y, group=group_foreground)) if b.id == "hard_2": spr_enemy_list.append( pyglet.sprite.Sprite(img=resources.enemy_9_image, x=b.x, y=b.y, group=group_foreground)) if b.id == "hard_3": spr_enemy_list.append( pyglet.sprite.Sprite(img=resources.enemy_10_image, x=b.x, y=b.y, group=group_foreground)) for b in spr_enemy_list: b = shrink_2(b) b.draw() spr_explosion_list = [] remove_explosion_list = [] for b in Explosion_list: spr_explosion_list.append( pyglet.sprite.Sprite(img=resources.bullet_explosion, x=b.x, y=b.y, group=group_foreground)) spr_explosion_list[-1].scale = b.radius * (b.timer / b.duration) if b.timer > b.duration: remove_explosion_list.append(b) else: b.timer += 1 for b in remove_explosion_list: Explosion_list.remove(b) for b in spr_explosion_list: b.draw() else: game_window.clear() spr_lvl_up.draw() for b in spr_options: b.draw() elif game_screen == 3: #score screen game_window.clear() game_background_2.draw() temp = 'HIGHSCORES:\n' scores = score.get_scores() for i in range(0, len(scores)): temp += str(i + 1) + '.\t\t' + str(scores[i]) + '\n' label = pyglet.text.Label(temp.strip(), font_name='Times New Roman', font_size=24, x=300, y=400, width=500, anchor_x='center', anchor_y='center', multiline=True) label.draw() elif game_screen == 4: #game over screen game_window.clear() #name = self.widgets[0].document.print(name) spr = pyglet.text.Label(g_o_text, font_name='Times New Roman', font_size=36, x=300, y=400, width=500, anchor_x='center', anchor_y='center', multiline=True) spr.draw() elif game_screen == 5: #help screen game_window.clear() spr = pyglet.text.Label(help_text, font_name='Times New Roman', font_size=22, x=300, y=400, width=500, anchor_x='center', anchor_y='center', multiline=True) spr.draw()
import db import config from email_client import Email_Client from score import get_scores # Flask app configuration app = Flask("ACM_WC", static_folder=config.STATIC_DIR, template_folder=config.TEMPLATES_DIR) app.secret_key = config.SECRET_KEY app.config["SESSION_REFRESH_EACH_REQUEST"] = True app.config["SESSION_COOKIE_HTTPONLY"] = True app.config['UPLOAD_FOLDER'] = config.SUBMISSION_DIR mail_client = Email_Client(**config.email_config) USER_SCORES = get_scores() @app.route("/netsoc-policy", methods=["GET"]) def netsoc_policy(): return render_template("netsoc_policy.html") @app.route("/cookies-policy", methods=["GET"]) def cookies_policy(): return render_template("cookies_policy.html", COOKIES_NOTIFICATION=tools.show_cookies_policy(), LOGGED_IN=tools.is_logged_in()) @app.route("/data-protection", methods=["GET"])