Python代写:FIT1045 FIFA World Cup Statistics

代写世界杯比赛模拟器,根据每场结果,模拟冠军球队。

Task 1: FIFA World Cup Statistics 50 Marks

In this task, you are given scores of all matches played in 2010 FIFA World Cup (see the file matches.txt under task1 folder in the zipped file provided on moodle). Some of the lines in matches.txt are shown below.

South Africa:Mexico:1:1
Uruguay:France:0:0
Korea Republic:Greece:2:0
Argentina:Nigeria:1:0

The values in each line are separated by colon. The values in first two columns correspond to the names of home team and away team, respectively. Third and fourth columns represent the scores of home team and away team, respectively. For example, the third line above shows that Korea Republic scored 2 goals and Greece scored 0 goal. You need to write a Python program that first computes the following statistics for each team.

Played: Number of matches played
Won: Number of matches won
Drawn: Number of matches drawn
Lost: Number of matches lost
GS: Total number of goals scored
GA: Total number of goals the opponent scored against the team
GD: The difference between GS and GA (i.e., GS-GA)
Points: Total number of points calculated as 3*Won + Drawn.

After computing the above statistics for each team, you need to rank the teams according to the following criteria (see the sample output shown on the next page for explanation of the ranking criteria).

  • The team are first ranked by the total number of points (e.g., Germany is ranked higher than Argentina).
  • If two teams have equal number of points then the team that played fewer matches is ranked higher (e.g., Australia and Mexico have 4 points each but Australia is ranked higher because Australia has played 3 matches as compared to 4 matches played by Mexico).
  • If the tie is still not broken, the team with higher goal dierence (GD) is ranked higher (e.g., Australia and South Africa have the same points and have played the same number of matches but South Africa is ranked higher because its GD is -2 as compared to the GD (-3) of Australia).
  • If the two teams have equal number of points, have played the same number of matches and have the same goal dierence, the team that has scored more goals (i.e., higher GS) is ranked higher (e.g., Nigeria is ranked higher than Algeria because Nigeria scored more goals than Algeria).
  • In the unlikely event that the tie still cannot be broken, the teams are ranked alphabetically. We do not have such a case in this data set but assume that Nigeria and Algeria both had same number of points, matches played, GD and GS, then we would rank Algeria higher because Algeria alphabetical order.
A sample output for the file matches.txt.
Team           Played     Won   Drawn    Lost      GS      GA      GD   Points
Netherlands         7       6       0       1      12       6       6       18
Spain               7       6       0       1       8       2       6       18
Germany             7       5       0       2      16       5      11       15
Argentina           5       4       0       1      10       6       4       12
Uruguay             7       3       2       2      11       8       3       11
Brazil              5       3       1       1       9       4       5       10
Ghana               5       2       2       1       5       4       1        8
Japan               4       2       1       1       4       2       2        7
Chile               4       2       0       2       3       5      -2        6
Paraguay            5       1       3       1       3       2       1        6
Portugal            4       1       2       1       7       1       6        5
USA                 4       1       2       1       5       5       0        5
England             4       1       2       1       3       5      -2        5
Ivory Coast         3       1       1       1       4       3       1        4
Slovenia            3       1       1       1       3       3       0        4
Switzerland         3       1       1       1       1       1       0        4
South Africa        3       1       1       1       3       5      -2        4
Australia           3       1       1       1       3       6      -3        4
Mexico              4       1       1       2       4       5      -1        4
Korea Republic      4       1       1       2       6       8      -2        4
Slovakia            4       1       1       2       5       7      -2        4
New Zealand         3       0       3       0       2       2       0        3
Serbia              3       1       0       2       2       3      -1        3
Denmark             3       1       0       2       3       6      -3        3
Greece              3       1       0       2       2       5      -3        3
Italy               3       0       2       1       4       5      -1        2
Nigeria             3       0       1       2       3       5      -2        1
Algeria             3       0       1       2       0       2      -2        1
France              3       0       1       2       1       4      -3        1
Honduras            3       0       1       2       0       3      -3        1
Cameroon            3       0       0       3       2       5      -3        0
Korea DPR           3       0       0       3       1      12     -11        0

