CITS1401 Computational Thinking with Python Project 1 Semester 2 2020 Page 1 of 6 Project 1: Submission deadlines: 5:00 pm, Friday 18th September 2020 Value: 15% of CITS1401. To be completed...

1 answer below »
python


CITS1401 Computational Thinking with Python Project 1 Semester 2 2020 Page 1 of 6 Project 1: Submission deadlines: 5:00 pm, Friday 18th September 2020 Value: 15% of CITS1401. To be completed individually. You should construct a Python 3 program containing your solution to the following problem and submit your program electronically on Moodle. No other method of submission is allowed. Your program will be automatically tested on Moodle. Remember your first two checks against the tester on Moodle will not have any penalty. However any further check will carry 10% penalty per check. You are expected to have read and understood the University's guidelines on academic conduct. In accordance with this policy, you may discuss with other students the general principles required to understand this project, but the work you submit must be the result of your own effort. Plagiarism detection, and other systems for detecting potential malpractice, will therefore be used. Besides, if what you submit is not your own work then you will have learnt little and will therefore, likely, fail the final exam. You must submit your project before the submission deadline listed above. Following UWA policy, a late penalty of 5% will be deducted for each day (or part day), after the deadline, that the assignment is submitted. No submissions will be allowed after 7 days following the deadline except approved special consideration cases. Overview The Government of Australia established the Bureau of Meteorology (“BOM”) in 1906 under the Meteorology Act which, at the time, brought together the state meteorological services. The main objective of the BOM is to provide weather services to Australia and its surrounding areas. A research group in UWA requires a computer program which can read the data from a csv (comma separated values) file and return different statistical aspects of the rainfall recorded in the Perth metropolitan area. Your task is to write this program which will meet the following specification. Specification (i.e. what your program will need to do) Input: Your program must define the function main with the following signature: def main(csvfile, year, type): The input arguments to this function are: • csvfile is the name of the CSV file containing the record of the rainfall in Perth which needs to be analysed. The first row of the CSV file will contain the headers. From the second row, the first value of each row contains the station number of the Bureau of Meteorology, and the second, third and fourth values will contain the year, month and day respectively. The http://www.teachingandlearning.uwa.edu.au/staffnet/policies/conduct http://www.teachingandlearning.uwa.edu.au/staffnet/policies/conduct CITS1401 Computational Thinking with Python Project 1 Semester 2 2020 Page 2 of 6 last value of the row will contain the recorded rainfall in millimetres. We do not have prior knowledge about the number of days of rainfall (i.e. the number of rows) that the CSV file will contain. • year is the year or years for which we are looking to analyse. This input argument will accept an integer as a year if the third input requires statistical analysis of a particular year. Otherwise this input argument will contain a list of two integers containing two years for which a correlation is to be calculated instead. • type is the input argument which mentions which type of analysis are required. It can take only one of the two string inputs: “stats” or “corr”. If third input argument is “stats”, then the objective of the program is to find the statistical analysis of a single year. Otherwise if the third input argument is “corr” then the objective of the program is to find the correlation of statistical data of two years. Output: The function is required to return the following outputs in the order provided below: • A list containing the minimum recorded rainfall (that is greater than zero) for each month of the year (i.e. the year provided as the second input argument) if third input is “stats”. Otherwise if the third input parameter is “corrs”, then the output should be a single value that is the correlation of the minimum recorded rainfalls of the two years (that are provided as a single list in second input argument). • A list or value in the same fashion as the above that contains or is the correlation of the maximum recorded rainfall. • A list or value in the same fashion as the above that contains or is the correlation of the average recorded rainfall. • A list or value in the same fashion as the above that contains or is the correlation of the standard deviations in recorded rainfall. All returned lists should have the values recorded for each month of the year in order from January to December. All returned output values (both in lists and individual) must contain numerical values rounded to four decimal places (if required to be rounded off). Please do not round the values during calculations. Instead round them only at the time that you save them into the final output variables. Examples: Download the sample_rainfall_data.csv file from the folder of Project 1 on LMS or Moodle. Some examples how you can call your program from the Python shell (and examine the results it returns) are: >>> mn1,mx1,avg1,std1 = main('sample_rainfall_data.csv',2019, "stats") Your program’s outputs (that will be stored in the variables) are: >>> mn1 [0.2, 0.2, 0.2, 3.0, 0.2, 0.2, 0.2, 0.2, 0.2, 0.8, 0.2, 0.2] >>> mx1 CITS1401 Computational Thinking with Python Project 1 Semester 2 2020 Page 3 of 6 [4.8, 0.2, 3.4, 23.4, 7.2, 58.0, 44.2, 28.0, 13.8, 9.0, 13.0, 1.8] >>> avg [0.2323, 0.0071, 0.2, 1.4733, 0.5742, 7.0667, 3.5032, 3.6839, 1.0467, 0.5742, 0.6133, 0.0774] >>> std [0.8946, 0.0371, 0.6584, 4.4946, 1.6568, 12.4251, 8.3301, 7.563, 3.1806, 1.7029, 2.4684, 0.324] >>> mn2,mx2,avg2,std2=main('sample_rainfall_data.csv',[2019,2018],"corr") Your program’s outputs (that will be stored in the variables) are: >>> mn2 -0.0916 >>> mx2 0.0677 >>> avg2 0.7229 >>> std2 0.254 Assumptions: Your program can assume a number of things: • Anything that is meant to be a string (i.e. header row) will be a string, and anything that is meant to be a number (i.e. data) will be a number. • The order of columns in each row will follow the order of the headings provided in the first row. However, the rows may be in random order (i.e. they will not necessarily be in date order) and their number are not constant across different testing CSV files. • No data will be missing in the csv file except recorded rainfall. You can presume the missing recorded rainfall as zero. • It is not mandatory that rainfall is recorded all days of the month or year. Therefore, while finding average or standard deviation for record of a month, you are required to not to make assumptions about the missing days’ data. • If there is no recorded rainfall over a month then consider it to be zero. The minimum will also be considered as zero which cannot be the case otherwise. • The main() function will always be provided with valid input parameters. • The formula for standard deviation and correlation can be found at the end of the project sheet. CITS1401 Computational Thinking with Python Project 1 Semester 2 2020 Page 4 of 6 Important grading instruction: You will have noticed that you have not been asked to write specific functions. That has been left to you. However, it is essential that your program defines the top-level function main(csvfile, year, type) (hereafter referred to as “main()” to save space when writing it, note that when “main()” is written it still implies that it is defined with its three input arguments). The idea is that within main(), the program calls the other functions. (Of course, these functions may then call further functions.) The reason this is essential is that when your program is tested on Moodle, the testing program will call your main() function. So, if you fail to define main(), the testing program will not be able to test your program and your submission will be graded zero. Don’t forget the penalty for repeated submissions (see the Project 1 Moodle submission page for more information about this). Things to avoid: There are a few things for your program to avoid. • You are not allowed to import any Python module. While use of the many of these modules, e.g. csv or math is a perfectly sensible thing to do in a production setting, it takes away much of the point of different aspects of the project, which is about getting practice opening text files, processing text file data, and use of basic Python structures, in this case lists and loops. • Do not assume that the input file names will end in .csv. File name suffixes such as .csv and .txt are not mandatory in systems other than Microsoft Windows. Do not enforce that within your program that the file must end with a .csv or any other extension (or try to add an extension onto the provided csvfile argument), doing so can easily lead to lost marks. • Ensure your program does NOT call the input()function at any time. Calling the input() function will cause your program to hang, waiting for input that automated testing system will not provide (in fact, what will happen is that if the marking program detects the call(s), and will not test your code at all which may result in zero grade). • Your program should also not call the print()function at any time. If it has encountered an error state and is exiting gracefully then your program
Answered Same DaySep 15, 2021CITS1401

