0% found this document useful (0 votes)
41 views

AdditionalAssignment2018 2

This document describes a programming assignment for a data science course. It includes 4 parts to complete: 1) Validate the strike rates in a cricket scorecard by recomputing them from runs and balls. 2) Write a function to simulate the outcome of each ball in cricket and update the score. 3) Write a function to simulate the full score of a single batsman. 4) Write a function to simulate the total score of a 10-member cricket team.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

AdditionalAssignment2018 2

This document describes a programming assignment for a data science course. It includes 4 parts to complete: 1) Validate the strike rates in a cricket scorecard by recomputing them from runs and balls. 2) Write a function to simulate the outcome of each ball in cricket and update the score. 3) Write a function to simulate the full score of a single batsman. 4) Write a function to simulate the total score of a 10-member cricket team.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Project Spring 2018

301113 Programming for Data Science

Due Friday ofFriday,


11:59pm
11:59pm week January
Monday 124th Feb
25 (Sydney Time)

1 Project Description

In this assignment there are 4 parts. For each part you should:
• Write the appropriate code.
• Include comments within the code to explain thewhatalgorithm.
the code does.
• Test the code to ensure its correctness.
• Format and stricture
structure the code to maximise its readability.
A report must be submitted containing a cover page, the solutions to each of the four parts, and your code, as
a PDF using the vUWS assignment submission page.
The cover page must contain your name, student number, unit number and name, and the declaration below.
Submission
Submissionis is
duedue
by Friday of weekMonday
by 11:59pm
11:59pm 12 using4th
Friday, the vUWS online
January
February system. Time)
25 (Sydney Late submissions
via emailwillto receive a 10%
Dr Barnes:
reduction in marks for each day late.
[email protected] . Late submissions will receive a 10% reduction in marks for each day late.

2 Marking Criteria

This assignment is worth 40% of the unit assessment tasks. There four problems to investigate and 10 marks
available for each of the four questions. The marking criteria for each question is given in Table 1.
When writing the solutions to each of the four parts, make sure to consult the marking criteria and check that
you have covered them. The project will be marked using this criteria.

Criteria Q1 Q2 Q3 Q4
Code Correctness (5 marks)
Comments explaining code (2 marks)
Code Testing (1 mark)
Code Style and Readability (2 marks)
Total (10 marks)

Table 1: Marking criteria for each part of this project.

1
Batsman How Out Runs Balls 4s 6s SR
KL Rahul c Finch b Hazlewood 2 8 0 0 25.00
M Vijay c †Paine b Starc 11 22 1 0 50.00
CA Pujara run out (Cummins) 123 246 7 2 50.00
V Kohli (c) c Khawaja b Cummins 3 16 0 0 18.75
AM Rahane c Handscomb b Hazlewood 13 31 0 1 41.93
RG Sharma c Harris b Lyon 37 61 2 3 60.65
RR Pant † c †Paine b Lyon 25 38 2 1 65.78
R Ashwin c Handscomb b Cummins 25 76 1 0 32.89
I Sharma b Starc 4 20 1 0 20.00
Mohammed Shami c †Paine b Hazlewood 6 10 1 0 60.00
JJ Bumrah not out 0 0 0 0 -

Table 2: India’s �rst innings results.

3 Declaration

Before submitting the assignment, include the following declaration in a clearly visible and readable place on
the cover page of your project report.

By including this statement, we the authors of this work, verify that:


• We hold a copy of this assignment that we can produce if the original is lost or damaged.
• We hereby certify that no part of this assignment/product has been copied from any other student’s
work or from any other source except where due acknowledgement is made in the assignment.
• No part of this assignment/product has been written/produced for us by another person except where
such collaboration has been authorised by the subject lecturer/tutor concerned.
• We are aware that this work may be reproduced and submitted to plagiarism detection software programs
for the purpose of detecting possible plagiarism (which may retain a copy on its database for future
plagiarism checking).
• We hereby certify that we have read and understand what the School of Computing, Engineering and
Mathematics de�nes as minor and substantial breaches of misconduct as outlined in the learning guide
for this unit.

Note: An examiner or lecturer/tutor has the right not to mark this project report if the above declaration has
not been added to the cover of the report.

4 Project �estions

The scorecard in Table 2 is from the �rst innings of the �rst cricket test in the Australia vs India 2018
series. http://www.espncricinfo.com/series/18693/scorecard/1144993/australia-vs-india-1st-test-india-in-aus-
2018-19
The columns show:

2
• Batsman: The name of the batsman.
• How Out: How the batsman was given out.
• Runs: The number of runs made by the batsman.
• Balls: The number of balls faced by the batsman.
• 4s: The number of 4s hit by the batsman.
• 6s: The number of 6s hit by the batsman.
• SR: The batsman’s strike rate (100*Runs/Balls).

4.1 Validating the Strike Rate

Cricinfo believe that there is a bug in their code that computes the batsman’s strike rate (SR), and so they want
you to verify the numbers.
Write the code to:
1. Create a data frame in R containing the data from Table 2.
2. Compute the strike rate using the data frame from the Runs and Balls.
3. Subtract your computed strike rate from the data frame column SR.
Finally, state if your output shows errors in the data, and where the errors occur.

4.2 Ball Outcome

Cricinfo want to create a simple cricket simulator to test their scorecard and so have come to you for help.
After a ball is bowled, there are eight possible outcomes. Below we list the eight outcomes and each outcome’s
e�ect on the score:
• 0 runs: add 1 to the ball count
• 1 run: add 1 to the ball count, add 1 to the run count
• 2 runs: add 1 to the ball count, add 2 to the run count
• 4 runs: add 1 to the ball count, add 4 to the run count, add 1 to the 4s count
• 6 runs: add 1 to the ball count, add 6 to the run count, add 1 to the 6s count
• Wide: add 1 to the extras count
• No ball: add 1 to the extras count
• Out: add 1 to the ball count, mark batsman as out
Cricinfo store a batsman’s record using the variable:
state = list(balls = 0, runs = 0, fours = 0, sixes = 0, extras = 0, out = FALSE)
Write the function oneBall that takes the input state and one outcome and returns the updated state based
on the eight outcomes above.

4.3 Batsman’s score

A batsman keeps facing balls until the batsman is out. To simulate a single batsman, we need to:
1. Randomly sample one of the eight outcomes,
2. Update the score state,
3. Repeat until the outcome is Out.

3
Write the function oneBatsman that randomly samples one of the eight outcomes from above, updates the
score using your function oneBall, then repeats until the outcome is Out. Note that we can randomly sample
an outcome using:
outcome = sample(c("0 runs", "1 runs", "2 runs", "4 runs", "6 runs",
"Wide", "No Ball", "Out"), size = 1)

4.4 Team Score

The �nal piece of the simulation is to simulate the score for the whole team, and compute the team score.
Write a function that contains the code to:
1. Simulate the scores for 10 batsmen (using the function oneBatsman).
2. Add the runs and extras from each batsman to obtain the team score.

You might also like