Important Instructions

  • Download the files provided on Moodle. In the task1 folder, a file task1.py is provided. Write your code in this file. We have provided two functions in this file. Do not modify these functions - These are critical for auto-marking as explained later.
  • You will need to create a table (i.e., list of lists) that contains the statistics for each team and then sort the table as shown in the above input.
  • Once you have sorted the table according to the above criteria, call the function writeTable() provided in task1.py and pass your table as a parameter. This should display you the output as well as it will create an output file called FIFA_stats.txt.
  • The checker has been tested on Windows environment on the lab machines. If you are using your own laptop to run the checker, make sure that the default program to open .py files is set to python.exe (not IDLE, pycharm etc.). If you receive any other strange errors, test your code on the lab machine before submitting or contact us with the specic details of the error message.

Task 2: Selecting the Most Walkable House 50 Marks

Your friend Alice is moving to USA. She is considering to rent a house in North West USA (Washington and Oregon area). Her ideal house would be close to a school, a fast food restaurant, a post oce and a hospital. She has come up with a scoring function to compute the score of each available house, called walkability score Given a house.h, let mindist(h, school) denote the distance of the closest school to the house h. Similarly, mindist(h, fastfood), mindist(h, postof f ice), and mindist(h, hospital) denote the distances to the house h’s closest fast food restaurant, post oce, and hospital, respectively. Walkability score of the house h is denoted as h.walkability and is computed using the equation below.

h.walkability = mindist(h, school) + mindist(h, f astf ood) + mindist(h, postof f ice) + mindist(h, hospital)

She wants to find the most walkable house, i.e., the house with the smallest walkability score. She has downloaded a file from OpenStreetMap (www.openstreetmap.org) that has the locations of all relevant points of interest (POIs), i.e., schools, post oces, fast food restaurants, hospitals and the houses available for renting in Washington and Oregon (see POI.txt under task2 folder). Below are some records from this file.

1:47.068818:-122.89045:house
2:45.513901:-123.065825:school
3:43.35308:-124.201326:school
4:45.639439:-122.658908:hospital

Each line represents a unique point of interest (POI). The values in each line are separated by colon. First column in each line is the unique id of the POI. The second column is the latitude and the third column is the longitude of the POI. The fourth column species the type of POI (e.g., house, school etc.). The distance between two points is computed using haversine formula that returns the shortest distance (i.e., as-the-crow the longitude files) between two points on earth. The function to compute haversine distance is provided in the file task2.py. The function haversine(point1, point2) takes two lists as parameters where each list contains latitude and longitude of the point. The function returns the distance between the two points in kilometers. Below is an example on how to call this function to get the distance between the house with ID 1 and the school with ID 2 in the above sample input.

p1 = [47.068818,-122.89045]
p2 = [45.513901,-123.065825]
dist = haversine(p1,p2)
print("The distance is:",dist, "km")

This will print “The distance is: 173.42303260967046 km.”
Alice needs your help in writing a program that can find the most walkable house in a given area. Specically, the program should take a rectangular area (called window) as an input from the user and return the most walkable house among the houses that lie in the window. The window is represented using the locations of its lower fileft corner and upper right corner. Consider the example of Figure 1 where the window (the shaded area) is represented by its lower fileft corner [47.7, -122.5], and upper right corner [47.9, -122.4]. Note that, in [47.7, -122.5] is the latitude and -122.5 is the longitude of the point.

The user will enter the input in a string where values are separated by colon.

The first two columns correspond to the latitude and longitude of the lower fileft corner and the third and fourth column represent the latitude and longitude of the upper right corner. Below is a sample input entered by the user for the window in Figure 1.

47.7:-122.5:47.9:-122.5

Your program must find the most walkable house in the given window. In the example of Figure 1, there are only two houses H1 and H3 that lie within the window. The closest school to H1 is S1 and assume that the haversine distance between H1 and S1 (denoted as dist(H1 , S1 )) is 1 km.

Your program must output the location of the most walkable house, its walkability score and its distance to the closest POI of each type. The output must be printed to a file called walkable.txt. Below are two sample outputs for two dierent windows using the data provided in POI.txt.

A sample output.
Enter the window: 47.701460:-122.573313:47.916884:-122.397654
Location of the most walkable house: 47.800229, -122.502084
Walkability Score: 12.64256128910096
The closest school is 0.30596846398819993 km
The closest fast food is 0.06558006467957564 km
The closest post office is 0.19904259701867597 km
The closest hospital is 12.071970163414509 km
Another sample output.
Enter the window: 42.3:-124.2:43.3:-123.3
Location of the most walkable house: 42.449755, -123.328187
Walkability Score: 5.315847211532855
The closest school is 0.6055333221300785 km
The closest fast food is 1.0371239069242966 km
The closest post office is 0.395888284834936 km
The closest hospital is 3.2773016976435434 km

If the window does not contain any house, your program must print No house found in the window.