Changes

Jump to: navigation, search

OPS435 Python Assignment 2

2,170 bytes added, 15:59, 14 March 2019
Bonus item 10% extra
asmith pts/11 10.40.105.130 Tue Feb 13 14:07:43 2018 - Tue Feb 13 16:07:43 2018 (02:00)
</pre>
It is always desirable to have a daily, weekly, monthly usage reports by user or by remote host based on the above information.
== Tasks for this assignment ==In this assignment, your duty is to should preform the following activities:# work Work out an algorithm for producing daily, weekly, and monthly usage reports by user or by remote host based on the information obtained from the 'last' command or any given files which contain similar information as the 'last' command. # Once you believe you have a workable algorithm, you should then identify <b>design the structure of your python script</b> by identifying the different tasks appropriate python objects and functions to be used for each task in your algorithm and any repeated sub-the main control logic. Make sure to identify all the input data, computation tasks,and outputs.# implement your computational solution using a single python script with the proper . You can use of any built-in functions, and finallyfunctions from the allowed python modules to implement your solution.# review your working python code to see whether you can improve the interface of each function and to facilitate better core code re-use (this process is called <b>refactoring</b>).
== Allowed Python Modules you can use in your script for this assignment ==
* the <b>os, sys</b> modules
* the <b>argparse</b> module
=== Program Name and valid command line arguments ===
Name your Python3 script as <code>ur_[student_id].py</code>. Create a symbolic link to your script as ur.py (e.g. use the command ln -s ur_rchan.py ur.py to create the linelink) so that you can refer to your script as ur.py. Your script must accept one or more "file name" as its command line parameters and other optional parameters as shown below. Your python script should produce the following usage text when run with the --help option:
<pre>
[rchan@centos7 a1]$ python3 ./ur.py -h
-v, --verbose tune on output verbosity
Copyright 2018 2019 - Raymond Chan
</pre>
Replace the last line with your own full name
=== Header ===
All your Python codes for this program must be placed in a <font color='red'><b><u>single source file</u></b></font>. Please include the following declaration by <b><u>you</u></b> as the <font color='blue'><b>script level docstring </b></font> in your Python source code file (replace [Student_id] with your Seneca email user name, and "Student Name" with your own name):
<source>OPS435 Assignment 2 - Fall 2018Winter 2019
Program: ur_[Stduent_id].py
Author: "Student Name"
=== Sample outputs ===
The following are the reports generated by the usage report script (ur.py) with the "usage_data_file" mentioned in the overview section.You can download the file [https://scs.senecac.on.ca/~raymond.chan/ops435/a2/usage_data_file here] for testing your ur.py script.==== User List ====The following is the user list extracted from the usage_data_file created by the command:<pre>[rchan@centos7 a2]$ ./ur.py -l user usage_data_file</pre> <pre>User list for usage_data_file=============================asmithbigiacwsmithhfangmlee18mshanarchantsliu2</pre>
==== Remote Host List ====
The following is the remote host list extracted from the usage_file_file created by the command:
<pre>
[rchan@centos7 a2]$ ./ur.py -l host usage_data_file
</pre>
 
<pre>
Host list for usage_data_file
=============================
10.40.105.130
10.40.43.94
10.40.91.236
10.40.91.247
10.43.115.162
24.114.50.50
</pre>
==== Daily Usage Report by User ====
The following is a Daily Usage Report create created for user rchan by the following command:
<pre>
[rchan@centos7 a1-summera2]$ ./ur.py -u rchan -t daily usage_data_file
</pre>
==== Daily Usage Report by Remote Host====
The following is a sample Daily Usage Report from created for the Remote Host 10.9440.105.103 by the command:<pre>[rchan@centos7 a2]$ ./ur.py -r 10.25 on host40.cty105.senecacollege.ca:130 -t daily usage_data_file</pre>
<pre>
Daily Usage Report from for 10.9440.10105.25 130====================================Date Usage in seconds2018 02 14 30Seconds2018 02 07 412018 02 01 913 7969Total 80 7969
</pre>
==== Weekly Usage Report by User ====
The following is a sample Weekly Usage Report created for user1 on hostuser rchan by the command:<pre>[rchan@centos7 a2]$ .cty/ur.senecacollege.ca:py -u rchan -t weekly usage_data_file</pre>
<pre>
Weekly Usage Report for user1rchan
=============================
Week # Usage in Seconds
2017 01 1602018 07 15802017 02 452017 03 52017 04 Total 20 Total 2201580
</pre>
==== Weekly Usage Report by Remote Host ====
The following is a sample Weekly Usage Report from created for the remote host 10.9440.105.130 by the command:<pre>[rchan@centos7 a2]$ ./ur.py -r 10.25 on host.cty40.senecacollege105.ca:130 -t weekly usage_data_file</pre>
<pre>
Weekly Usage Report from for 10.9440.10105.25130=====================================
Week # Usage in Seconds
2017 01 302018 07 79692017 03 Total 4179692017 05 92017 06 11</pre>
Total 91==== Monthly Usage Report by User ====The following is a Monthly Usage Report created for user rchan by the command:<pre>[rchan@centos7 a2-2018fall]$ ./ur.py -u rchan -t monthly usage_data_file
</pre>
==== Monthly Usage Report by User ====
The following is a sample Monthly Usage Report for user1 on host.cty.senecacollege.ca:
<pre>
Monthly Usage Report for user1rchan
==============================
Month Usage in Seconds
2017 01 1602017 2018 02 45 1580Total 205 1580
</pre>
==== Monthly Usage Report by Remote Host ====
The following is a sample Monthly Usage Report created for remote host 10.9440.105.130 by the command:<pre>[rchan@centos7 a2-2018fall]$ ./ur.py -r 10.25 on host.cty40.senecacollege105.ca:130 -t monthly usage_data_file</pre>
<pre>
Monthly Usage Report from for 10.9440.10105.25130======================================
Month Usage in Seconds
2017 01 302017 2018 02 41 7969Total 71 7969
</pre>
== Suggested Script Development and Testing ==
The following python functions (to be created) are useful in handling the following sub-tasks:
* gets login records from the output of "last" command and filters out unwanted records
* reads login records from files and filters out unwanted records
* generate convert login records into proper python object type so that it can be processed using as much built-in functions as possible * create function which generates daily usage reports by user and/or by remote host* generate create function which generates weekly usage reports by user and/or by remote host* generate create function which generates monthly usage reports by user and/or by remote hostTo help you with this assignment, [[OPS435 A1 Usage Report Template|here is a template]] you can use as a starting point in developing designing your own Python Usage Report script. For each function, identify what type of objects should be passed to the function, and what type of objects should be returned to the caller.
Once you have finished coding a function, you should start a Python3 interactive shell, import your functions and manually call the function you want to test under interactive modeand verify its correctness.
Once you have all the individual function tested and that each is working properly, perform the final test with test data provided by your professor and verify that your script produces the correct results before submitting your python program on Blackboard.
== Sample login /logout records file and sample test run results==* [https://scs.senecac.on.ca/~raymond.chan/ops435/a1a2/ Sample test date data files and sample runstest run results]
== Rubric ==
! Task !! Maximum mark !! Actual mark
|-
| Program Authorship Declaration Algorithm and program design||1 15 ||
|-
| Program usage Authorship Declaration || 2 5 ||
|-
| Program Options usage || 2 5 ||
|-
| Daily Usage Report by User Program Options || 2 15 ||
|-
| Daily Usage Report by Remote Host Generate user name list || 2 10 ||
|-
| Weekly Usage Report by User Generate remote host IP list|| 2 10 ||
|-
| Weekly Daily Usage Report by Remote Host User || 2 10 ||
|-
| Monthly Daily Usage Report by User Remote Host || 2 10 ||
|-
| Monthly Weekly Usage Report by Remote Host User || 2 5 ||
|-
| Get Login Records from 'last' Weekly Usage Report by Remote Host || 2 5 ||
|-
| Get Login Records from files Monthly Usage Report by User || 2 5 ||
|-
| Generate user name list Monthly Usage Report by Remote Host || 2 5 ||
|-
| Generate remote host IP list|| 2 || |-| '''Total''' || 25 100 ||
|}
== Bonus item 10% extra ==
* Create a function to capture that output of the 'last -Fiw' on the system your script is being executed and return the contents in the type of object as what you get from a regular login/logout record file.
* Call this function and use the objects it returned when the file name input at the command line is 'last'.
== Submission ==
After fully testing your program, submit your python file script ur_[student_id].py and your algorithm and program design report ur_[student_id].pdf in pdf format on Blackboardby April 5th, 2019.
1,760
edits

Navigation menu