Answer To: CITS1401 Computational Thinking with Python Project 1 Semester 2 2020 Page 1 of 6 Project 1:...

Shivani answered on Sep 16 2021
140 Votes
import math
def correlationCoefficient(X, Y, n) :
sum_X = 0
sum_Y = 0
sum_XY = 0
squareSum_X = 0
squareSum_Y = 0
i = 0
while i < n :
# sum of
elements of array X.
sum_X = sum_X + X[i]
# sum of elements of array Y.
sum_Y = sum_Y + Y[i]
# sum of X[i] * Y[i].
sum_XY = sum_XY + X[i] * Y[i]
# sum of square of array elements.
squareSum_X = squareSum_X + X[i] * X[i]
squareSum_Y = squareSum_Y + Y[i] * Y[i]
i = i + 1

# use formula for calculating correlation
# coefficient.
corr = (float)(n * sum_XY - sum_X * sum_Y)/ (float)(math.sqrt((n * squareSum_X - sum_X * sum_X)* (n * squareSum_Y - sum_Y * sum_Y)))
return round(corr,4)
def main(csvfile, year, type):
# open the csv file
fp = open(csvfile, "r")
# skip the first header line
next(fp, None)
list_min=[0.0]*12
list_max=[0.0]*12
list_avg=[0.0]*12
# To store number of days in a month (for calculating average)
cnt_avg=[31,28,31,30,31,30,31,31,30,31,30,31]
# dictionary to store values for rainfall in each month (for calculating std dev)
dct = {}
for i in range(1,13):
dct['month_%s' % i] = []
list_stddev=[0.0]*12
list1_min=[0.0]*12
list1_max=[0.0]*12
list1_avg=[0.0]*12
dct1 = {}
for i in range(1,13):
dct1['month_%s' % i] = []
list1_stddev=[0.0]*12

if type == "stats":
lines = fp.readlines()
for line in lines:
curr_line = (line.strip()).split(',')
# if current line is for the given year
if int(curr_line[1]) == year:
mnth = int(curr_line[2])
# If no rainfall is recorded for this month of the year, let it be 0
if curr_line[4] ==...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here