Changes

Jump to: navigation, search

OPS445 Online Assignment 1

103 bytes added, 09:14, 28 September 2022
m
Command Line Argument to be supported
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 two dates a date in the "DD-MM-YYYY" format as well as a number of days, and return the date when that number of days from the first is applied to the second date. That is, if the user enters "18-06-2020" and "25-06-20207", the script will return "725-06-2020". Similarly, if the target date number is in the pasta negative number, the script will return a negative numberdate in the past.
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 date. = Assignment Requirements =
= 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: <code>git commit -am "a sensible message"</code> and <code>git push</code>. **Please explain the change you made in your commit message.** == Required Files ==<!--<b>NOTE: It's necessary to download these files if you are cloning a repository provided by your professor!</b>-->There are two files that we are providing to you within the assignment repository [clone it to get these files]:* <!--[https://ict.senecacollege.ca/~eric.brauer/ops445/a1/assign1.py assign1.py]--> '''assign1.py''' - contains starter code for your assignment. You should commit all of your code to this file.* <!--[https://ict.senecacollege.ca/~eric.brauer/ops445/a1/checkA1.py checkA1.py]--> '''CheckA1.py''' - is a check script that will help you evaluate your assignment. For full marks, your assignment should pass all checks. == The First Milestone - BB only!!! (Due Oct 07) ==* 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]algorithm_youruserid.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 a1_templatethe assign1.pytemplate. 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()". 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 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.
* [https://simple.m.wikipedia.org/wiki/Algorithm Here is an a basic introduction to Algorithm]* While you are working on the step-by-step instructions, note that there are different number numbers 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 Assignment Second Milestone (Due Oct 21) ==* As stated beforeFor the second milestone, your code you will be asked to have committed the following functions inside the file "a1_[studentid]assign1.py"file inside your repository:* before()* leap_year()* valid_date() It's not necessary to submit these functions to Blackboard. The first step will be to clone If you have pushed the commits correctly, the Assignment 1 repository. The invite link changes will be provided visible to you by your professor. Once you clone the repository, you will rename "a1_template.py" and begin writing the content that is required. Additional requirements are outlined below.
== The Debrief Assignment (Due Nov 4) ==This document, like the algorithm document* As stated before, your code will be submitted to Blackboard one week after inside the assignmentfile "assign1.py". Answer the following questions:* Research Python modules that you could have used The first step will be to accomplish the same goals as the todayclone (or create) and leap_year() functionsthe Assignment 1 repository. * Which solution is preferable, in terms of performance? Which solution is preferable, in terms of programmer hours? (which solution would take longer for a programmer to implement?)* Which approach would Further instructions will be preferable in the "real world"? Why is it useful to try creating our own algorithm?* What challenges did you encounter during the assignment, and what resources did you use to solve your issues? (help from classmates, help from Stackoverflow, debuggers, etc.)* Additionally, provided by your professor may have questions specific to your submission. You should answer these questions as wellAdditional requirements are outlined below.
== Assignment Requirements ==
=== Required Modules and Functions ===
<b><font color='blue'>Your python script is allowed to import only the <u>os, subprocess and sys</u> modules module from the standard library , and all the built-in functionsonly to handle command line arguments.</font></b>
Based on the algorithm you have designed for this assignment, you should at least have the following four three 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 should also create additional functions to improved improve 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()
=== Command Line Argument to be supported ===
* You will are provided with a file called a1_templateassign1.py.* Rename Be sure that this python script as a1_[student_id].py, where [student_id] is has your Seneca email user nameand student_id set inside the docstring.* Your python script must support one or two command -line arguments only: both the first should be a valid dates date in DD-MM-YYYY formatand 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.
=== Authorship Declaration ===
All your Python code for this assignment must be placed in a <font color='red'><b><u>single source python file</u></b></font>. Please complete the declaration <b><u>as part of the docstring</u></b> in your Python source code file (replace "Student Name" and "Student ID" with your own nameand student id respectively).
=== Github Commits ===
== Tests and Test results ==
You must name your python 3 script as <code>a1_[Student_id]assign1.py</code>. 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 "YYYYDD-MM-DDYYYY" 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 "YYYYDD-MM-DDYYYY" 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 examplesexample:* <b><code>python3 a1_rchanassign1.py 01-01-2019 02-01-20191</code></b>, and the output should be<br /> 102-01-2019* <b><code>python3 a1_rchanassign1.py 01-01-2019 31-12-20181</code></b>, and the output should be<br /> 31-12-12018* <b><code>python3 a1_rchanassign1.py 01-06-2020365</code></b>, and since today is June 3, the output should be<br /> 2 01-06-2021 * <b><code>python3 a1_rchanassign1.py 01-01-2019 01-01-2020365</code></b>, and the output should be<br /> 36501-01-2020* <b><code>python3 a1_rchanassign1.py 01-01-2021 01-01-2020 366 </code></b>, and the output should be<br /> 01-36601-2020* <b><code>python3 a1_rchanassign1.py 01-13-20181</code></b>, and the output should be<br />
Error: wrong month entered
* <b><code>python3 a1_rchanassign1.py 99-01-2020 01-01-20201</code></b>, and the output should be<br />
Error: wrong day entered
* <b><code>python3 a1_rchanassign1.py 2018 2</code></b>, and the output should be<br />
Error: wrong date entered
If there is too few or too many command line arguments given, display the proper usage:
* <code>Usage: a1_rchanassign1.py DD-MM-YYYY [DD-MM-YYYY] >N </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 "YYYYDD-MM-DDYYYY" 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 computerbefore()'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 "YYYYDD-MM-DDYYYY" format and return the date of the previous day in the same format.* The '''after() ''' function will take a date in "YYYYDD-MM-DDYYYY" 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 "YYYYDD-MM-DDYYYY" 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 ===
<pre>
# Return the date in YYYYDD-MM-DD YYYY after the given day
#
def after(today):
if len(today) != 10:
return '000000-00-000000'
else:
str_yearstr_day, str_month, str_day str_year = today.split('-')
year = int(str_year)
month = int(str_month)
to_month = tmp_month + 0
next_date = str(yearto_day).zfill(2)+"-"+str(to_month).zfill(2)+"-"+str(to_dayyear).zfill(2)
return next_date
|-
| Program usage || 5 ||
|-
| Program Options --step || 5 ||
|-
| after() function || 5 ||
|-
| before() function || 15 10 ||
|-
| dbda() function || 10 ||
| valid_date() function || 5 ||
|-
| days_in_mon() function check script results || 5 15 ||
|-
| usage() function First Milestone || 5 10||
|-
| Algorithm Second Milestone ||1510||
|-
| github.com repository||15||
Please submit the following files by the due date:
* [ ] your algorithm document, named as 'algorithm_usernamealgorithm_youruserid.txt', to Blackboard. This is your first milestone.* [ ] your python script, named as 'a1_[seneca-id]assign1.py', should be included in your repository, and also '''submitted to Blackboard.'''* [ ] the output of the checking script checkA1'CheckA1.py-f -v &>', named as 'a1_resultsa1_output.txt', should be included in your repository.* [ ] your debrief document should be submitted to Blackboard.
572
edits

Navigation menu