Changes

Jump to: navigation, search

OPS445/A1-S23-NAANBB

9,321 bytes added, 20:47, 30 May 2023
initial import
<span id="assignment-1"></span>
= Assignment 1 =

<span id="overview"></span>
== Overview ==

Your assignment will calculate the number of weekend days (Saturdays and Sundays) within a given period of time. The time period in question will be calculated from a start date and an end date.

Example:

<code>python3 assignment1.py 2023-05-01 2023-05-30</code>

<pre>The period between 2023-05-01 and 2023-05-30 includes 8 weekend days.</pre>
<span id="restrictions"></span>
== Restrictions ==

* You may '''only use <code>sys</code> for parsing command line arguments'''.
* No other modules are allowed

<span id="instructions"></span>
== Instructions ==

The assignment will be broken into two milestones and one final submission. Please update your repository for each milestone and complete the final submission in order to earn all marks.

* Milestone 1 will be due on '''June 9 at 5:00pm'''.
* Milestone 2 will be due on '''June 16 at 5:00pm'''.
* The Final submission will be due on '''June 23 at 5:00pm'''.


-----

<span id="preparation"></span>
=== Preparation ===

# Accept the assignment on Blackboard.
# Once you accepted the assignment, you will get access to a starting repo.
# Add your code to the ''existing'' <code>assignment1.py</code> file.
# Commit after '''each significant change''' to the code.
# '''You can never have too many commits.''' GitHub is your proof of work and your backup if things go wrong.

<span id="milestone-1"></span>
=== Milestone 1 ===

# You are provided with a function called <code>after()</code>. This function is complete and should successfully return the next day’s date when provided with a starting date in <code>YYYY-MM-DD</code> format. You can experiment with this function by importing it into the Python interpreter:

<syntaxhighlight lang="python">from assignment1 import after
after('2023-01-25')</syntaxhighlight>
<ol start="2" style="list-style-type: decimal;">
<li>Study the <code>after()</code> function and explain how it works. Use '''in-line comments''' for each line of code.</li></ol>

This Milestone will ask you to ''refactor'' your code. This means modifying existing code to make it more portable.

<ol start="3" style="list-style-type: decimal;">
<li>Complete the <code>leap_year()</code> function, using the relevant code that’s already inside <code>after()</code>.</li>
<li>Edit your <code>after()</code> function. Replace any code that calculates leap years with a <code>leap_year</code> function call.<br />
</li>
<li>Repeat the same process for the <code>mon_max()</code> function.</li>
<li>Verify that <code>after()</code> still works after your changes.</li>
<li>Don’t forget to push your code.</li></ol>

<span id="check-your-work"></span>
==== Check Your Work ====

Use the check script to verify your work so far.

<code>python3 CheckA1.py -f -v TestAfter</code> <code>python3 CheckA1.py -f -v TestLeap</code> <code>python3 CheckA1.py -f -v TestMonMax</code>

<span id="feedback"></span>
==== Feedback ====

I will provide you feedback on '''GitHub'''. Check the '''Issues''' tab, and make any changes that are required before the next deadline. You can '''close the issue''' to indicate that you have seen the comment.


-----

<span id="milestone-2"></span>
=== Milestone 2 ===

# Complete the <code>day_count()</code> function. Given a starting date and ending_date, <code>day_count()</code> should call <code>after()</code> inside of a loop. For each date (including the start and end dates), your function should call the provided <code>day_of_week()</code> function. Count each Saturday and Sunday, and return that number as an integer.
# Complete the <code>valid_date()</code> function. This should use error checking to make sure that any date entered by the user is valid.

<span id="check-your-work-1"></span>
==== Check Your Work ====

Use the check script to verify your work.

* <code>python3 CheckA1.py -f -v TestValidDate</code>
* <code>python3 CheckA1.py -f -v TestDayCount</code>

<span id="feedback-1"></span>
==== Feedback ====

Once again I will provide you feedback on '''GitHub'''. Check the '''Issues''' tab, and make any changes that are required before the next deadline. You can '''close the issue''' to indicate that you have seen the comment.


-----

<span id="final-submission"></span>
=== Final Submission ===

For the final submission you should integrate your functions into a working script, add relevant comments and implement some '''error checking''' so that invalid or dates will cause a '''usage''' message to be displayed. In addition, the earlier date should always be considered the '''start date''' even if the '''user enters the dates in the wrong order'''.

