Changes

Jump to: navigation, search

OPS435 Assignment 1 for Section A

1,844 bytes removed, 23:04, 8 October 2020
no edit summary
[[Category:OPS435-Python]][[Category:rchan]]
= Overview =
When making back up of data files or log filesapplying for a bank account, it is accepting a very common practice to name the backup directories and/job, or files based on the date the backup was done. In order to restore or locate the directory/filesome other activity that is personal, we often need to find out it may involve the backup date from todayprocessing of someone's dateof birth. It is critical for this type of data to be validated before being processed by a computation system.
The computational task for this assignment is to design an algorithm and write a python script according to your algorithm with appropriate functionsvalidate a given string in various forms as the date of birth of someone and convert it into a standard format. The DOB conversion script should take two dates a date in the following four formats: "YYYYMMDD", "YYYY/MM/DD", "YYYY-MM-DD", and "YYYY.MM.DD" format and return the number 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 days from the first to month, and 'yyyy' is the second datefour-digit year. That is, if the user enters "1820201007", or "2020-0610-07", or "2020/10/07" and , or "25-06-2020.10.07", the script will return "Oct 7, 2020". Similarly, if the target date is in the past, the script will return a negative number. In addition, if the user enters one date only, then the number returned should be the number of days between today's date and the specified dateMore examples to follow.
= Assignment Requirements =
== The First Milestone Checkpoint (due June 19Oct 13) ==* Before you begin programmingcoding 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_[student_id].txt'''. This file should be plaintext. The document will contain two sections: * A description of how the "after()" function your main program works. The "after()" function main program flow is provided to you in a1_template.py. Open the file, and use clear English to describe what each line of code does in such a way that a competent programmer Python coder could reproduce the code without seeing it firsthand. * You will then apply the same principles to create an algorithm for "before()", and "dbda()"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 will should be submitted to Blackboard a week after the assignment goes liveby Oct 13, 2020, and should be your first priority. The object objective of the milestone first checkpoint is not to have a 100% perfect algorithm, but to plan ahead and anticipate challenges and issues with the assignment. The milestone first checkpoint will also give allow your professor an opportunity for to give you feedbackbefore the assignment overall due date.
* [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.
* You should also do some research Since we don't think we are going to find out when we started using the Calendar in the current formencounter someone who is 120 years or older, your algorithm can consider a date of birth before year 1900 as invalid. (This will pose a Could you think of other limit you should put on the validity someone's date of your algorithm.)birth?
== The Assignment 2nd Checkpoint - your drafted Python Script (due July 3Oct 16) ==* As stated before, your code will be inside the file "a1_[studentidSeneca_name].py". The first step will be to clone the Assignment 1 template repository(https://github. The invite link will be provided to you by your professorcom/rayfreeping/ops435-a1). Once you clone the repository, run this command: "cp a1_template.py a1_[studentidSeneca_name].py". (Replace studentid Seneca_name with your myseneca usernameSeneca account user name). Begin writing the content 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 Oct 16, 2020. * The script doesn't have to be perfect and error free. However, it shouldn't contain any syntax errors when exectued.* This intern submission is just to show that you are activity working on your assignment.
== The Debrief 3rd Checkpoint - preliminary test results (due July 10Oct 20) ==This document, like * Run the preliminary test script named "checkA1.py" in the algorithm document, will be submitted to Blackboard one week after "tests" sub-folder of the assignmentops435-a1 repository mentioned above. Answer the following questions:* Research Python modules that you could have used to accomplish Please read the same goals as the today() and leap_year() functionsreadme. * Which solution is preferable, txt in terms of performance? Which solution is preferable, in terms the tests sub-folder for more information about the purpose of programmer hours? (which solution would take longer for a programmer to implement?)* Which approach would be preferable in the "real world"? Why is it useful to try creating our own algorithm?preliminary test script.* What challenges did you encounter during When your are satisfy with the assignmenttest result, capture the test result to a file named a1_pretest.txt and what resources did you use to solve submit it together with your issues? (help from classmates, help from Stackoverflow, debuggers, etcPython script a1_[Seneca_name].)* Additionallypy to Blackboard by Oct 20, your professor may have questions specific to your submission. You should answer these questions as well2020.
== Assignment Python Coding Requirements ==
=== Required Modules and Functions ===
<b><font color='blue'>Your python script is allowed to import only call all the built-in functions and the functions imported from the <u>os, subprocess and sys</u> modules from the standard library and all the built-in functions.</font></b> Based on the algorithm you have designed for this assignment, you should at least have the following four functions defined in your python script (see later section on the purpose of each function) in order to get a passing grade for this assignment:* dbda()* after()* before()* today()
You Based on the algorithm you have designed for this assignment, you should also create additional at least have the following four functions to improved the re-usability of defined in your python code by adding script (see later section on the following functions to earn the maximum possible mark for this assignmentpurpose of each function):* days_in_mon()
* leap_year()
* valid_daterange_check()* sanitize()* size_check()
* usage()
=== Command Line Argument to be supported ===
* You will provided with a file called a1_template.py.* Rename this python script as a1_[student_id].py, where [student_id] is your Seneca email user name.* Your python Python script must support one or two command line arguments argument only: both date in the following format with correct values in YYYY, MM, and DD should be considered as valid dates in input data:** YYYYMMDD** YYYY/MM/DD** YYYY-MM-DD** YYYY format.MM.DD. * If there are no argumentsargument, more than two argumentsargument, or an invalid dateyear, month, or day, your script should display the correct 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 of the functions (function level documentation) you created for this assignment. * The docstring should describe 'what' the function does, not 'how' it does.* Refer to the docstring for after() to get an idea of the function docstrings required.
=== Authorship Declaration ===
=== 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 will be are expected to follow these guidelines as much as possible. Break your problem into smaller pieces, and work iteratively to solve each small problem. Test your code after each small change you make, 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 <code>a1_[Student_idSeneca_name].py</code>. The following examples assumes that the student_id Seneca_name is rchan.The script should accept two one command line argumentsargument, the first one is the date argument can be either in "YYYYMMDD", "YYYY/MM/DD", "YYYY-MM-DD" format, and the second one is the number of day from the given date, a positive value indicates the number of days after the given date, and a negative value indicates the number of days before the given date. There is an optional flag called --step which can be provided at the command line that makes the program print out all dates until the target date. If the or "YYYY-.MM-.DD" format is broken. 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 01-01-2019 022020-0110-201910</code></b>, and the output should be<br /> 1Oct 10, 2020* <b><code>python3 a1_rchan.py 012020-0110-2019 31-12-201809</code></b>, and the output should be<br /> -1Oct 9, 2020* <b><code>python3 a1_rchan.py 012020-06-30</code></b>, and the output should be<br /> Jun 30, 2020* <b><code>python3 a1_rchan.py 20201010</code></b>, and since today is June 3the output should be<br /> Oct 10, 2020* <b><code>python3 a1_rchan.py 2020/10/10</code></b>, and the output should be<br /> 2 Oct 10, 2020* <b><code>python3 a1_rchan.py 01-01-2019 01-01-2020.02.29</code></b>, and the output should be<br /> 365Feb 29, 2020* <b><code>python3 a1_rchan.py 01-01-2021 01-01-2020 2019.02.28</code></b>, and the output should be<br /> -366Error 03: wrong day entered* <b><code>python3 a1_rchan.py 01-2019.13-2018.12</code></b>, and the output should be<br /> Error02: wrong month entered* <b><code>python3 a1_rchan.py 99-01-2020 01-01-20202019.06.31</code></b>, and the output should be<br /> Error03: wrong day entered* <b><code>python3 a1_rchan.py 2018 2201802</code></b>, and the output should be<br /> Error09: 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 data entered 
If there is too few or too many command line arguments argument given, display the proper usage:* <code>Usage: a1_rchan.py YYYYMMDD|YYYY/MM/DD|YYYY-MM-DD|YYYY [.MM.DD-MM-YYYY] ></code>
== Script structure and sample template ==
The following is a brief description of each function:
 
* The dbda() function should be the main function of your script. The dbda() function will take two dates in "DD-MM-YYYY" format, and return an integer that corresponds to the number of days between the given dates. If the start date is earlier than the stop date, the number is positive. If start date is later than the stop date, the number is negative. Your dbda() function should delegate the actual calculation of the target date to either the after() function or the before() function.
* The today() function will be called if the user has not specified a second argument. It will return '''your Linux computer's local time''' in the format DD-MM-YYYY. Hint: you may need to read man pages for a shell command in order to return a usable date. You may also use string formatting to modify output.
* The before() function will take a date in "DD-MM-YYYY" format and return the date of the previous day in the same format.
* The after() function will take a date in "DD-MM-YYYY" format and return the date of the next day in the same format. Next paragraph is a sample python code for the after() function. To earn the maximum possible mark for the assignment, you should modify the sample after() function to make use of the days_in_mon() 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 valid_daterange_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 date integer range. If the integer object falls in "DD-MM-YYYY" formatbetween the range given in the tuple, and return 'True if the given date is a valid date', otherwise return 'False plus an appropriate status message'. * The valid_datesanitize() function should make use of will take two string objects, the first string object is the object to be sanitized, and the days_in_mon() 2nd string object contains letters that are allowed. This functionwill return the first object with letters not in the 2nd string object removed.* The days_in_monsize_check() function will take a year in "YYYY" format, an collection data type object and expected number of items as an integer and will return a dictionary object which contains either 'True' or 'False'. If the total number of days items in each month for the data object match the integer value given year. The days_in_mon() function should make use of the leap_year() function., return 'True', otherwise return 'False'
* The usage() function will take no argument and return a string describing the usage of the script.
 
