Difference between revisions of "OPS435 Online Assignment 1"
Eric.brauer (talk | contribs) (→The First Milestone) |
|||
(10 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
[[Category:OPS435-Python]][[Category:rchan]] | [[Category:OPS435-Python]][[Category:rchan]] | ||
= Overview = | = Overview = | ||
− | When | + | When applying for a bank account, accepting a job, or some other activity that is personal, it may involve the processing of someone's date of birth. It is critical for this type of data to be validated before being processed by a computation system. |
− | The | + | The task for this assignment is to design an <b>algorithm</b> and write a python script to validate a given string in various forms as the date of birth of someone and convert it into a standard format. The DOB (date of birth) conversion script should take a date in one of the following four formats: "YYYYMMDD", "YYYY/MM/DD", "YYYY-MM-DD", and "YYYY.MM.DD" format and return the date in a standard format: 'mmm d, yyyy", where "mmm" is the three letter abbreviated month's name, 'd' is a one or two-digit day of the month, and 'yyyy' is the four-digit year. That is, if the user enters "20210604", or "2021-06-04", or "2021/06/04", or "2021.06.04", the script will return "Jun 4, 2021". More examples to follow. |
− | |||
− | |||
= Assignment Requirements = | = Assignment Requirements = | ||
− | == The First | + | == The First Checkpoint (Jun 9) == |
− | * Before you begin | + | * Before you begin coding in Python, it is important to plan your algorithm. Therefore your first task will be to complete and submit an algorithm document. This document should be named '''algorithm_[Seneca_name].txt'''. This file should be plaintext. The document will contain two sections: |
− | + | :* A description of how your main program works. The main program flow is provided to you in a1_template.py. Open the file, and use clear and simple English to describe what each line of code does in such a way that a competent Python coder could reproduce the code without seeing it first hand. | |
− | + | :* You will then apply the same principles to create an <b>algorithm</b> for each validation function named in the a1_template.py file. Inside the code, if you are calling another function like "leap_year()", you may simply describe what the function will return, and not the operation of the function itself. | |
− | * This file | + | * This file should be submitted to Blackboard by Jun 9, 2021, and should be your first priority. The objective of the first checkpoint is not to have a 100% perfect algorithm, but to plan ahead and anticipate challenges and issues with the assignment. The first checkpoint will also allow your professor an opportunity to give you feedback before the assignment overall due date. |
* [https://simple.m.wikipedia.org/wiki/Algorithm Here is an basic introduction to Algorithm] | * [https://simple.m.wikipedia.org/wiki/Algorithm Here is an basic introduction to Algorithm] | ||
* While you are working on the step-by-step instructions, note that there are different number of days in each month and some years have 365 days and some years have 366 days. | * While you are working on the step-by-step instructions, note that there are different number of days in each month and some years have 365 days and some years have 366 days. | ||
− | * | + | * Since we don't think we are going to encounter someone who is 120 years or older, your algorithm can consider a date of birth before year 1900 as invalid. Could you think of other limits you should impose on someone's date of birth? |
− | == The | + | == The 2nd Checkpoint - your drafted Python Script (Jun 16) == |
− | * As stated before, your code will be inside the file "a1_[ | + | * As stated before, your code will be inside the file "a1_[Seneca_name].py". The first step will be to clone the Assignment 1 template repository (https://github.com/rayfreeping/ops435-a1). Once you clone the repository, run this command: "cp a1_template.py a1_[Seneca_name].py". (Replace Seneca_name with your Seneca account user name). Begin coding your algorithm into Python code that is required. Additional requirements are outlined below. |
+ | * Your should update the author and date information in your Python script. | ||
+ | * Your Python script file a1_[Seneca_name].py should be submitted to Blackboard by Jun 16, 2021. * The script doesn't have to be perfect and error free. However, it shouldn't contain any syntax errors when executed. | ||
+ | * This intern submission is just to show that you are actively working on your assignment. | ||
− | == The | + | == The Final submission with preliminary test results (Jun 21) == |
− | + | * Run the preliminary test script named "checkA1.py" in the "tests" sub-folder of the ops435-a1 repository mentioned above. | |
− | * | + | * Please read the readme.txt in the tests sub-folder for more information on the purpose of the preliminary test script. |
− | + | * When your are satisfy with the test result, capture the test result to a file named a1_pretest.txt and submit it together with your Python script a1_[Seneca_name].py to Blackboard by Jun 21, 2021. | |
− | |||
− | * | ||
− | |||
− | == | + | == Python Coding Requirements == |
=== Required Modules and Functions === | === Required Modules and Functions === | ||
− | <b><font color='blue'>Your python script is allowed to | + | <b><font color='blue'>Your python script is allowed to call all the built-in functions and the functions imported from the <u>os, subprocess and sys</u> modules from the standard library.</font></b> |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | Based on the algorithm you have designed for this assignment, you should at least have the following five functions defined in your python script (see later section on the purpose of each function): | |
− | |||
* leap_year() | * leap_year() | ||
− | * | + | * range_check() |
+ | * sanitize() | ||
+ | * size_check() | ||
* usage() | * usage() | ||
Line 49: | Line 42: | ||
=== Command Line Argument to be supported === | === Command Line Argument to be supported === | ||
− | + | * Your Python script must accept only one command line argument: date. Input date in the following format with correct values of YYYY, MM, and DD should be considered as valid input data: | |
− | + | ** <code>YYYYMMDD</code> | |
− | * Your | + | ** <code>YYYY/MM/DD</code> |
− | * If there are no | + | ** <code>YYYY-MM-DD</code> |
+ | ** <code>YYYY.MM.DD</code> | ||
+ | * If there are no argument, more than one argument, or an invalid year, month, or day, your script should display the appropriate usage message, error code, and exit. | ||
=== Documentation === | === Documentation === | ||
− | * Please use python's docstring to document your python script | + | * Please use python's docstring to document your python script |
− | + | ** script level documentation, and | |
+ | ** function level documention for each function you created for this assignment. | ||
+ | * The docstring should describe 'what' the function does, not 'how' it does. | ||
=== Authorship Declaration === | === Authorship Declaration === | ||
Line 62: | Line 59: | ||
=== Github Commits === | === Github Commits === | ||
− | You will be graded partly on the quality of your Github commits. Professionals generally follow these guidelines: | + | You will be graded partly on the quality and transaction activities of your Github commits. Professionals generally follow these guidelines: |
* commit their code after every significant change, | * commit their code after every significant change, | ||
− | * the code should run without errors after each commit, and | + | * the code should run without syntax errors after each commit, and |
* every commit has a descriptive commit message. | * every commit has a descriptive commit message. | ||
− | These guidelines are not always possible, but you | + | These guidelines are not always possible, but you are expected to follow these guidelines as much as possible. Break the assigned task into smaller pieces, and work iteratively to solve each small task. Test your code after each small change you made, and address errors as soon as they arise. It will make your coding life easier! |
== Tests and Test results == | == Tests and Test results == | ||
− | You must name your python 3 script as <code>a1_[ | + | You must name your python 3 script as <code>a1_[Seneca_name].py</code>. The following examples assumes that the Seneca_name is rchan. The script should accept one command line argument, the argument can be either in "YYYYMMDD", "YYYY/MM/DD", "YYYY-MM-DD", or "YYYY.MM.DD" format. If the input data does not represent a real date, your script should give an appropriate error message. Invalid months (>12) or invalid days of month(different for each month, and if the month is February, the year matter too), should be detected and give appropriate error messages. For examples: |
− | * <b><code>python3 a1_rchan.py | + | * <b><code>python3 a1_rchan.py 2020-10-10</code></b>, and the output should be<br /> |
− | + | Oct 10, 2020 | |
− | * <b><code>python3 a1_rchan.py | + | * <b><code>python3 a1_rchan.py 2020-10-09</code></b>, and the output should be<br /> |
− | + | Oct 9, 2020 | |
− | * <b><code>python3 a1_rchan.py | + | * <b><code>python3 a1_rchan.py 2020-06-30</code></b>, and the output should be<br /> |
− | + | Jun 30, 2020 | |
− | * <b><code>python3 a1_rchan.py | + | * <b><code>python3 a1_rchan.py 20201010</code></b>, and the output should be<br /> |
− | + | Oct 10, 2020 | |
− | * <b><code>python3 a1_rchan.py | + | * <b><code>python3 a1_rchan.py 2020/10/10</code></b>, and the output should be<br /> |
− | + | Oct 10, 2020 | |
− | * <b><code>python3 a1_rchan.py | + | * <b><code>python3 a1_rchan.py 2020.02.29</code></b>, and the output should be<br /> |
− | Error: wrong month entered | + | Feb 29, 2020 |
− | * <b><code>python3 a1_rchan.py | + | * <b><code>python3 a1_rchan.py 2019.02.29</code></b>, and the output should be<br /> |
− | Error: wrong day entered | + | Error 03: wrong day entered |
− | * <b><code>python3 a1_rchan.py | + | * <b><code>python3 a1_rchan.py 2019.13.12</code></b>, and the output should be<br /> |
− | Error: wrong date entered | + | Error 02: wrong month entered |
+ | * <b><code>python3 a1_rchan.py 2019.06.31</code></b>, and the output should be<br /> | ||
+ | Error 03: wrong day entered | ||
+ | * <b><code>python3 a1_rchan.py 201802</code></b>, and the output should be<br /> | ||
+ | Error 09: wrong date entered | ||
+ | * <b><code>python3 a1_rchan.py 18981225</code></b>, and the output should be <br /> | ||
+ | Error 10: year out of range, must be 1900 or later | ||
+ | * <b><code>python3 a1_rchan.py 18981299</code></b>, and the output should be <br /> | ||
+ | Error 10: year out of range, must be 1900 or later | ||
+ | * <b><code>python3 a1_rchan.py 189802</code></b>, and the output should be<br /> | ||
+ | Error 09: wrong date entered | ||
+ | |||
− | If there is too few or too many command line | + | If there is too few or too many command line argument given, display the proper usage: |
− | * <code>Usage: a1_rchan.py DD-MM-YYYY | + | * <code>Usage: a1_rchan.py YYYYMMDD|YYYY/MM/DD|YYYY-MM-DD|YYYY.MM.DD </code> |
== Script structure and sample template == | == Script structure and sample template == | ||
The following is a brief description of each function: | The following is a brief description of each function: | ||
− | |||
− | |||
− | |||
− | |||
− | |||
* The leap_year() function will take a year in "YYYY" format, and return True if the given year is a leap year, otherwise return False. | * The leap_year() function will take a year in "YYYY" format, and return True if the given year is a leap year, otherwise return False. | ||
− | * The | + | * The range_check() function will take an integer object and a tuple with two integer values, the first value indicates the lower bound and the second one indicates the upper bound of a integer range. If the integer object falls in between the range given in the tuple, return 'True', otherwise return 'False'. |
− | * The | + | * The sanitize() function will take two string objects, the first string object is the object to be sanitized, and the 2nd string object contains letters that are allowed. This function will return the first object with letters not in the 2nd string object removed. |
+ | * The size_check() function will take an collection data type object and expected number of items as an integer and will return either 'True' or 'False'. If the number of items in the data object match the integer value given, return 'True', otherwise return 'False' | ||
* The usage() function will take no argument and return a string describing the usage of the script. | * The usage() function will take no argument and return a string describing the usage of the script. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
= Rubric = | = Rubric = | ||
Line 160: | Line 116: | ||
| Check script passed || 30 || | | Check script passed || 30 || | ||
|- | |- | ||
− | | | + | | size_check() function design || 4 || |
|- | |- | ||
− | | | + | | sanitize() function design || 4 || |
|- | |- | ||
− | | | + | | leap_year() function design || 4 || |
|- | |- | ||
− | | | + | | range_check() function design || 4 || |
|- | |- | ||
− | | | + | | usage() function design || 4 || |
|- | |- | ||
− | | | + | | script level docstring || 5 || |
|- | |- | ||
− | | | + | | function level docstring || 5 || |
|- | |- | ||
− | | First | + | | First Checkpoint ||10|| |
|- | |- | ||
− | | | + | | Second Checkpoint || 10 || |
|- | |- | ||
| github.com repository: Commit messages and use ||15|| | | github.com repository: Commit messages and use ||15|| | ||
Line 189: | Line 145: | ||
Please submit the following files by the due date: | Please submit the following files by the due date: | ||
− | * [ ] your algorithm document, named as ' | + | * [ ] your algorithm document, named as 'algorithm_[Seneca_name].txt', to Blackboard. |
− | * [ ] your python script, named as 'a1_[ | + | * [ ] your python script, named as 'a1_[Seneca_name].py', should be included in your repository, and also '''submitted to Blackboard.''' |
− | * [ ] the output of the checking script checkA1.py, named as ' | + | * [ ] the output of the checking script checkA1.py, named as 'a1_pretest.txt', should be included in your repository, and also '''submitted to Blackboard.''' |
− |
Latest revision as of 09:45, 3 June 2021
Contents
- 1 Overview
- 2 Assignment Requirements
- 3 Rubric
- 4 Due Date and Final Submission requirement
Overview
When applying for a bank account, accepting a job, or some other activity that is personal, it may involve the processing of someone's date of birth. It is critical for this type of data to be validated before being processed by a computation system.
The task for this assignment is to design an algorithm and write a python script to validate a given string in various forms as the date of birth of someone and convert it into a standard format. The DOB (date of birth) conversion script should take a date in one of the following four formats: "YYYYMMDD", "YYYY/MM/DD", "YYYY-MM-DD", and "YYYY.MM.DD" format and return the date in a standard format: 'mmm d, yyyy", where "mmm" is the three letter abbreviated month's name, 'd' is a one or two-digit day of the month, and 'yyyy' is the four-digit year. That is, if the user enters "20210604", or "2021-06-04", or "2021/06/04", or "2021.06.04", the script will return "Jun 4, 2021". More examples to follow.
Assignment Requirements
The First Checkpoint (Jun 9)
- Before you begin coding in Python, it is important to plan your algorithm. Therefore your first task will be to complete and submit an algorithm document. This document should be named algorithm_[Seneca_name].txt. This file should be plaintext. The document will contain two sections:
- A description of how your main program works. The main program flow is provided to you in a1_template.py. Open the file, and use clear and simple English to describe what each line of code does in such a way that a competent Python coder could reproduce the code without seeing it first hand.
- You will then apply the same principles to create an algorithm for each validation function named in the a1_template.py file. Inside the code, if you are calling another function like "leap_year()", you may simply describe what the function will return, and not the operation of the function itself.
- This file should be submitted to Blackboard by Jun 9, 2021, and should be your first priority. The objective of the first checkpoint is not to have a 100% perfect algorithm, but to plan ahead and anticipate challenges and issues with the assignment. The first checkpoint will also allow your professor an opportunity to give you feedback before the assignment overall due date.
- Here is an basic introduction to Algorithm
- While you are working on the step-by-step instructions, note that there are different number of days in each month and some years have 365 days and some years have 366 days.
- Since we don't think we are going to encounter someone who is 120 years or older, your algorithm can consider a date of birth before year 1900 as invalid. Could you think of other limits you should impose on someone's date of birth?
The 2nd Checkpoint - your drafted Python Script (Jun 16)
- As stated before, your code will be inside the file "a1_[Seneca_name].py". The first step will be to clone the Assignment 1 template repository (https://github.com/rayfreeping/ops435-a1). Once you clone the repository, run this command: "cp a1_template.py a1_[Seneca_name].py". (Replace Seneca_name with your Seneca account user name). Begin coding your algorithm into Python code that is required. Additional requirements are outlined below.
- Your should update the author and date information in your Python script.
- Your Python script file a1_[Seneca_name].py should be submitted to Blackboard by Jun 16, 2021. * The script doesn't have to be perfect and error free. However, it shouldn't contain any syntax errors when executed.
- This intern submission is just to show that you are actively working on your assignment.
The Final submission with preliminary test results (Jun 21)
- Run the preliminary test script named "checkA1.py" in the "tests" sub-folder of the ops435-a1 repository mentioned above.
- Please read the readme.txt in the tests sub-folder for more information on the purpose of the preliminary test script.
- When your are satisfy with the test result, capture the test result to a file named a1_pretest.txt and submit it together with your Python script a1_[Seneca_name].py to Blackboard by Jun 21, 2021.
Python Coding Requirements
Required Modules and Functions
Your python script is allowed to call all the built-in functions and the functions imported from the os, subprocess and sys modules from the standard library.
Based on the algorithm you have designed for this assignment, you should at least have the following five functions defined in your python script (see later section on the purpose of each function):
- leap_year()
- range_check()
- sanitize()
- size_check()
- usage()
Coding Standard
Your python script must follow the following coding guide:
Command Line Argument to be supported
- Your Python script must accept only one command line argument: date. Input date in the following format with correct values of YYYY, MM, and DD should be considered as valid input data:
-
YYYYMMDD
-
YYYY/MM/DD
-
YYYY-MM-DD
-
YYYY.MM.DD
-
- If there are no argument, more than one argument, or an invalid year, month, or day, your script should display the appropriate usage message, error code, and exit.
Documentation
- Please use python's docstring to document your python script
- script level documentation, and
- function level documention for each function you created for this assignment.
- The docstring should describe 'what' the function does, not 'how' it does.
Authorship Declaration
All your Python code for this assignment must be placed in a single source python file. Please complete the declaration as part of the docstring in your Python source code file (replace "Student Name" with your own name).
Github Commits
You will be graded partly on the quality and transaction activities of your Github commits. Professionals generally follow these guidelines:
- commit their code after every significant change,
- the code should run without syntax errors after each commit, and
- every commit has a descriptive commit message.
These guidelines are not always possible, but you are expected to follow these guidelines as much as possible. Break the assigned task into smaller pieces, and work iteratively to solve each small task. Test your code after each small change you made, and address errors as soon as they arise. It will make your coding life easier!
Tests and Test results
You must name your python 3 script as a1_[Seneca_name].py
. The following examples assumes that the Seneca_name is rchan. The script should accept one command line argument, the argument can be either in "YYYYMMDD", "YYYY/MM/DD", "YYYY-MM-DD", or "YYYY.MM.DD" format. If the input data does not represent a real date, your script should give an appropriate error message. Invalid months (>12) or invalid days of month(different for each month, and if the month is February, the year matter too), should be detected and give appropriate error messages. For examples:
-
python3 a1_rchan.py 2020-10-10
, and the output should be
Oct 10, 2020
-
python3 a1_rchan.py 2020-10-09
, and the output should be
Oct 9, 2020
-
python3 a1_rchan.py 2020-06-30
, and the output should be
Jun 30, 2020
-
python3 a1_rchan.py 20201010
, and the output should be
Oct 10, 2020
-
python3 a1_rchan.py 2020/10/10
, and the output should be
Oct 10, 2020
-
python3 a1_rchan.py 2020.02.29
, and the output should be
Feb 29, 2020
-
python3 a1_rchan.py 2019.02.29
, and the output should be
Error 03: wrong day entered
-
python3 a1_rchan.py 2019.13.12
, and the output should be
Error 02: wrong month entered
-
python3 a1_rchan.py 2019.06.31
, and the output should be
Error 03: wrong day entered
-
python3 a1_rchan.py 201802
, and the output should be
Error 09: wrong date entered
-
python3 a1_rchan.py 18981225
, and the output should be
Error 10: year out of range, must be 1900 or later
-
python3 a1_rchan.py 18981299
, and the output should be
Error 10: year out of range, must be 1900 or later
-
python3 a1_rchan.py 189802
, and the output should be
Error 09: wrong date entered
If there is too few or too many command line argument given, display the proper usage:
-
Usage: a1_rchan.py YYYYMMDD|YYYY/MM/DD|YYYY-MM-DD|YYYY.MM.DD
Script structure and sample template
The following is a brief description of each function:
- The leap_year() function will take a year in "YYYY" format, and return True if the given year is a leap year, otherwise return False.
- The range_check() function will take an integer object and a tuple with two integer values, the first value indicates the lower bound and the second one indicates the upper bound of a integer range. If the integer object falls in between the range given in the tuple, return 'True', otherwise return 'False'.
- The sanitize() function will take two string objects, the first string object is the object to be sanitized, and the 2nd string object contains letters that are allowed. This function will return the first object with letters not in the 2nd string object removed.
- The size_check() function will take an collection data type object and expected number of items as an integer and will return either 'True' or 'False'. If the number of items in the data object match the integer value given, return 'True', otherwise return 'False'
- The usage() function will take no argument and return a string describing the usage of the script.
Rubric
Task | Maximum mark | Actual mark |
---|---|---|
Program Authorship Declaration | 5 | |
Check script passed | 30 | |
size_check() function design | 4 | |
sanitize() function design | 4 | |
leap_year() function design | 4 | |
range_check() function design | 4 | |
usage() function design | 4 | |
script level docstring | 5 | |
function level docstring | 5 | |
First Checkpoint | 10 | |
Second Checkpoint | 10 | |
github.com repository: Commit messages and use | 15 | |
Total | 100 |
Due Date and Final Submission requirement
Check with your professor for the due date for your section.
Please submit the following files by the due date:
- [ ] your algorithm document, named as 'algorithm_[Seneca_name].txt', to Blackboard.
- [ ] your python script, named as 'a1_[Seneca_name].py', should be included in your repository, and also submitted to Blackboard.
- [ ] the output of the checking script checkA1.py, named as 'a1_pretest.txt', should be included in your repository, and also submitted to Blackboard.