Difference between revisions of "OPS445 Online Assignment 1"
Eric.brauer (talk | contribs) (changes for fall2021) |
Eric.brauer (talk | contribs) (→Command Line Argument to be supported) |
||
Line 52: | Line 52: | ||
=== Command Line Argument to be supported === | === Command Line Argument to be supported === | ||
− | * You will provided with a file called | + | * You will provided with a file called assign1.py. |
− | * | + | * Be sure that this python script has your name and student_id set inside the docstring. |
− | * Your python script must support one or two command line arguments only: | + | * Your python script must support one or two command line arguments only: the first should be a valid date in DD-MM-YYYY format and the second an integer (negative or positive). |
* If there are no arguments, more than two arguments, or an invalid date, your script should display the correct usage message and exit. | * If there are no arguments, more than two arguments, or an invalid date, your script should display the correct usage message and exit. | ||
Revision as of 21:09, 29 September 2021
Contents
Overview
When making back up of data files or log files, it is a very common practice to name the backup directories and/or files based on the date the backup was done. In order to restore or locate the directory/file, we often need to find out the backup date from today's date.
The computational task for this assignment is to design an algorithm and write a python script according to your algorithm with appropriate functions. The script should take a date in the "DD-MM-YYYY" format as well as a number of days, and return the date when that number of days is applied to the date. That is, if the user enters "18-06-2020" and "7", the script will return "25-06-2020". Similarly, if the number is a negative number, the script will return a date in the past.
Assignment Requirements
GitHub Repository
- Your professor will either provide you with a starting repository, or you will be required to create one. If you are asked to create a repository, you will be required to add your professor as an admin user for that repository. **All repositories must be set to private during the initial phase of creation.**
- Each significant change to your code should have its own commit. This is the standard that most companies will adhere to: version control commits are used to document proof of work, and commit messages are invaluable when issues are being debugged.
- When making a change to your code, use the following commands to document the commit:
git commit -am "a sensible message"
andgit push
. **Please explain the change you made in your commit message.**
The First Milestone
- Before you begin programming, 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 works. The "after()" function is provided to you in the assign1.py template. Open the file, and use clear English to describe what line of code does in such a way that a competent programmer could reproduce the code without seeing it firsthand. * You will then apply the same principles to create an algorithm for "before()", and "dbda()".
- This file will be submitted to Blackboard a week after the assignment goes live, and should be your first priority. The object of the milestone is not to have a 100% perfect algorithm, but to plan ahead and anticipate challenges and issues with the assignment. The milestone will also give your professor an opportunity for feedback.
- 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 to find out when we started using the Calendar in the current form. (This will pose a limit on the validity of your algorithm.)
The Second Milestone
For the second milestone, you will be asked to have committed the following functions inside the assign1.py file inside your repository:
- before()
- leap_year()
- valid_date()
It's not necessary to submit these functions to Blackboard. If you have pushed the commits correctly, the changes will be visible to your professor.
The Assignment
- As stated before, your code will be inside the file "assign1.py". The first step will be to clone (or create) the Assignment 1 repository. Further instructions will be provided by your professor. Additional requirements are outlined below.
Assignment Requirements
Required Modules and Functions
Your python script is allowed to import only the os, subprocess and sys modules from the standard library and all the built-in functions.
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()
You should 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()
Coding Standard
Your python script must follow the following coding guide:
Command Line Argument to be supported
- You will provided with a file called assign1.py.
- Be sure that this python script has your name and student_id set inside the docstring.
- Your python script must support one or two command line arguments only: the first should be a valid date in DD-MM-YYYY format and the second an integer (negative or positive).
- If there are no arguments, more than two arguments, or an invalid date, your script should display the correct usage message and exit.
Documentation
- Please use python's docstring to document your python script (script level documentation) and 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
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 of your Github commits. Professionals generally follow these guidelines:
- commit their code after every significant change,
- the code should run without errors after each commit, and
- every commit has a descriptive commit message.
These guidelines are not always possible, but you will be 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 life easier!
Tests and Test results
You must name your python 3 script as a1_[Student_id].py
. The following examples assumes that the student_id is rchan.The script should accept two command line arguments, the first one is the date in "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 "YYYY-MM-DD" format is broken, your script should give an appropriate error message. Invalid months (>12) or invalid days of month(different for each month), should be detected and give appropriate error messages. For examples:
-
python3 a1_rchan.py 01-01-2019 02-01-2019
, and the output should be
1
-
python3 a1_rchan.py 01-01-2019 31-12-2018
, and the output should be
-1
-
python3 a1_rchan.py 01-06-2020
, and since today is June 3, the output should be
2
-
python3 a1_rchan.py 01-01-2019 01-01-2020
, and the output should be
365
-
python3 a1_rchan.py 01-01-2021 01-01-2020
, and the output should be
-366
-
python3 a1_rchan.py 01-13-2018
, and the output should be
Error: wrong month entered
-
python3 a1_rchan.py 99-01-2020 01-01-2020
, and the output should be
Error: wrong day entered
-
python3 a1_rchan.py 2018 2
, and the output should be
Error: wrong date entered
If there is too few or too many command line arguments given, display the proper usage:
-
Usage: a1_rchan.py DD-MM-YYYY [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 a date in "YYYY-MM-DD" format, a positive or negative integer, 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() 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 "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.
Sample code for the after() function
# 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) 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(year)+"-"+str(to_month).zfill(2)+"-"+str(to_day).zfill(2) return next_date
Rubric
Task | Maximum mark | Actual mark |
---|---|---|
Program Authorship Declaration | 5 | |
Program usage | 5 | |
Program Options --step | 5 | |
after() function | 5 | |
before() function | 15 | |
dbda() function | 10 | |
script level docstring | 5 | |
leap_year() function | 5 | |
valid_date() function | 5 | |
days_in_mon() function | 5 | |
usage() function | 5 | |
Algorithm | 15 | |
github.com repository | 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_username.txt', to Blackboard.
- [ ] your python script, named as 'a1_[seneca-id].py', should be included in your repository, and also submitted to Blackboard.
- [ ] the output of the checking script checkA1.py, named as 'a1_results.txt', should be included in your repository.
- [ ] your debrief document should be submitted to Blackboard.