=== Sample code for the after() function ===
<pre>
# Return the date in DD-MM-YYYY after the given day
#
def after(today):
if len(today) != 10:
return '00-00-0000'
else:
str_day, str_month, str_year = today.split('-')
year = int(str_year)
month = int(str_month)
day = int(str_day)
 
lyear = year % 4
if lyear == 0:
feb_max = 29 # this is a leap year
else:
feb_max = 28 # this is not a leap year
 
lyear = year % 100
if lyear == 0:
feb_max = 28 # this is not a leap year
 
lyear = year % 400
if lyear == 0:
feb_max = 29 # this is a leap year
 
tmp_day = day + 1 # next day
 
mon_max = { 1:31, 2:feb_max, 3:31, 4:30, 5:31, 6:30, 7:31, 8:31, 9:30, 10:31, 11:30, 12:31}
if tmp_day > mon_max[month]:
to_day = tmp_day % mon_max[month] # if tmp_day > this month's max, reset to 1
tmp_month = month + 1
else:
to_day = tmp_day
tmp_month = month + 0
 
if tmp_month > 12:
to_month = 1
year = year + 1
else:
to_month = tmp_month + 0
 
next_date = str(to_day)+"-"+str(to_month).zfill(2)+"-"+str(year).zfill(2)
return next_date
</pre>
= Rubric =
| Check script passed || 30 ||
|-
| todaysize_check() function design || 2 4 ||
|-
| beforesanitize() function design || 5 4 ||
|-
| dbdaleap_year() function design || 10 4 ||
|-
| script level docstring range_check() function design || 5 4 ||
|-
| leap_yearusage() function design || 2 4 ||
|-
| valid_date() function design script level docstring || 5 ||
|-
| usage() function design level docstring || 1 5 ||
|-
| First Milestone Checkpoint ||10||
|-
| Reflection Essay Second Checkpoint || 10 ||
|-
| github.com repository: Commit messages and use ||15||
1,760
edits

Navigation menu