Open main menu

CDOT Wiki β

OPS435 Online Assignment 2P

Revision as of 20:12, 6 December 2020 by Rchan (talk | contribs) (Overview)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

[Category:OPS435-Python]]

Assignment 2 P - Create new data object

Weight: 15% of the overall grade

What you need

  • A github account with a private repository named ops435-a2p
  • Complete Lab 7
  • Has access to matrix.senecacollege.ca

Due Date: Please follow the three stages of submission schedule:

  • Check point 1: complete the detail algorithm for each task in this assignment by November 25, 2020. Name it as a2p_algorithm.txt and upload it to your github repository
  • Check point 2: complete the coding of your python class file from the algorithm by Dec 2, 2020. Name it as a2p_[Seneca_name].py (replace [Seneca_name] with your Seneca email user name) and upload it to your github repo by Dec 2, 2020.
  • Check point 3: complete the testing and debugging of your python class file by Dec 4, and also submit your algorithm file (a2p_algorithm.txt), test results, and the python class file (a2p_[Seneca_name].py) to Blackboard.

Late Penalty: 20% per school day, and note that in order to pass this course, this assignment must be completed satisfactorily, i.e. a grade of 50% or more.

Overview

You want to design an algorithm to compute the date which is n day before or after a given date. You also want to implemented your algorithm using a Python class to create a new programmer-define object called "Date" with the appropriate data attributes and function attributes to support the necessary manipulation of a date object needed to implement your algorithm.

Your python script must follow the following coding guide:

Class Requirements

Programmer-defined object type: Date

  • Data Attributes: year, month, and day as integer
  • Method attributes: tomorrow(), yesterday(), day_of_week()
  • Operator Overloading:
    • '+': perform addition for one date object and an integer.
    • '-': perform subsraction for two Date() object, and one date object and an integer
  • Special methods:
    • __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

Your python script is allowed to import only the os and sys modules from the standard library and all the built-in functions.

Documentation

  • Please use python's docstring to document your new python class, class functions and external functions. The docstring should describe 'what' the class is for, what does each class function do, what each data attribute is for.

Authorship Declaration

Your Python code for the Date class and its associated functions must be placed in a single source python file. Please include the following declaration as part of the docstring in your Python source code file (replace "Student Name" with your own name):

OPS435 Assignment 2P - Fall 2020
Program: a1_[student_id].py (replace student_id with your Seneca User name)
Author: "Student Name"
The python code in this file (a1_[Student_id].py) is original work written by
"Student Name". No code in this file is copied from any other source 
except those provided by the course instructor, including any person, 
textbook, or on-line resource. I have not shared this python script 
with anyone or anything except for submission for grading.  
I understand that the Academic Honesty Policy will be enforced and 
violators will be reported and appropriate action will be taken.

Tests and Test results

You must name your class definition python script for Date as a2_class.py. The following tests in an interactive python sessions are for testing your class definition. The assignment test script called "checkA2P.py" should be used once your Date class passes 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:
[raymond.chan@mtrx-node04pd a2p]$ python3
Python 3.6.8 (default, May  2 2019, 20:40:44) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from a2_class import *
>>> dir()
['Date', '__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'daysb4month', 'int_to_date']
>>> d1 = Date(2019,11,6)
>>> d1.tomorrow()
2019-11-07
>>> d1.yesterday()
2019-11-05
>>> print(d1.tomorrow())
2019/11/07
>>> print(d1.yesterday())
2019/11/05
>>> d2 = Date(2019,2,28)
>>> d2.tomorrow()
2019-03-01
>>> d2.yesterday()
2019-02-27
>>> d3 = Date(2016,2,28)
>>> d3.tomorrow()
2016-02-29
>>> d3.yesterday()
2016-02-27
>>> d4 = Date(2018,12,31)
>>> d4.tomorrow()
2019-01-01

Test for operator overloading '+' and '-'

>>> d1
2019-11-07

>>> d2
2019-11-14

>>> d1 - d2
-7

>>> d2 - d1
7

>>> d2 = Date(2019,2,28)
>>> d2
2019-02-28

>>> d2 + 1
2019-03-01

>>> d2 + 2
2019-03-02

>>> d3
2016-02-28

>>> d3 + 1
2016-02-29

>>> (d3 + 1) - 1
2016-02-28

>>> d3 - 1
2016-02-27

>>> d4
2018-12-31

>>> d4 + 365
2019-12-31

>>> d4 - 365
2017-12-31

Test for day of the week method

The day of week on Jan 1, 1970 is Thursday. The date.day_of_week() method should return the day of week for the give date in numeric form.
0 - Sun,
1 - Mon,
2 - Tue,
3 - Wed,
4 - Thu,
5 - Friday, and
6 - Saturday
>>> d1 = Date(2019,11,7)
>>> d1
2019-11-07
>>> d1.day_of_week()
4
>>> d2 = d1 + 7
>>> d2
2019-11-14
>>> d2.day_of_week()
4
>>>

Deliverable

Create a private repository on github.com under your account

  • name the repository as 'ops435-a2p
  • invite 'rayfreeping' as one of the collaborator to your 'ops435-a2p' repository
  • use this repository for developing the and keeping track of the following text/source code files:
    • The readme.md file to show your progress. Add entry whenever you update any files in this repository.
    • the python class definition named "a2_class.py"
    • the test results produce by the assignment checking script "checkA2P.py". Name it as a2p_results.txt

Rubric

Task Maximum mark Actual mark
Program Authorship Declaration 5
class block 5
__init__() method 5
__str__() method 5
__repr() method 5
'+' operator 10
'-' operator 10
tomorrow() method 10
yesterday() method 10
day_of_week() function 5
docstring 15
github.com repository 15
Total 100

Due Date and Final Submission requirement

Please submit the following files to blackboard by the due date:

  • your python class file, name the file as 'a2p_[Seneca_name].py' (was named as a2_class.py above)
  • the output of the checking script checkA2P.py, name the file as 'a2p_results.txt'
  • the 'git log' output for your own repository 'ops435-a2p' on github.com, name the file as 'a2p_gitlog.txt'