Changes

Jump to: navigation, search

OPS435 Python3 Assignment 2P

4,852 bytes removed, 19:02, 11 November 2019
Programmer-defined object type: Date
[[Category:OPS435-Python]][[Category:rchan]]
= Overview =
When making back up of data files or log files, it is a very common practice You have successfully designed an algorithm to name compute the backup directories and/date which is '''n''' day before or files based on the after a given date . You have also successfully implemented your algorithm using the backup was done. In order to restore or locate Python language by identifying the directory/file, we often need functions that are needed to find out perform the backup date from today's datecomputation.
The computational task for In this assignment is , you are going to design an re-implement the algorithm and write a you have for assignment 1 using python script according class. You are going to your algorithm create a new programmer-define object called Date with the appropriate functions. The script should take a date in the "YYYY/MM/DD" format data attributes and function attributes to support the number necessary manipulation of days before or after the given '''date as the command line arguments, calculate and output ''' object needed to the standard output data channel the targeted date which is the number of day before or after the given date in the same formatimplement your algorithm for assignment 1.
== Coding Standard ==
Your python script must follow the following coding guide:
* [https://www.python.org/dev/peps/pep-0008/ PEP-8 -- Style Guide for writing Python Code]
== Command Line Argument to be supported ==
* Name your python script as a1_[student_id].py, where [student_id] is your Seneca email user name.
* Your python script must support two mandatory command line arguments : (1) any valid date in YYYY/MM/DD format, (2) number of days before or after the given date, and one option flag: "--step"
* If there are less or more than two data items provided at the command line, your script should display the correct usage message and exit.
= Class Requirements =
** __init__(self): Date object constructor
** __repr__(self): return date object as a string in "yyyy-mm-dd" format
** __str__(self): return date object as a string in "yyyy:/mm:/dd" format
* Supporting function:
** days_to_time(): convert an integer which is n days from epoch (Jan 1, 1970) to a corresponding date object.
== Required Modules and Functions ==
<b><font color='blue'>Your python script is allowed to import only the <u>os 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 three methods defined in your class file for Date (see later section on the purpose of each function) in order to get a passing grade for this assignment:
* tomorrow()
* yesterday()
* sum_date()
* diff_date()
 
You can also create additional functions to improved the re-usability of your python code by adding the following functions to earn the maximum possible mark for this assignment:
* days_in_mon()
* leap_year()
* valid_date()
* usage()
== Documentation ==
* Please use python's docstring to document your new python script (script level documentation) class, class functions and each of the external functions (function level documentation) you created for this assignment. The docstring should describe 'what' the class is for, what does each class function doesdo, not 'how' it doeswhat each data attribute is for.* The following shows the docstring that was added to the after() function which provides the following information when called with help(after) in the python interactive shell: 
== Authorship Declaration ==
All your Your Python code for this assignment the Date class and its associated functions must be placed in a <font color='red'><b><u>single source python file</u></b></font>. Please include the following declaration <b><u>as part of the docstring</u></b> in your Python source code file (replace "Student Name" with your own name):
<source>OPS435 Assignment 2P - Fall 2019
Program: a1_[student_id].py (replace student_id with your Seneca User name)
== Tests and Test results ==
You must name your class definition python script for Date as <code>a2_class.py</code>. The following test scripts tests in an interactive python sessions are for testing your class definition. The assignment test scripts can script called "checkA2P.py" should be used to test the date objects created by using once your Date classpasses all the interactive tests.
Please review those tests that failed and try to fix it in your class definition to address any bugs you may have.
 
=== Test for tomorrow and yesterday methods ===
: Start up an interactive Python session and issue the following python statments:<source lang="python">
2019-01-01
</source>
 
 
=== Test for operator overloading '+' and '-' ===
: <source lang="python">
>>> d1
2019-11-07
=== Test for day of the week method ===>>> d22019-11-14
== Script structure and sample template ==>>> d1 - d2Your code should all be in a single python file with at least the functions mentioned above: dbda(), after(), and before(). To earn the maximum mark, you should also create additional functions into your algorithm, e.g.: leap_year(), days_in_mon, valid_date(), usage(), etc-7
The following is a brief description of each function:>>> d2 - d17
* The dbda>>> d2 = Date() function should be the main function of your script. The dbda() function will take a date in "YYYY/MM/DD" format2019, a positive or negative integer2, and return a date either before or after the given date according to the value of the given integer in the same format. Your dbda() function should delegate the actual calculation of the target date to either the after() function or the before(28) function. * The before() function will take a date in "YYYY/MM/DD" format and return the date of the previous day in the same format.* The after() function will take a date in "YYYY/MM/DD" 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_date() function will take a date in "YYYY/MM/DD" format, and return True if the given date is a valid date, otherwise return False plus an appropriate status message. The valid_date() function should make use of the days_in_mon() function.* The days_in_mon() function will take a year in "YYYY" format, and return a dictionary object which contains the total number of days in each month for the given year. The days_in_mon() function should make use of the leap_year() function.* The usage() function will take no argument and return a string describing the usage of the script.<pre>>> d2 #!/usr/sbin/env python3 ''' docstring ''' import ...2019-02-28
def after(today):>>> d2 + 1 .... return next_day2019-03-01
def before(today):>>> d2 + 2 .... return previous_day2019-03-02
....>>> d32016-02-28
def dbda(date,days):>>> d3 + 1 ... setup loop: call after() or before() as appropriate return target_day2016-02-29
if __name__ == "__main__":>>> (d3 + 1) - 12016-02-28
.. processing command line arguments ..>>> d3 - 1 .. call dbda() ... .. output the result2016-02-27
</pre> >> d4 2018-12-31
=== Sample code for the after() function ===<pre>>> d4 + 365# Return the date in YYYY/MM/DD after the given day# def after(today): if len(today) != 10: return '0000/00/00' else: str_year, str_month, str_day = today.split('/') year = int(str_year) month = int(str_month) day = int(str_day)2019-12-31
lyear = year % 4>>> d4 - 365 if lyear == 0:2017-12-31 feb_max = 29 # this is a leap year else: feb_max = 28 # this is not a leap year</source>
lyear = year % 100 if lyear == 0: feb_max Test for day of the week method == 28 # this is not a leap year  lyear = year % 400 if lyear == 0: feb_max = 29 # this is a leap year  tmp_day = The day + of week on Jan 1 # next , 1970 is Thursday. The date.day_of_week() method should return the dayof week for the give date in numeric form.  mon_max = { 1:31: 0 - Sun, 2:feb_max, 3:311 - Mon, 4:30, 5:312 - Tue, 6:30, 7:313 - Wed, 8:31, 9:304 - Thu, 10:31, 11:305 - Friday, 12and:31} if tmp_day > mon_max[month]: to_day 6 - Saturday <source lang= tmp_day % mon_max[month] # if tmp_day "python"> this month's max, reset to 1 tmp_month >>> d1 = month + 1Date(2019,11,7) else:>>> d1 to_day = tmp_day2019-11-07 tmp_month = month + 0>>> d1.day_of_week()4 if tmp_month > 12: to_month = 1 year >> d2 = year d1 + 17 else:>>> d2 to_month = tmp_month + 02019-11-14  next_date = str(year)+"/"+str(to_month)>>> d2.zfillday_of_week(2)+"/"+str(to_day).zfill(2) 4 return next_date>>></presource= Normal task =Your script must be able to take two dates both in "YYYY/MM/DD" format and output the number of days between the given two dates.e.g.* Calculate the number of days between "2018/03/01" and "2019/03/01" python3 a1_rchan.py 2018/03/01 2019/03/01 365* Calculate the number of days between "2019/03/01" and "2018/03/01" python3 a1_rchan.py 2019/03/01 2018/03/01 365
= Deliverable =
== Create a private repository on github.com under your account ==
* name the repository as 'ops435-a1'a2p* invite 'rayfreeping' as one of the collaborator to your 'ops435-a1a2p' repository
* use this repository for developing the and keeping track of the following text/source code files:
** the algorithm for assignment 1 named "a1_algorithmThe readme.md file to show your progress. Add entry whenever you update any files in this repository.txt"** the python script for assignment 1 class definition named "a1_[seneca-id]a2_class.py"** the test results produce by the assignment checking script "checkA1checkA2P.py". Name it as a1_resultsa2p_results.txt
= Rubric =
| Program Authorship Declaration ||5 ||
|-
| Program usage || 5 |||-| Program Options --step class block || 5 ||
|-
| after__init__() function method || 5 ||
|-
| before__str__() function method || 15 5 ||
|-
| dbda__repr() function method || 10 5 ||
|-
| script level docstring '+' operator || 5 10 ||
|-
| leap_year() function '-' operator || 5 10 ||
|-
| valid_datetomorrow() function method || 5 10 ||
|-
| days_in_monyesterday() function method || 5 10 ||
|-
| usageday_of_week() function || 5 ||
|-
| Algorithm docstring ||15||
|-
| github.com repository||15||
Please submit the following files to blackboard by the due date:
* your algorithm (step-by-step instruction for solving the computation problem for this assignment in the English language), name the file as 'a1_algorithm.txt'* your python script, name the file as 'a1_[seneca-id]a2_class.py'* the output of the checking script checkA1checkA2P.py, name the file as 'a1_resultsa2p_results.txt'* the 'git log' output for your own repository 'ops435-a1a2p' on github.com, name the file as 'a1_gitloga2p_gitlog.txt'
1,760
edits

Navigation menu