def edit(self, tid, json): if tid and json['team_name'] and json['team_info'] and json[ 'sport_name']: new_team = Team(tid, json['team_name'], json['team_info'], json['sport_name']) teams = TeamRepository().edit(new_team) return jsonify(Teams=[team.serialize() for team in teams]), CREATED else: return jsonify(Error='Unexpected attributes in post'), BAD_REQUEST
def __init__(self, stubhubId, dateUTC, sportName, seasonName, teamCity=None, teamName=None, teamId=None, dateLocal=None, conn=None): self.stubhubId = stubhubId self.dateUTC = dateUTC self.dateLocal = dateLocal self.teamId = teamId self.teamName = teamName self.teamCity = teamCity self.sportName = sportName if conn: cursor = conn.cursor(buffered=True) cursor.execute("SELECT Id FROM `Sport` WHERE `name`='%s'" % (sportName)) data = cursor.fetchall() self.sportId = data[0][0] # Find if team exists cursor.execute("SELECT * FROM `Team` WHERE `stubhubId`='%s'" % (self.teamId)) data = cursor.fetchall() if len(data) > 0: self.team = Team(stubhubId=data[0][0], city=data[0][1], name=data[0][2], sportName=sportName) self.teamId = data[0][0] self.team_exists = True else: self.team_exists = False cursor.execute("SELECT Id FROM `Season` WHERE `name`='%s'" % (seasonName)) data = cursor.fetchall() self.seasonId = data[0][0]
def get(self, tid): cursor = self.conn.cursor() query = "SELECT team.id, team_name, info, sportname FROM ((team JOIN team_sport ON team.id = team_id) JOIN sport ON sport_id = sport.id) WHERE team.id = ?" cursor.execute(query, (tid, )) team_tup = cursor.fetchall() team_obj = [ Team(team[0], team[1], team[2], team[3]) for team in team_tup ] for team in team_obj: dao = TeamStatisticDAOFactory().getDAO(team.sport_name) team.sportStatistic = dao.getByTeamid(team.team_id) team.managers = ManagerDAO().getByTeamID(team.team_id) team.teamRecords = RecordsDAO().getByTeamID(team.team_id) cursor.close() return team_obj
def get_all_teams(sport): conn = connect() cursor = conn.cursor(buffered=True) cursor.execute("SELECT Id FROM `Sport` WHERE `name`='%s'" % (sport)) sportId = cursor.fetchall()[0][0] cursor.execute("SELECT * FROM `Team` WHERE `sportId`='%s'" % (sportId)) teams = cursor.fetchall() teams_objects = [] for team in teams: teams_objects.append(Team(team[0], team[1], team[2], sport)) conn.close() return teams_objects
def insert_event(self, conn): cursor = conn.cursor(buffered=True) if self.sportId: if self.seasonId: if not self.team_exists: print('No team found - creating %s %s' % (self.teamCity, self.teamName)) team = Team(stubhubId=self.teamId, city=self.teamCity, name=self.teamName, sportName=self.sportName, conn=conn) team.insert_team(conn) cursor = conn.cursor(buffered=True) cursor.execute( "SELECT city, name FROM `Team` WHERE `stubhubId`='%s'" % (self.teamId)) data = cursor.fetchall() if len(data) > 0: city, name = data[0][0], data[0][1] else: print("Team ") # Insert event add_event = ( "INSERT INTO Event " "(stubhubId, dateUTC, teamId, sportId, seasonId, dateLocal) " "VALUES (%(stubhubId)s, %(dateUTC)s, %(teamId)s, %(sportId)s, %(seasonId)s, %(dateLocal)s)" ) event_data = { "stubhubId": self.stubhubId, "dateUTC": self.dateUTC, "teamId": self.teamId, "sportId": self.sportId, "seasonId": self.seasonId, "dateLocal": self.dateLocal } cursor.execute(add_event, event_data) # Get city and name of team to print cursor.execute( "SELECT city, name FROM `Team` WHERE `stubhubId`='%s'" % (self.teamId)) data = cursor.fetchall() city, name = data[0][0], data[0][1] print("Adding Event %s for team: %s %s" % (self.stubhubId, city, name)) conn.commit() else: print("Error, seasonId not defined") else: print("Error, sportId not defined")
def main(): # H_1 parameters action = request.args.get('action', '') on = request.args.get('on', '') gsid = request.args.get('gsid', '') # TODO email = request.args.get('email', '') # H_2 credentials # HIGHLIGHT 需開啟 Google Sheets API、Google Drive API gsheets = load_gsheets() db = load_firestore() bucket = load_storage() # H_3 action if on == 'team': target = Team(gsheets=gsheets, db=db, bucket=bucket) elif on == 'project': target = Project(gsheets=gsheets, db=db) elif on == 'survey': target = Survey(gsheets=gsheets, db=db, bucket=bucket) elif on == 'module': target = SurveyModule(gsheets=gsheets, db=db) elif on == 'recode_module': target = SurveyModule(gsheets=gsheets, db=db, module='recode') if on: if action == 'create' and email: return target.create(email=email) elif action == 'update' and gsid: return target.update(gsid=gsid) elif action == 'delete' and gsid: return target.delete(gsid=gsid) elif on == 'survey' and action == 'update_respondents' and gsid: return target.update_respondents(gsid=gsid) elif on == 'survey' and action == 'transfer' and gsid: return target.transfer(gsid=gsid) elif on == 'survey' and action == 'update_download_files' and gsid: return target.update_download_files(gsid=gsid) elif on == 'survey' and action == 'delete_all_responses' and gsid: return target.delete_all_responses(gsid=gsid) return '失敗了....'
from match.match import Match, GroupMatch, KOMatch from team.team import Team from group.group import Group '''set the number of tournaments you want to simulate''' num_tournaments = 10000 '''initialise all the team info''' Brazil = Team("Brazil", "SA") '''If you want to print some info or save a graph uncomment''' #Brazil.print_info() #Brazil.print_results() Brazil.make_goals_plot() Croatia = Team("Croatia", "EU") Mexico = Team("Mexico", "NA") Cameroon = Team("Cameroon", "AF") Spain = Team("Spain", "EU") Netherlands = Team("Netherlands", "EU") Chile = Team("Chile", "SA") Australia = Team("Australia", "AS") Colombia = Team("Colombia", "SA") Greece = Team("Greece", "EU") Ivory_Coast = Team("Cote dIvoire", "AF") Japan = Team("Japan", "AS") Uruguay = Team("Uruguay", "SA") Costa_Rica = Team("Costa Rica", "NA") England = Team("England", "EU") Italy = Team("Italy", "EU") Switzerland = Team("Switzerland", "EU")