def create_team(): user = session['user'] if user['type'] != 'Mentor': return redirect(url_for('index')) if request.method == 'POST': team_name = request.form['new_team_name'] chosen_members = [] member1 = request.form['member1'] member2 = request.form['member2'] member3 = request.form['member3'] member4 = request.form['member4'] if member1: chosen_members.append(Student.get_student_by_id(member1)) if member2: chosen_members.append(Student.get_student_by_id(member2)) if member3: chosen_members.append(Student.get_student_by_id(member3)) if member4: chosen_members.append(Student.get_student_by_id(member4)) if len(team_name) > 0: Team.add_new_team(team_name, chosen_members) return redirect('teams.html') return render_template('team_create.html', student_list=Student.get_list_of_students(), user=user)
def generate_sections_summary_table(target_file): match_quantity = model.match.get_match_quantity() sections = Team.objects().distinct('section') with open(target_file, 'w', encoding='ANSI') as f: add_cell(f, "ID") add_cell(f, "Section") for i in range(1, match_quantity + 1): add_cell(f, i) f.write("\n") add_cell(f) add_cell(f) schedules = service.get_all_schedules() for schedule in schedules: add_cell(f, schedule) f.write("\n") for section in sections: team_codes = list() teams = Team.objects(section=section).order_by('code') for team in teams: team_codes.append(team.code) add_cell(f, "{} - {}".format(team_codes[0], team_codes[-1])) add_cell(f, section) for i in range(1, match_quantity + 1): games = list() for team in teams: for match in team.matches: if match.time == i: games.append(match.game_number) add_cell(f, ', '.join(str(x) for x in sorted(games))) f.write("\n")
def get_team(team_uuid): conn = _connect() # todo use connection as context manager c = conn.cursor() query = """SELECT id, name, description, photo_url, team_uuid FROM team WHERE team_uuid=?""" c.execute(query, (team_uuid,)) t = c.fetchone() if t is None: return None created_team = Team(id=t[0], name=t[1], description=t[2], photo_url=t[3], team_uuid=t[4]) member_query = """SELECT id, first_name, last_name, email, phone_number, school, city FROM team_member WHERE team_id=?""" c.execute(member_query, (created_team.id,)) members = c.fetchall() for m in members: created_member = TeamMember(id=m[0], first_name=m[1], last_name=m[2], email=m[3], phone_number=m[4], school=m[5], city=m[6], team=created_team) created_team.add_member(created_member) conn.commit() c.close() conn.close() return created_team
def AssignTeam(self, team_id: int, station: str): team_id = int(team_id) if station not in self.alliance_stations: return "Invalid alliance station" dsconn = self.alliance_stations[station].driverstation_connection if dsconn != None and dsconn.team_id == team_id: return None if dsconn != None: dsconn.Close() self.alliance_stations[station].team = None self.alliance_stations[station].driverstation_connection = None if team_id == 0: self.alliance_stations[station].team = None return None team = Team() team.id = team_id self.alliance_stations[station].team = team notice(f"Team {team_id} has been assigned to station {station}") return None
def create_team(self, team, members): if not team: return None t = Team(*team[:2]) t.add_members([member for _, member in members]) return t
def get_team(self, team_type, attrib): try: team = Team() team.code = attrib['%s_team_code' % team_type] team.name = attrib['%s_fname' % team_type] team.mlb_id = int(attrib['%s_id' % team_type]) return team except: return None
def parseSeason(name, seasonUrl): data = urllib2.urlopen(seasonUrl) soup = BeautifulSoup(data.read()) teams = [] divisions = [] divisionSet = set() currentDivision = None divisionLevels = dict() seasonId = None divisionLevel = 1 season = Season() season.name = name season.url = seasonUrl teamId = 1 divisionId = 1 for link in soup.find_all('a'): hrefVal = link.get('href') if hrefVal and hrefVal.startswith('display-schedule.php'): #print 'Team name is: ' + link.string + ' : ' + hrefVal if seasonId is None: seasonId = getSeason(hrefVal) team = Team() team.url = hrefVal team.name = link.string team.teamId = teamId teamId += 1 team.players = parseTeam(baseUrl + hrefVal) if (currentDivision) : currentDivision.teams.append(team) elif not hrefVal : test = link.string.split() division = test[1] #print 'Division: ' + division # Only process if division not in divisionSet: divisionSet.add(division) divisions.append(division) divisionLevels[division] = divisionLevel divisionLevel += 1 currentDivision = Division() currentDivision.level = divisionLevel divisionId += 1 currentDivision.divisionId =divisionId currentDivision.name = link.string season.divisions.append(currentDivision ) season.seasonId = seasonId return season
def get_ranking(gender=None): """ Get the ranking by team. :param gender: (optional) filter the ranking on a gender :return: list of tuples (team code, section, score) """ teams = Team.objects(sex=gender) if gender else Team.objects() scores = list() for team in teams: scores.append((team.code, team.section, get_score(team.code)[0])) return sorted(scores, key=lambda xyz: xyz[2], reverse=True)
def get_ranking_by_section(gender_filter=None): """ Get the ranking by section. Scores is based on the average of all the teams of each section :param gender_filter: (optional) filter the ranking on a gender :return: list of tuples (section, mean score) """ if gender_filter: sections = Team.objects(sex=gender_filter).distinct('section') else: sections = Team.objects().distinct('section') section_scores = dict() for section in sections: section_scores[section] = get_section_score(section) return sorted(section_scores.items(), key=lambda kv: kv[1], reverse=True)
def __fetch_to_object(self, fetchresult, return_one=False): liste = [] try: if len(fetchresult) > 0: for fetch in fetchresult: obj = Team(fetch[0], fetch[2], fetch[3]) obj.id = fetch[1] liste.append(obj) return liste if not return_one else liste[0] else: return None except Exception as ex: DAOException(self, ex)
def add_team(self, team_name, admin_name): if team_name not in self.teams.keys(): if self.teams_db.add_team(team_name, admin_name): self.teams[team_name] = Team(team_name, admin_name) return True return False
def generate_team_roadmaps(target_file): files_to_merge = list() with tempfile.TemporaryDirectory() as tmpdir: for team in Team.objects(): tpl = DocxTemplate(TEAM_ROADMAP_TEMPLATE) qr = pyqrcode.create(team.hash, error=QR_ERROR, version=QR_VERSION) qr_file = os.path.join(tmpdir, "team.png") qr.png(qr_file, scale=QR_SCALE, module_color=QR_COLOR, quiet_zone=QUIET_ZONE) context = dict(section=team.section, teamCode=team.code, qrCode=InlineImage(tpl, qr_file, width=Mm(QR_SIZE))) for i, match in enumerate(team.matches, 1): game_number = match.game_number context["game{}".format(i)] = Game.objects( number=game_number).get().name context["gId{}".format(i)] = str(game_number) tpl.render(context) team_file = os.path.join(tmpdir, "team{}.docx".format(team.code)) tpl.save(team_file) files_to_merge.append(team_file) _combine_docx(target_file, files_to_merge)
def display_teams(): user = session['user'] if user['type'] != 'Mentor': return redirect(url_for('index')) return render_template('teams.html', teams=Team.get_list_of_teams(), user=user)
def team_details(team_id): user = session['user'] if user['type'] != 'Mentor': return redirect(url_for('index')) return render_template('team_details.html', person=Team.get_team_details(team_id), user=user)
def assignment_submit(assignments_id): """ Student submit assignment :param assignments_id: :return: """ assignment = Assignment.get_by_id(assignments_id) submit = Submition.get_submit( user_session(session['user'], session['type']).id, assignments_id) if request.method == "POST": content = request.form['content'] if assignment.type == 'group': team_id = user_session(session['user'], session['type']).team_id team = Team.get_by_id(team_id) team_members = team.get_members() for student in team_members: submit = Submition.get_submit(student.id, assignments_id) submit.change_content(content) else: submit.change_content(content) return redirect( url_for('assignment_controller.view_assignments', assignments_id=assignments_id)) return render_template('stud-submit.html', user=user_session(session['user'], session['type']), assignment=assignment, submit=submit)
def set_player_codes(): """ Set players codes in all the Match objects """ for match in Match.objects(): for number in match.players_number: match.players_code.append(Team.objects(number=number).get().code) match.save()
def resolve_hash(hash_value): game = Game.objects(hash=hash_value).first() if game: return game.number try: return Team.objects(hash=hash_value).get().code except DoesNotExist: raise BadenException( "No teams nor games found for hash {}".format(hash_value))
def parse(cls, raw_message: str) -> StoreTeam: print('parsing sign') try: command_lines = cls.__get_rows(raw_message) team = command_lines[0] league = command_lines[1] members = command_lines[2:] players = [] captain = '' team_tag = cls.__get_team_tag(team) team_name = team.replace(team_tag, '')[:-1] for member in members: name = cls.__get_id(cls.__get_mention(member)) role = cls.__get_role(member) profile_link = cls.__get_profile_link(member) if role == RoleEnum.CAPTAIN.value: captain = Captain(name, team_name, profile_link) else: players.append(TeamMember(name, team_name, profile_link)) league_name = cls.__get_league_name(league) if captain != '': signed_team = StoreTeam(Team(team_name, league_name, team_tag), captain, players) else: raise CommandParserException('Please enter a team captain') return signed_team except CouldNotFindTeamNameException: raise CommandParserException('Please enter team name right') except CouldNotFindCaptainNameException: raise CommandParserException('Please enter captain name right') except LeagueNameParseException: raise CommandParserException('Please enter league name right') except NoTeamTagException: raise CommandParserException('Please enter team tag right') except MentionParseException: raise CommandParserException( 'Please make sure mentioned players appear in blue, links are in the same row as player and picture is a file and not a link' ) except NoRoleException: raise CommandParserException( 'Please make sure you enter roles as shown in the example') except WrongLinkException: raise CommandParserException( 'Please make sure you use an r6stats link') except BadUrlFormatException: raise CommandParserException( 'Please make sure you are using an https://r6stats.com/stats/ link' ) except URLNotFoundException: raise CommandParserException( 'Please enter a link to you r6stats profile')
def add_team(): """ Return team_form.html POST: Add team to database basing on data from request.form['name'] and redirect user to list-teams definition. """ if request.method == 'POST': Team(request.form['name']).add_team() flash('Team was added') return redirect('list-teams') return render_template("team_form.html", user=user_session(session['user'], session['type']))
def get_section_score(section): """ Get the mean score of a given section :param section: a section name :return: the mean score """ scores = list() teams = Team.objects(section=section) for team in teams: if not team.ignore_score: scores.append(get_score(team.code)[0]) return sum(scores) / len(scores)
def create_team(self, name, homepage, actual_rank, hltv_id): c1 = Team(name=name, homepage=homepage, actual_rank=actual_rank, hltv_id=hltv_id) try: self.session.add(c1) self.session.commit() except: self.session.rollback() raise return c1
def scan_teams(comment, assignments): for reply in comment.replies: # Make sure the message isn't removed if reply.removed: continue # Add the user to the approved submitters list config.subreddit.contributor.add(reply.author.name) # Keep our team assignments up to date assignments.add_team( Team(str(reply.author.name), str(reply.body), reply.fullname)) assignments.set_url(config.reddit_base_url + str(comment.permalink))
def add_student(): """ GET: returns add student formula POST: returns list of students with new student added """ teams = Team.list_teams() if request.method == 'POST': save_student('add') flash('Student was added') return redirect(url_for('student_controller.list_students')) return render_template('student_form.html', user=user_session(session['user'], session['type']), teams=teams)
def edit_team(team_id): """ Return team_form.html with team basing on given team_id POST: Edit team with given values in request.form['name'] and redirect user to list-teams definition. :param team_id: team id in database """ team = Team.get_by_id(team_id) if request.method == 'POST': team.name = request.form['name'] team.edit_team() flash('Team was edited') return redirect(url_for('team_controller.list_teams')) return render_template('team_form.html', user=user_session(session['user'], session['type']), team=team)
def getNormalizedTeamsPos(playerArray, force_lineups=False): playerOfteam1 = filter(lambda player: player.teamID == 1, playerArray) playerOfteam2 = filter(lambda player: player.teamID == 2, playerArray) # sort in order of importance, will cut the last ones in the list playerOfteam1 = sorted(playerOfteam1, key=lambda player: player.careerScore, reverse=True) playerOfteam2 = sorted(playerOfteam2, key=lambda player: player.careerScore, reverse=True) team1 = Team() team1.setValues(playerOfteam1, force_lineups) team2 = Team() team2.setValues(playerOfteam2, force_lineups) return team1.positionArray, team2.positionArray
def getTeams(playerArray): playerOfteam1 = filter(lambda player: player.teamID == 1, playerArray) playerOfteam2 = filter(lambda player: player.teamID == 2, playerArray) # sort in order of importance, will cut the last ones in the list playerOfteam1 = sorted(playerOfteam1, key=lambda player: player.careerScore, reverse=True) playerOfteam2 = sorted(playerOfteam2, key=lambda player: player.careerScore, reverse=True) team1 = Team() team1.setValues(playerOfteam1) team2 = Team() team2.setValues(playerOfteam2) return team1, team2
def grade_assigment(assigment_id): user = session['user'] if user['type'] != 'Mentor': return redirect(url_for('index')) assigment = Assigment.get_assigment_by_id(assigment_id) if assigment.task_type == 'Personal': students_list = Student.get_list_of_students() return render_template('assignment_grade.html', assigment=assigment, students_list=students_list, user=user) elif assigment.task_type == 'Team': team_list = Team.get_list_of_teams() return render_template('assignment_grade.html', assigment=assigment, team_list=team_list, user=user)
def all_teams_page(): if request.method == 'POST': if not request.form['team_name']: teams = get_teams_db() return render_template("teams.html", teams=teams, error="Team name can not be empty!") try: team = Team(request.form['team_name'], request.form['rating'], "yes") insert_teams_db(team) teams = get_teams_db() flash("Team successfully added!") except psycopg2.errors.UniqueViolation: teams = get_teams_db() return render_template("teams.html", teams=teams, error="Team name must be unique!") return render_template("teams.html", teams=teams) elif request.method == 'GET': teams = get_teams_db() return render_template("teams.html", teams=teams)
def edit_student(student_id): """ Edit student formula to edit student details :param student_id: int GET return edit student formula POST return list of students with edited student changes saved """ teams = Team.list_teams() student = Student.get_by_id(student_id) print('Editing') if student: if request.method == 'POST': save_student('edit', student.id) flash('Student was edited') return redirect(url_for('student_controller.list_students')) return render_template('edit_student_form.html', user=user_session(session['user'], session['type']), student=student, teams=teams) return redirect('list-students')
def grade_user_assignments(username): """ Grade assignment of user if you are mentor :param username: :return: """ if request.method == "POST": if request.form['grade_user'] == 'grade': assignment_id = request.form['assignment'] student_id = request.form['id'] assignment = Assignment.get_by_id(assignment_id) student = Student.get_by_id(student_id) student_submit = Submition.get_submit(student_id, assignment_id) return render_template('grade_user_assignments.html', user=user_session(session['user'], session['type']), student=student, assignment=assignment, student_submit=student_submit) elif request.form['grade_user'] == 'Save': submit_id = request.form['submit_id'] new_grade = request.form['new_grade'] assignment_id = request.form['assignment_id'] assignment = Assignment.get_by_id(assignment_id) submit = Submition.get_by_id(submit_id) if assignment.type == 'group': team_id = Student.get_by_id(submit.student_id).team_id team = Team.get_by_id(team_id) team_members = team.get_members() for student in team_members: submit = Submition.get_submit(student.id, assignment_id) submit.update_grade(new_grade) else: submit.update_grade(new_grade) return redirect( url_for('assignment_controller.grade_assignment', assignmentID=assignment_id)) return render_template('404.html', user=user_session(session['user'], session['type']))
def teams(self, password=None, **unknown_args): login_page = request_login("teams", password, 2) if login_page: return login_page match_quantity = model.match.get_match_quantity() code_list = list() code_list.append(open(join(HTML_DIR, "header_admin.html"), 'r').read()) with html.div(code_list, 'class="table-responsive-sm text-nowrap text-center"'): with html.table(code_list, 'class="table table-bordered table-hover"'): with html.thead(code_list, 'class="thead-light"'): with html.tr(code_list): with html.th(code_list, scope="col"): with html.a(code_list, "/admin"): code_list.append("Teams") with html.th(code_list, scope="col"): code_list.append("Score") with html.th(code_list, scope="col"): code_list.append("V") with html.th(code_list, scope="col"): code_list.append("E") with html.th(code_list, scope="col"): code_list.append("D") for i in range(1, match_quantity + 1): with html.th(code_list, scope="col"): code_list.append("t{}".format(i)) with html.tbody(code_list): for team in Team.objects().order_by('code'): score, victories, evens, defeat = service.get_score( team.code) with html.tr(code_list): color_tag = "table-primary" if team.sex == "M" else "table-danger" with html.th( code_list, scope="row", params='class="{}"'.format(color_tag)): code_list.append(team.code) with html.td(code_list): code_list.append(str(score)) with html.td(code_list): code_list.append(str(victories)) with html.td(code_list): code_list.append(str(evens)) with html.td(code_list): code_list.append(str(defeat)) for match in team.matches: if not match.recorded: color_tag = "" elif match.even: color_tag = "table-warning" elif match.winner == team.code: color_tag = "table-success" else: color_tag = "table-danger" with html.td(code_list, 'class="{}"'.format(color_tag)): with html.a( code_list, "/admin/match?mid={}".format( match.id)): code_list.append(str( match.game_number)) code_list.append(open(join(HTML_DIR, "footer.html"), 'r').read()) return ''.join(code_list)
def __init__(self): self.team = Team()