# In the ''main'' block, check the number of arguments. Both arguments should be valid dates.
# Create or research a function to verify that the start date is always earlier than the end date. Failing to do so will cause an infinite loop.
# Print the number of weekend days in the given time period.
# Complete the <code>usage()</code> function. This should print a helpful message to the user when they make a mistake, and exit.

<span id="final-checks"></span>
==== Final Checks ====

* <code>python3 CheckA1.py -f -v TestFinal</code> to test the final version of your script.

<span id="submitting-your-code-for-review"></span>
==== Submitting Your Code For Review ====

# Push your code to GitHub before the deadline.
# In addition, '''submit your code to Blackboard'''. A link will be provided.


-----

<span id="formatting-and-style"></span>
== Formatting And Style ==

A significant amount of your mark will be based on the things that ''aren’t'' your code. Please review the following guidelines to maximise your grade.

<span id="comments-and-documentation"></span>
=== Comments And Documentation ===

'''You need to be commenting your code'''. The following documentation is required:

* '''in-line comments''': Any line of code that is doing something non-obvious should be commented. Explain '''why''' you are doing something, rather than '''what''' you are doing.
* '''function docstrings''': After your <code>def</code> line, you enter a docstring inside ““. Any function that doesn’t already come with a docstring should have one.
* '''top-level docstring''': You will have noticed that the top of your <code>assignment1.py</code> file already has this docstring. Complete the '''Academic Honesty declaration''' and complete the docstring.

<span id="pep"></span>
=== PEP ===

The [https://peps.python.org/pep-0008/ PEP-8 Style Guide] is an official Python document that describes best practices for formatting your code. '''You should follow this guide as much as possible'''. You may find that [https://code.visualstudio.com/docs/python/linting using a linter] to check style to be useful.

<span id="functions-and-variables"></span>
=== Functions and Variables ===

* In addition to the required functions, you may create as many functions as you need.
* Functions should be in lower case, and spaces should be represented with an underscore. For example: <code>function_name</code>.
* Any data used inside of a function should be passed in as a parameter. Avoid global variables.
* Variables should have a sensible name. Avoid naming things <code>x</code>.
* Variables should be in lower case, and spaces represented by an underscore. For example: <code>start_date</code>.

<span id="git-commits"></span>
=== Git Commits ===

A workplace will have its own policy about how often to commit, and how to document commits. For us, '''git commits are your proof of work'''. Assignments that lack commits are subject to '''Academic Integrity review'''.

* A good practice is to create a commit for '''every significant change''' to your code. '''At the very least, commit after completing each of the required functions.'''
* An acceptable commit message needs to short, but should also describe the change. For example: <code>git commit -m &quot;completed the leap_year function&quot;</code>.

<span id="rubric"></span>
== Rubric ==

{|
! Element
!align="right"| Marks
|-
| '''Milestone 1:'''
|align="right"|
|-
| Documentation for <code>after</code> function
|align="right"| 4
|-
| TestAfter Checks
|align="right"| 2
|-
| TestLeap Checks
|align="right"| 2
|-
| TestMonMax Checks
|align="right"| 2
|-
| '''Milestone 2:'''
|align="right"|
|-
| TestValidDate Checks
|align="right"| 4
|-
| TestDayCount Checks
|align="right"| 6
|-
| '''Final Submission:'''
|align="right"|
|-
| TestFinal Checks
|align="right"| 16
|-
| Comments and Documentation
|align="right"| 5
|-
| github use
|align="right"| 5
|-
| functions and style
|align="right"| 2
|-
| error checking
|align="right"| 2
|}

<span id="sample-output"></span>
== Sample Output ==

<code>assignment1.py 2023-05-18 2023-06-04</code>

<pre>The period between 2023-05-18 and 2023-06-04 includes 6 weekend days.</pre>
Works with the dates reversed:

<code>assignment1.py 2023-05-21 2023-05-01</code>

<pre>The period between 2023-05-01 and 2023-05-21 includes 6 weekend days.</pre>
Wrong number of arguments:

<code>assignment1.py 2023-05-21</code>

<pre>Usage: assignment1.py YYYY-MM-DD YYYY-MM-DD</pre>
If either of the dates is invalid, print usage:

<code>assignment1.py 2023-02-31 2023-99-99</code>

<pre>Usage: assignment1.py YYYY-MM-DD YYYY-MM-DD</pre>

Navigation menu