Veterans Don't Die | Data in Memory of Men's Basketball World Cup

Keywords: Python JSON encoding

The men's basketball World Cup has come to an end, I believe that all the friends who watch the game have already had enough basketball addiction. Regrettably, there are also the loss of the world's hegemony, the perseverance of the Veterans and, of course, the ascent of the Spanish Legion.

Suicide lost to Poland and defeated to Nigeria. China, who had been representing Asia in the Olympic Games, may be absent from the next one. When the League of Arab States is old, China will no longer have any player with the level of the world basketball players, no one! Look forward to the rise of Chinese men's basketball team again!

The stars are dim, the young general leads, the magical old man on the coach bench also failed to create magic, the worst record in history, we do not know whether this American men's basketball team should be given the title of "Dream Team". Maybe in Tokyo in the near future, they will gather stars and come back.

What is an old soldier? A fighter who is close to 40 years old. It's an incomprehensible and amazing insistence. At the end of the diamond, although not as expected, but who cares, you have conquered the whole world! The eagle on the Pampas grassland will eventually fly high.

As in football, the Spanish Legion's basketball is equally powerful. Can not but admire and sigh, when Gasol and Rubio inside and outside the alliance, two swords together, they are the hegemony of basketball.

Now let's count all the data of the men's basketball World Cup through the real data.

Where does the data come from?

I don't produce data, I'm just a data porter.

The data analyzed below are all from Sina Sports.

_Data Grabbing

On Sina Sports website, there is a World Cup column. In the data list module, you can find a link similar to the following.

https://events.sports.sina.com.cn/bps/peony/mersh/beitai/fiba/stats/playerdata_order?leagueid=433&ordertype=FieldGoalsAverage&order=desc&dpc=1

This link, as long as you modify the order type field, you can get some columns of data such as player scores, rebounds, assists, etc. The specific process is not to mention, that is, to send a request, parse the simple operation of json.

import requests
import time

url_list = [
    'https://events.sports.sina.com.cn/bps/peony/mersh/beitai/fiba/stats/playerdata_order?leagueid=433&ordertype=PointsAverage',
    'https://events.sports.sina.com.cn/bps/peony/mersh/beitai/fiba/stats/playerdata_order?leagueid=433&ordertype=ReboundsAverage',
    'https://events.sports.sina.com.cn/bps/peony/mersh/beitai/fiba/stats/playerdata_order?leagueid=433&ordertype=PlusMinusAverage',
    'https://events.sports.sina.com.cn/bps/peony/mersh/beitai/fiba/stats/playerdata_order?leagueid=433&ordertype=StealsAverage',
    'https://events.sports.sina.com.cn/bps/peony/mersh/beitai/fiba/stats/playerdata_order?leagueid=433&ordertype=AssistsAverage',
    'https://events.sports.sina.com.cn/bps/peony/mersh/beitai/fiba/stats/playerdata_order?leagueid=433&ordertype=BlockedAverage',
    'https://events.sports.sina.com.cn/bps/peony/mersh/beitai/fiba/stats/playerdata_order?leagueid=433&ordertype=TurnoversAverage',
    'https://events.sports.sina.com.cn/bps/peony/mersh/beitai/fiba/stats/playerdata_order?leagueid=433&ordertype=PersonalFoulsAverage',
    'https://events.sports.sina.com.cn/bps/peony/mersh/beitai/fiba/stats/playerdata_order?leagueid=433&ordertype=FieldGoalsAverage'
]

def fire(url):
    file_name = url.split('=')[2]
    res = requests.get(url).json()
    data = res['playerdata_order']
    items = map(get_data, data)
    print('save data')
    save_to_csv(items, file_name)

def get_data(data):
    name = data['CNAlias']
    country = data['TeamCNName']
    points = data['PointsAverage']
    rebounds = data['ReboundsAverage']
    steals = data['StealsAverage']
    assists = data['AssistsAverage']
    fouls = data['PersonalFoulsAverage']
    plus_minus = data['PlusMinusAverage']
    blocked = data['BlockedAverage']
    goals_percentage = data['FieldGoalsPercentage_m']
    turnovers = data['TurnoversAverage']
    result = {
        'name': name,
        'country': country,
        'points': points,
        'rebounds': rebounds,
        'steals': steals,
        'assists': assists,
        'fouls': fouls,
        'plus_minus': plus_minus,
        'blocked': blocked,
        'goals_percentage': goals_percentage,
        'turnovers': turnovers
    }
    return result

def save_to_csv(data, file_name):
    with open(file_name + '_data.csv', 'w', encoding='utf-8') as f:
        f.write('name,country,points,rebounds,steals,assists,fouls,plus_minus,blocked,goals_percentage,turnovers\n')
        for d in data:
            try:
                row = '{},{},{},{},{},{},{},{},{},{},{}'.format(d['name'],
                                                                d['country'],
                                                                d['points'],
                                                                d['rebounds'],
                                                                d['steals'],
                                                                d['assists'],
                                                                d['fouls'],
                                                                d['plus_minus'],
                                                                d['blocked'],
                                                                d['goals_percentage'],
                                                                d['turnovers'])
                f.write(row)
                f.write('\n')
            except:
                continue

