def add_round(): round = Round(userId=request.json['userId'], teeboxId=request.json['teeboxId'], roundDate=request.json['roundDate']) db.session.add(round) db.session.commit() return jsonify(round.to_id_dict())
def handle(self, *args, **options): try: os.system('python3 manage.py makemigrations') os.system('python3 manage.py migrate') # 清空数据库 Score.objects.all().delete() Status.objects.all().delete() Flag.objects.all().delete() Logs.objects.all().delete() Round.objects.all().delete() Round(round_index=round_index).save() for i in status: Status(user_name=i[0], run=i[1], round_index=i[2]).save() for i in score: Score(user_name=i[0], fraction=i[1], token=i[2]).save() # for i in logs: # Logs( # user_name=i[0], # hacked_name=i[1], # flag_num=i[2], # info=i[3], # round_index=i[4], # result=i[5] # ).save() # for i in flags: # Flag( # user_name=i[0], # flag_num=i[1], # round_index=i[2] # ).save() self.stdout.write( self.style.SUCCESS('初始化成功,请尽情使用吧 (~o ̄▽ ̄)~o ~。。。')) except Exception: self.stdout.write(self.style.ERROR('命令执行出错'))
def post(self, request, **kwargs): if not request.user.is_authenticated: return redirect("competition_detail", name_id=self.name_id) if not self.competition.is_judge(request.user): return redirect("competition_detail", name_id=self.name_id) if not self.competition.is_private and self.competition.is_display: return redirect("competition_detail", name_id=self.name_id) self.competition.delete() Round.delete(self.competition.id) FeePerEvent.delete(self.competition.id) FeePerEventCount.delete(self.competition.id) return redirect("competition_create")
def set_choice(self, player_name, choice): """Add player choice to DB""" print 'Set choice for player {} - {}'.format(player_name, choice) player = Player.query.filter_by(name=player_name).first() if not self.round_id: cur_round = Round(round=self.round, game_id=self.game_id) db.session.add(cur_round) db.session.commit() print "ROUND", cur_round self.round_id = cur_round.id else: cur_round = Round.query.get(self.round_id) result = Result(round_id=cur_round.id, choice=choice, player_id=player.id) db.session.add(result) db.session.commit() db.session.close()
def get_workout_from_dom(dom: str) -> WorkoutSchema: soup = BeautifulSoup(dom, 'html.parser') all_dom_rounds = soup.select('.card') rounds = [] for dom_round in all_dom_rounds: dom_exercises = dom_round.find_all('a') exercises = [] for dom_exercise in dom_exercises: exercises.append( Exercise(title=dom_exercise.find('h6').string, quantity=dom_exercise.find('p').string)) rounds.append( Round( title=dom_round.find('h5').string, exercises=exercises, )) return Workout( title=soup.find('h3').string, rounds=rounds, )
def createround(): """ route for createround. gets data from CreateRoundForm and openweathermap,creates round and default values for scores. """ courses = Course.query.all() form = CreateRoundForm() if form.validate_on_submit(): course = Course.query.filter_by(coursename=form.course.data).first_or_404() today = datetime.today() """ Get icon of current weather based on course location """ key = os.getenv("OWM_KEY") owm = OWM(key) mgr = owm.weather_manager() observation = mgr.weather_at_place(course.courselocation) weather = observation.weather icon = weather.weather_icon_name round = Round(rounddate=today, roundweather=icon, rounduser_id= current_user.id ,roundcourse_id= course.id) db.session.add(round) db.session.commit() """ Create default values for scores """ holes = course.get_holes() holenum = 1 for hole in holes: roundscore = Roundscore(hole=holenum, score=hole.holepar, ob=False, round_id=round.id) db.session.add(roundscore) db.session.commit() holenum = holenum+1 flash('New round has been started!') holenum = 1 return redirect(url_for('roundscores', roundid = round.id, holenum = holenum)) return render_template('createround.html', title='Start new round', courses = courses, form=form)
def create_game(): form = CreateGameForm() if form.validate_on_submit(): new_game = Game(name=form.name.data, words_per_player=form.words_per_player.data, is_open=True, owner_player_id=g.current_player.id, created_at=datetime.utcnow()) db.session.add(new_game) db.session.flush() for i in range(min(10, form.number_of_rounds.data)): db.session.add( Round(game_id=new_game.id, round_number=i + 1, seconds_per_turn=form.seconds_per_turn.data)) db.session.commit() return redirect(url_for('.games')) return render_template('salad_bowl/actions/create_game.html', form=form, action_url=url_for('.create_game'))
def seed_rounds(): rounds = {} # TPC Championship (holes 1-18) rounds[1] = Round(userId=1, teeboxId=1, roundDate=datetime.datetime(2021, 3, 17)) rounds[2] = Round(userId=1, teeboxId=1, roundDate=datetime.datetime(2021, 3, 5)) rounds[3] = Round(userId=1, teeboxId=1, roundDate=datetime.datetime(2021, 1, 3)) rounds[4] = Round(userId=1, teeboxId=1, roundDate=datetime.datetime(2021, 1, 12)) rounds[5] = Round(userId=1, teeboxId=1, roundDate=datetime.datetime(2021, 2, 1)) rounds[6] = Round(userId=1, teeboxId=1, roundDate=datetime.datetime(2021, 2, 8)) # TPC Players (holes 19-36) rounds[7] = Round(userId=1, teeboxId=2, roundDate=datetime.datetime(2021, 2, 15)) rounds[8] = Round(userId=1, teeboxId=2, roundDate=datetime.datetime(2021, 3, 2)) rounds[9] = Round(userId=1, teeboxId=2, roundDate=datetime.datetime(2021, 1, 8)) rounds[10] = Round(userId=1, teeboxId=2, roundDate=datetime.datetime(2021, 1, 9)) rounds[11] = Round(userId=1, teeboxId=2, roundDate=datetime.datetime(2021, 1, 10)) rounds[12] = Round(userId=1, teeboxId=2, roundDate=datetime.datetime(2021, 2, 9)) # Ak-Chin Tips (holes 55-72) rounds[13] = Round(userId=1, teeboxId=4, roundDate=datetime.datetime(2021, 2, 10)) rounds[14] = Round(userId=1, teeboxId=4, roundDate=datetime.datetime(2021, 2, 11)) rounds[15] = Round(userId=1, teeboxId=4, roundDate=datetime.datetime(2021, 2, 12)) rounds[16] = Round(userId=1, teeboxId=4, roundDate=datetime.datetime(2021, 2, 13)) rounds[17] = Round(userId=1, teeboxId=4, roundDate=datetime.datetime(2021, 2, 21)) rounds[18] = Round(userId=1, teeboxId=4, roundDate=datetime.datetime(2021, 2, 22)) # Ak-Chin Gold (holes 73-90) rounds[19] = Round(userId=1, teeboxId=5, roundDate=datetime.datetime(2021, 2, 25)) rounds[20] = Round(userId=1, teeboxId=5, roundDate=datetime.datetime(2020, 12, 8)) rounds[21] = Round(userId=1, teeboxId=5, roundDate=datetime.datetime(2020, 12, 12)) rounds[22] = Round(userId=1, teeboxId=5, roundDate=datetime.datetime(2020, 12, 15)) rounds[23] = Round(userId=1, teeboxId=5, roundDate=datetime.datetime(2020, 12, 16)) rounds[24] = Round(userId=1, teeboxId=5, roundDate=datetime.datetime(2020, 12, 24)) for i in range(1, 25): db.session.add(rounds[i]) db.session.commit()
def handle(self, *args, **kwargs): person_list = {} persons = Person.objects.all() for person in persons: person_list[person.id] = person with open(self.get_fixtures_path("round")) as file: json_round = json.loads(file.read()) rounds = [] for record in json_round: round = Round( id=record["pk"], competition_id=record["fields"]["competition_id"], event_id=record["fields"]["event_id"], event_name=record["fields"]["event_name"], attempt_count=record["fields"]["attempt_count"], type=record["fields"]["type"], format_id=record["fields"]["format_id"], limit_type=record["fields"]["limit_type"], limit_time=record["fields"]["limit_time"], cutoff_attempt_count=record["fields"]["cutoff_attempt_count"], cutoff_time=record["fields"]["cutoff_time"], proceed_type=record["fields"]["proceed_type"], proceed_count=record["fields"]["proceed_count"], proceed_rate=record["fields"]["proceed_rate"], room_name=record["fields"]["room_name"], begin_at=record["fields"]["begin_at"], end_at=record["fields"]["end_at"], ) rounds.append(round) cursor = connection.cursor() cursor.execute("SET FOREIGN_KEY_CHECKS = 0") cursor.execute("TRUNCATE TABLE app_round") cursor.execute("SET FOREIGN_KEY_CHECKS = 1") Round.objects.bulk_create(rounds) # 参照のためdictとして保持 tmpRounds = {} for round in rounds: tmpRounds[round.id] = round with open(self.get_fixtures_path("result")) as file: json_result = json.loads(file.read()) results = [] for record in json_result: result = Result( id=record["pk"], competition_id=record["fields"]["competition_id"], event_id=record["fields"]["event_id"], person_id=record["fields"]["person_id"], round=tmpRounds[record["fields"]["round_id"]], rank=record["fields"]["rank"], best=record["fields"]["best"], average=record["fields"]["average"], value1=record["fields"]["value1"], value2=record["fields"]["value2"], value3=record["fields"]["value3"], value4=record["fields"]["value4"], value5=record["fields"]["value5"], ) results.append(result) cursor = connection.cursor() cursor.execute("TRUNCATE TABLE app_result") Result.objects.bulk_create(results) with open(self.get_fixtures_path("averagerank")) as file: json_average_rank = json.loads(file.read()) average_ranks = [] for record in json_average_rank: average_rank = AverageRank( id=record["pk"], person=person_list[record["fields"]["person_id"]], event_id=record["fields"]["event_id"], competition_id=record["fields"]["competition_id"], competition_name_id=record["fields"]["competition_name_id"], competition_name=record["fields"]["competition_name"], year=record["fields"]["year"], best=record["fields"]["best"], value1=record["fields"]["value1"], value2=record["fields"]["value2"], value3=record["fields"]["value3"], value4=record["fields"]["value4"], value5=record["fields"]["value5"], gender=record["fields"]["gender"], generation=record["fields"]["generation"], prefecture_id=record["fields"]["prefecture_id"], rank=record["fields"]["rank"], gender_rank=record["fields"]["gender_rank"], generation_rank=record["fields"]["generation_rank"], prefecture_rank=record["fields"]["prefecture_rank"], ) average_ranks.append(average_rank) cursor = connection.cursor() cursor.execute("TRUNCATE TABLE app_averagerank") AverageRank.objects.bulk_create(average_ranks) with open(self.get_fixtures_path("bestrank")) as file: json_best_rank = json.loads(file.read()) best_ranks = [] for record in json_best_rank: best_rank = BestRank( id=record["pk"], person=person_list[record["fields"]["person_id"]], event_id=record["fields"]["event_id"], competition_id=record["fields"]["competition_id"], competition_name_id=record["fields"]["competition_name_id"], competition_name=record["fields"]["competition_name"], year=record["fields"]["year"], best=record["fields"]["best"], gender=record["fields"]["gender"], generation=record["fields"]["generation"], prefecture_id=record["fields"]["prefecture_id"], rank=record["fields"]["rank"], gender_rank=record["fields"]["gender_rank"], generation_rank=record["fields"]["generation_rank"], prefecture_rank=record["fields"]["prefecture_rank"], ) best_ranks.append(best_rank) cursor = connection.cursor() cursor.execute("TRUNCATE TABLE app_bestrank") BestRank.objects.bulk_create(best_ranks) with open(self.get_fixtures_path("competition")) as file: json_competition = json.loads(file.read()) competitions = [] for record in json_competition: registration_open_at = None registration_close_at = None if ( record["fields"]["registration_open_at"] != "" or record["fields"]["registration_close_at"] != "" ): registration_open_at = record["fields"]["registration_open_at"] registration_close_at = record["fields"]["registration_close_at"] competition = Competition( id=record["fields"]["id"], type=record["fields"]["type"], name=record["fields"]["name"], name_id=record["fields"]["name_id"], open_at=record["fields"]["open_at"], close_at=record["fields"]["close_at"], registration_open_at=registration_open_at, registration_close_at=registration_close_at, is_registration_at_other=record["fields"][ "is_registration_at_other" ], registration_url=record["fields"]["registration_url"], stripe_user_person_id=record["fields"]["stripe_user_person_id"], judge_person_ids=record["fields"]["judge_person_ids"], event_ids=record["fields"]["event_ids"], prefecture_id=record["fields"]["prefecture_id"], organizer_name=record["fields"]["organizer_name"], organizer_email=record["fields"]["organizer_email"], organizer_person_ids=record["fields"]["organizer_person_ids"], venue_name=record["fields"]["venue_name"], venue_address=record["fields"]["venue_address"], venue_url=record["fields"]["venue_url"], latitude=record["fields"]["latitude"], longitude=record["fields"]["longitude"], limit=record["fields"]["limit"], guest_limit=record["fields"]["guest_limit"], is_display_pending_competitor=record["fields"][ "is_display_pending_competitor" ], fee_pay_type=record["fields"]["fee_pay_type"], fee_calc_type=record["fields"]["fee_calc_type"], fee_pay_close_at=record["fields"]["fee_pay_close_at"], twin_competition_id=record["fields"]["twin_competition_id"], description=record["fields"]["description"], description_en=record["fields"]["description_en"], qualification_description=record["fields"][ "qualification_description" ], qualification_description_en=record["fields"][ "qualification_description_en" ], disclaimer=record["fields"]["disclaimer"], disclaimer_en=record["fields"]["disclaimer_en"], refund_description=record["fields"]["refund_description"], refund_description_en=record["fields"]["refund_description_en"], awards_description=record["fields"]["awards_description"], awards_description_en=record["fields"]["awards_description_en"], assignment_description=record["fields"]["assignment_description"], assignment_description_en=record["fields"][ "assignment_description_en" ], visitor_description=record["fields"]["visitor_description"], visitor_description_en=record["fields"]["visitor_description_en"], is_cancel=record["fields"]["is_cancel"], is_payment=record["fields"]["is_payment"], is_display=record["fields"]["is_display"], is_private=record["fields"]["is_private"], ) competitions.append(competition) cursor = connection.cursor() cursor.execute("TRUNCATE TABLE app_competition") Competition.objects.bulk_create(competitions) with open(self.get_fixtures_path("scramble")) as file: json_scramble = json.loads(file.read()) scrambles = [] for record in json_scramble: scramble = Scramble( id=record["pk"], competition_id=record["fields"]["competition_id"], event_id=record["fields"]["event_id"], round_id=record["fields"]["round_id"], group_id=record["fields"]["group_id"], scramble=record["fields"]["scramble"], ) scrambles.append(scramble) cursor = connection.cursor() cursor.execute("TRUNCATE TABLE app_scramble") Scramble.objects.bulk_create(scrambles) with open(self.get_fixtures_path("feeperevent")) as file: json_fee_per_event = json.loads(file.read()) fee_per_events = [] for record in json_fee_per_event: fee_per_event = FeePerEvent( id=record["pk"], competition_id=record["fields"]["competition_id"], event_id=record["fields"]["event_id"], price=record["fields"]["price"], prepaid_price=record["fields"]["prepaid_price"], ) fee_per_events.append(fee_per_event) cursor = connection.cursor() cursor.execute("TRUNCATE TABLE app_feeperevent") FeePerEvent.objects.bulk_create(fee_per_events) with open(self.get_fixtures_path("feepereventcount")) as file: json_fee_per_event_count = json.loads(file.read()) fee_per_event_counts = [] for record in json_fee_per_event_count: fee_per_event_count = FeePerEventCount( id=record["pk"], competition_id=record["fields"]["competition_id"], event_count=record["fields"]["event_count"], price=record["fields"]["price"], prepaid_price=record["fields"]["prepaid_price"], ) fee_per_event_counts.append(fee_per_event_count) cursor = connection.cursor() cursor.execute("TRUNCATE TABLE app_feepereventcount") FeePerEventCount.objects.bulk_create(fee_per_event_counts)
def end_round(request, game_id, round_id): t = datetime.now() logging.debug('task end round started on game:%s round:%s' % \ (game_id, round_id)) round = Round.all().filter('uid', round_id).get() game = round.game if not round.uid == game.get_current_round().uid: raise FactionizeTaskException, 'Round argument is not the current round. Check if task has been repeated' village_thread = round.get_thread(role_vanillager) sheriff_thread = round.get_thread(role_sheriff) doctor_thread = round.get_thread(role_doctor) mafia_thread = round.get_thread(role_mafia) vote_death_role = get_thread_highest_vote(village_thread) logging.debug(('game:%s round:%s vote kill role_id:%s (%s) ' + \ 'profile_name:%s google_id:%s') % \ (game.uid, round.uid, vote_death_role.uid, vote_death_role.name, vote_death_role.player.name, vote_death_role.player.user.user_id())) if vote_death_role.name in [role_sheriff, role_doctor]: kill_in_threads(vote_death_role, [doctor_thread, sheriff_thread]) vote_death_role.kill(role_vanillager, round.number) death = DeathByVote(actor=vote_death_role, vote_thread=village_thread, thread=village_thread) doctor_saves = [x.role for x in filter(lambda x: x.total, doctor_thread.votesummary_set) \ if x.total] sheriff_reveals = [x.role for x in filter(lambda x: x.total, sheriff_thread.votesummary_set) \ if x.total] sheriff_reveals = filter(lambda x: x.uid != vote_death_role.uid, sheriff_reveals) if len(sheriff_reveals): # we know a reveal is valid and who should be revealed, but # not who did it, so figure that out revealers = filter_invalidated(Vote.all().filter('thread', sheriff_thread)) for r in revealers: logging.debug(('game:%s round:%s sheriff reveal actor:%s ' + \ 'target:%s role:%s') % \ (game.uid, round.uid, r.actor.uid, r.target.uid, r.target.name)) reveal = Reveal(actor=r.actor, target=r.target, thread=r.thread) reveal.put() mafia_vote_death = get_thread_highest_vote(mafia_thread) if mafia_vote_death.uid in [ds.uid for ds in doctor_saves]: # we know that somebody successfully saved, but not who yet # figure that out here saviours = filter_invalidated(Vote.all().filter('thread', doctor_thread)) for s in filter(lambda x: x.target.uid == mafia_vote_death.uid, saviours): logging.debug(('game:%s round:%s nurse save actor:%s target:%s' + \ 'role:%s') % \ (game.uid, round.uid, s.actor.uid, s.target.uid, s.target.name)) save = Save(actor=s.actor, target=s.target, thread=village_thread) save.put() else: logging.debug(('game:%s round:%s mafia kill role_id:%s (%s) ' + \ 'profile_name:%s google_id:%s') % \ (game.uid, round.uid, mafia_vote_death.uid, mafia_vote_death.name, mafia_vote_death.player.name, mafia_vote_death.player.user.user_id())) mafia_vote_death.kill(role_mafia, round.number) death = DeathByVote(actor=mafia_vote_death, vote_thread=mafia_thread, thread=village_thread) death.put() if not game.is_over(): logging.debug('game:%s round:%s starting next round' % \ (game.uid, round.uid)) r = game.start_next_round() logging.debug('game:%s started new round:%s' % (game.uid, r.uid)) assert r.number == round.number + 1 # sanity check taskqueue.add(url=reverse('end_round', kwargs={'game_id':game.uid, 'round_id':r.uid}), method='POST', countdown=r.length()) else: logging.debug('game:%s round:%s has hit the end game condition' % \ (game.uid, round.uid)) taskqueue.add(url=reverse('end_game', kwargs={'game_id':game.uid}), method='POST') logging.debug('game:%s round:%s end round total_time:%s' % \ (game.uid, round.uid, (datetime.now() - t).seconds)) return HttpResponse('ok', status=200)