
import pandas as pd


def howManyMedalsByCountry(df, name):
    te = ['Alpinism Mixed Alpinism',
          "Archery Men's Pole Archery, Large Birds, Team",
          "Archery Men's Pole Archery, Small Birds, Team",
          "Archery Men's Target Archery, 28 metres, Team",
          "Archery Men's Target Archery, 33 metres, Team",
          "Archery Men's Target Archery, 50 metres, Team",
          "Archery Men's Team",
          "Archery Men's Team Round",
          "Archery Women's Team",
          "Archery Women's Team Round",
          'Art Competitions Mixed Architecture',
          'Art Competitions Mixed Architecture, Architectural Designs',
          'Art Competitions Mixed Architecture, Designs For Town Planning',
          'Art Competitions Mixed Literature, Epic Works',
          "Athletics Men's 1,600 metres Medley Relay",
          "Athletics Men's 3 mile, Team",
          "Athletics Men's 3,000 metres, Team",
          "Athletics Men's 4 mile, Team",
          "Athletics Men's 4 x 100 metres Relay",
          "Athletics Men's 4 x 400 metres Relay",
          "Athletics Men's 5,000 metres, Team",
          "Athletics Men's Cross-Country, Team",
          "Athletics Women's 4 x 100 metres Relay",
          "Athletics Women's 4 x 400 metres Relay",
          "Badminton Men's Doubles", 'Badminton Mixed Doubles',
          "Badminton Women's Doubles",
          "Baseball Men's Baseball",
          "Basketball Men's Basketball",
          "Basketball Women's Basketball",
          "Beach Volleyball Men's Beach Volleyball",
          "Beach Volleyball Women's Beach Volleyball",
          "Biathlon Men's 4 x 7.5 kilometres Relay",
          "Biathlon Mixed 2 x 6 kilometres and 2 x 7.5 kilometres Relay",
          "Biathlon Women's 3 x 7.5 kilometres Relay",
          "Biathlon Women's 4 x 6 kilometres Relay",
          "Biathlon Women's 4 x 7.5 kilometres Relay",
          "Bobsleigh Men's Four",
          "Bobsleigh Men's Four/Five",
          "Bobsleigh Men's Two",
          "Bobsleigh Women's Two",
          "Canoeing Men's Canadian Doubles, 1,000 metres",
          "Canoeing Men's Canadian Doubles, 10,000 metres",
          "Canoeing Men's Canadian Doubles, 500 metres",
          "Canoeing Men's Canadian Doubles, Slalom",
          "Canoeing Men's Folding Kayak Doubles, 10 kilometres",
          "Canoeing Men's Kayak Doubles, 1,000 metres",
          "Canoeing Men's Kayak Doubles, 10,000 metres",
          "Canoeing Men's Kayak Doubles, 200 metres",
          "Canoeing Men's Kayak Doubles, 500 metres",
          "Canoeing Men's Kayak Fours, 1,000 metres",
          "Canoeing Men's Kayak Relay 4 x 500 metres",
          "Canoeing Women's Kayak Doubles, 500 metres",
          "Canoeing Women's Kayak Fours, 500 metres",
          "Cricket Men's Cricket",
          "Cross Country Skiing Men's 4 x 10 kilometres Relay",
          "Cross Country Skiing Men's Team Sprint",
          "Cross Country Skiing Women's 3 x 5 kilometres Relay",
          "Cross Country Skiing Women's 4 x 5 kilometres Relay",
          "Cross Country Skiing Women's Team Sprint",
          "Curling Men's Curling",
          "Curling Women's Curling",
          "Cycling Men's 100 kilometres Team Time Trial",
          "Cycling Men's Madison",
          "Cycling Men's Road Race, Team",
          "Cycling Men's Tandem Sprint, 2,000 metres",
          "Cycling Men's Team Pursuit, 1,980 yards",
          "Cycling Men's Team Pursuit, 4,000 metres",
          "Cycling Men's Team Sprint",
          "Cycling Women's Team Pursuit",
          "Cycling Women's Team Sprint",
          "Diving Men's Synchronized Platform",
          "Diving Men's Synchronized Springboard",
          "Diving Women's Synchronized Platform",
          "Diving Women's Synchronized Springboard",
          "Equestrianism Men's Dressage, Team",
          "Equestrianism Men's Jumping, Team",
          "Equestrianism Men's Three-Day Event, Team",
          "Equestrianism Men's Vaulting, Team",
          'Equestrianism Mixed Dressage, Team',
          'Equestrianism Mixed Jumping, Team',
          'Equestrianism Mixed Three-Day Event, Team',
          "Fencing Men's Foil, Team",
          "Fencing Men's Sabre, Team",
          "Fencing Men's epee, Team",
          "Fencing Women's Foil, Team",
          "Fencing Women's Sabre, Team",
          "Fencing Women's epee, Team",
          'Figure Skating Mixed Ice Dancing',
          'Figure Skating Mixed Pairs',
          'Figure Skating Mixed Team',
          "Football Men's Football",
          "Football Women's Football",
          "Golf Men's Team",
          "Gymnastics Men's Horizontal Bar, Teams",
          "Gymnastics Men's Parallel Bars, Teams",
          "Gymnastics Men's Team All-Around",
          "Gymnastics Men's Team All-Around, Free System",
          "Gymnastics Men's Team All-Around, Swedish System",
          "Gymnastics Women's Team All-Around",
          "Gymnastics Women's Team Portable Apparatus",
          "Handball Men's Handball",
          "Handball Women's Handball",
          "Hockey Men's Hockey",
          "Hockey Women's Hockey",
          "Ice Hockey Men's Ice Hockey",
          "Ice Hockey Women's Ice Hockey",
          "Lacrosse Men's Lacrosse",
          "Luge Mixed (Men)'s Doubles", 'Luge Mixed Team Relay',
          "Military Ski Patrol Men's Military Ski Patrol",
          "Modern Pentathlon Men's Team",
          "Nordic Combined Men's Team",
          "Polo Men's Polo",
          "Racquets Men's Doubles",
          "Rhythmic Gymnastics Women's Group",
          "Rowing Men's 17-Man Naval Rowing Boats",
          "Rowing Men's 6-Man Naval Rowing Boats",
          "Rowing Men's Coxed Eights",
          "Rowing Men's Coxed Fours",
          "Rowing Men's Coxed Fours, Inriggers",
          "Rowing Men's Coxed Fours, Outriggers",
          "Rowing Men's Coxed Pairs",
          "Rowing Men's Coxed Pairs (1 kilometres)",
          "Rowing Men's Coxed Pairs (1 mile)",
          "Rowing Men's Coxless Fours",
          "Rowing Men's Coxless Pairs",
          "Rowing Men's Double Sculls",
          "Rowing Men's Lightweight Coxless Fours",
          "Rowing Men's Lightweight Double Sculls",
          "Rowing Men's Quadruple Sculls",
          "Rowing Women's Coxed Eights",
          "Rowing Women's Coxed Fours",
          "Rowing Women's Coxed Quadruple Sculls",
          "Rowing Women's Coxless Fours",
          "Rowing Women's Coxless Pairs",
          "Rowing Women's Double Sculls",
          "Rowing Women's Lightweight Double Sculls",
          "Rowing Women's Quadruple Sculls",
          "Rugby Men's Rugby",
          "Rugby Sevens Men's Rugby Sevens",
          "Rugby Sevens Women's Rugby Sevens",
          "Sailing Men's Skiff",
          "Sailing Men's Two Person Dinghy",
          "Sailing Men's Two Person Keelboat",
          'Sailing Mixed 0-0.5 Ton',
          'Sailing Mixed 0.5-1 Ton',
          'Sailing Mixed 1-2 Ton',
          'Sailing Mixed 10 metres',
          'Sailing Mixed 10-20 Ton',
          'Sailing Mixed 12 foot',
          'Sailing Mixed 12 metres',
          'Sailing Mixed 2-3 Ton',
          'Sailing Mixed 3-10 Ton',
          'Sailing Mixed 40 metres',
          'Sailing Mixed 5.5 metres',
          'Sailing Mixed 6 metres',
          'Sailing Mixed 6.5 metres',
          'Sailing Mixed 7 metres',
          'Sailing Mixed 8 metres',
          'Sailing Mixed Multihull',
          'Sailing Mixed Open',
          'Sailing Mixed Skiff',
          'Sailing Mixed Three Person Keelboat',
          'Sailing Mixed Two Person Dinghy',
          'Sailing Mixed Two Person Heavyweight Dinghy',
          'Sailing Mixed Two Person Keelboat',
          "Sailing Women's Skiff",
          "Sailing Women's Three Person Keelboat",
          "Sailing Women's Two Person Dinghy",
          "Shooting Men's Dueling Pistol, 30 metres, Team",
          "Shooting Men's Free Pistol, 50 metres, Team",
          "Shooting Men's Free Pistol, 50 yards, Team",
          "Shooting Men's Free Rifle, 400, 600 and 800 metres, Team",
          "Shooting Men's Free Rifle, Three Positions, 300 metres, Team",
          "Shooting Men's Military Pistol, Team",
          "Shooting Men's Military Rifle, 200, 400, 500 and 600 metres, Team",
          "Shooting Men's Military Rifle, \
200/500/600/800/900/1,000 Yards, Team",
          "Shooting Men's Military Rifle, \
300 metres and 600 metres, Prone, Team",
          "Shooting Men's Military Rifle, Prone, 300 metres, Team",
          "Shooting Men's Military Rifle, Prone, 600 metres, Team",
          "Shooting Men's Military Rifle, Standing, 300 metres, Team",
          "Shooting Men's Running Target, Double Shot, Team",
          "Shooting Men's Running Target, Single Shot, Team",
          "Shooting Men's Small Bore-Rifle, Standing, 50 metres, Team",
          "Shooting Men's Small-Bore Rifle, 50 and 100 yards, Team",
          "Shooting Men's Small-Bore Rifle, \
Disappearing Target, 25 metres, Team",
          "Shooting Men's Small-Bore Rifle, Prone, 50 metres, Team",
          "Shooting Men's Trap, Team",
          "Short Track Speed Skating Men's 5,000 metres Relay",
          "Short Track Speed Skating Women's 3,000 metres Relay",
          "Ski Jumping Men's Large Hill, Team",
          "Softball Women's Softball",
          "Speed Skating Men's Team Pursuit (8 laps)",
          "Speed Skating Women's Team Pursuit (6 laps)",
          "Swimming Men's 200 metres Team Swimming",
          "Swimming Men's 4 x 100 metres Freestyle Relay",
          "Swimming Men's 4 x 100 metres Medley Relay",
          "Swimming Men's 4 x 200 metres Freestyle Relay",
          "Swimming Men's 4 x 250 metres Freestyle Relay",
          "Swimming Men's 4 x 50 Yard Freestyle Relay",
          "Swimming Women's 4 x 100 metres Freestyle Relay",
          "Swimming Women's 4 x 100 metres Medley Relay",
          "Swimming Women's 4 x 200 metres Freestyle Relay",
          "Synchronized Swimming Women's Duet",
          "Synchronized Swimming Women's Team",
          "Table Tennis Men's Doubles",
          "Table Tennis Men's Team",
          "Table Tennis Women's Doubles",
          "Table Tennis Women's Team",
          "Tennis Men's Doubles",
          "Tennis Men's Doubles, Covered Courts",
          "Tennis Men's Singles",
          'Tennis Mixed Doubles',
          'Tennis Mixed Doubles, Covered Courts',
          "Tennis Women's Doubles",
          "Tug-Of-War Men's Tug-Of-War",
          "Volleyball Men's Volleyball",
          "Volleyball Women's Volleyball",
          "Water Polo Men's Water Polo",
          "Water Polo Women's Water Polo"]
    print(df.keys())
    df = df[['Year', 'Medal', 'Team', 'Sport', 'Event', 'Name']]
    df = df.drop(df[df.Team != name].index)
    df = df.dropna()
    df.insert(2, "G", 0, True)
    df.insert(2, "B", 0, True)
    df.insert(2, "S", 0, True)
    df["B"] = [1 if x == "Bronze" else 0 for x in df["Medal"]]
    df["S"] = [1 if x == "Silver" else 0 for x in df["Medal"]]
    df["G"] = [1 if x == "Gold" else 0 for x in df["Medal"]]
    team = df.drop(df[~df.Event.isin(te)].index)
    single = df.drop(df[df.Event.isin(te)].index)
    team = team.groupby(['Year', 'Team', "Medal", 'Sport', 'Event']).agg(
        {'G': 'max', 'S': 'max', 'B': 'max'})
    single = single.groupby(['Year', 'Team', "Medal", 'Sport', 'Event']).agg(
        {'G': 'sum', 'S': 'sum', 'B': 'sum'})
    df = pd.concat([single, team])
    df = df.groupby(['Year']).agg({'G': 'sum', 'S': 'sum', 'B': 'sum'})
    return (df.T.to_dict())


if __name__ == "__main__":
    from FileLoader import FileLoader
    loader = FileLoader()
    data = loader.load("../ressources/athlete_events.csv")
    print(howManyMedalsByCountry(data, 'France'))