if __name__ == '__main__':
    for url in url_list:
        fire(url)
        time.sleep(2)

_Data preservation

I grabbed the ranking data of scores, rebounds, assists and so on, and saved them in different csv files, the final document content is roughly as follows

Visualization of All Players

Player Score Ranking

Several highlights:

South Korea's naturalized players scored the highest average score in the field.
Yan Allianz was elected successfully
No Americans

Maybe the Korean team does not play many games and the opponents are not very strong. As a mini center, Luo Jianer can also turn clouds and rain on the inside.

The League of Arab States is really not old, remember the last battle of life and death, if there is no League of Arab States, the game may be premature.

Once again, it proves that the current American men's basketball team has no major brand and absolute attack core, which may be the biggest reason for their defeat of China.

Players'Rebound Ranking

Interestingly, Luo Jianle is the first one. If we follow the standards of domestic platoon universities, it's appropriate to be double-class! __________.

Players'scoring and rebounding rankings

Luo Jianer is the only player in this World Cup who can get two or two rebounds, and is 20 + 10. There is no doubt about his ability.

Then we'll talk about two veterans, Scola and Yi Jianlian. Both of them have 17 + points per game plus 7 + rebounds. It can be seen that both players are indispensable members of their respective teams at both ends of the game. It is true that there is an old family, such as a treasure ah.

However, the Argentine men's basketball team has completed the alternation of old and new, and the future is still promising. And the Chinese men's basketball team, who will depend on in the future, is the first guard in Asia - Guo Allen, or the great devil - Zhou Qi, are still lack of leadership temperament and absolute ability ah!

Visualization Analysis of Optimum Lineup

Best lineup player

the_best_lineup = [
    'Peter Bogdanovich',
    'Fourier',
    'Marco Rubio',
    'Scola',
    'Gassol'
]

Analysis of Players'Ability

Next, let's look at the data of the best squad members in this World Cup. Ability is not strong, data do not lie.

I selected scoring, rebounding, assists, stealing, blocking, fouls and errors as the inspection points, and drew their respective radar charts.

Three outside lines and two inside lines, each with different abilities, affect the game and help the team.

Serbia's Bogdanovic, scoring ability is relatively strong, average assists are also good, the key is to assist the fault ratio is very low, appropriate attack engine.

French team Funier, scoring assists are relatively average, from the data point of view, is the weaker of the five. But its powerful impact is one of the keys to France's defeat of the United States.

Spain's Rubio is the highest assistant of the five, but also the most mistakes. His threat on the outside is an important factor in Spain's ability to easily defeat Argentina. The golden boy had grown his beard, and the vicissitudes of the years gave him more perseverance.

Scola of Argentina, as the absolute core of both sides of the offensive and defensive, would not have known that he was 39 years old if not for a little gray hair on his temples. At this time, the data is no longer important, basketball is everything!

Lesser Gasol of Spain, who succeeded in taking the flag of the national team from his brother, is not behind the gorgeous data, but his experience on the pitch, his old ways and deterrence. With him, Spain will not be easily defeated.

Comparison of shooting percentage of players

Unexpectedly, the highest shooting percentage is actually an outside player. Maybe this is related to the development of basketball today. Big ones run outward and small ones run inward!

The best five-player group, each person's hit rate is more than 40%, how a stable word.

Players'Positive and Negative Value Contrast

Funier is the lowest positive and negative among the five. I said he is the weakest among the five. Is that also confirmed from the side?

And Gasol's positive and negative value is the highest, he is the team's pin. I remember when Argentina's counter-attack was fierce, it was Pau Gasol who came on in danger, stabilized his army, curbed his opponent's attack and succeeded in helping the team win the game.

Veterans do not die

It's just fading away.

Look at the data of the League of Arab States, unexpectedly it is inexplicable sadness.

I don't want to analyse why his positive and negative values are so low, because we all saw his hard work and sweat on the court, and the scene of his frustrated hands smashing the ground because of his lost rebounds.

And Scola, 12.9 plus or minus, 43.4% shooting rate, 17.9 points per game, 8.1 rebounds, no one can ask him to do anything more, release as much as possible, try to burn, no regrets!

It's just right to end with the text of world football.

Time you do not rush, should come I do not push; Time you do not rush, go far still to chase. When you have to say goodbye, waving the other moment is like running time, who can get over it, who can sigh and how.

Backstage reply "veterans don't die" to get the complete code.

Posted by wopopd83 on Tue, 17 Sep 2019 06:43:25 -0700