Difference between revisions of "OPS435 Assignment 2 Summer"

From CDOT Wiki
Jump to: navigation, search
(Assignment 2 - Usage Report)
(Overview)
 
(33 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[Category:OPS435-Python]][[Category:rchan]]
 
[[Category:OPS435-Python]][[Category:rchan]]
 +
 
=Assignment 2 - Usage Report=
 
=Assignment 2 - Usage Report=
 
'''Weight:''' 15% of the overall grade
 
'''Weight:''' 15% of the overall grade
 +
 +
'''What you need''' A github account with a private repository named ops435-a2
  
 
'''Due Date:''' Please follow the four stages of submission schedule:
 
'''Due Date:''' Please follow the four stages of submission schedule:
* Complete the algorithm by July 17, 2019 on github,
+
* Complete the algorithm by July 19, 2019 on github,
* Complete the coding from algorithm to Python script by July 24, 2019 on github
+
* Complete the coding from algorithm to Python script by July 26, 2019 on github
* Complete the testing and debugging by July 31, 2019 on github, and
+
* Complete the testing and debugging by August 2, 2019 on github, and also submit the algorithm file, test results and the python script to blackboard.
* Submit your algorithm, test results and your python script by August 2, 2019 on blackboard.
 
  
 
'''Late Penalty:''' 20% per school day, and note that this assignment must be completed satisfactorily in order to pass the course even if you get zero mark for this assignment.
 
'''Late Penalty:''' 20% per school day, and note that this assignment must be completed satisfactorily in order to pass the course even if you get zero mark for this assignment.
Line 14: Line 16:
 
Most system administrators would like to know the utilization of their systems by their users. On a Linux system, each user's login records are normally stored in the binary file /var/log/wtmp. The login records in this binary file can not be viewed or edited directly using normal Linux text commands like 'less', 'cat', etc. The 'last' command is often used to display the login records stored in this file in a human readable form. Please check the man page of the 'last' command for available options. The following is the contents of the file named "usage_data_file", which is a sample output of the 'last' command with the '-Fiw' flag on:
 
Most system administrators would like to know the utilization of their systems by their users. On a Linux system, each user's login records are normally stored in the binary file /var/log/wtmp. The login records in this binary file can not be viewed or edited directly using normal Linux text commands like 'less', 'cat', etc. The 'last' command is often used to display the login records stored in this file in a human readable form. Please check the man page of the 'last' command for available options. The following is the contents of the file named "usage_data_file", which is a sample output of the 'last' command with the '-Fiw' flag on:
 
<pre>
 
<pre>
$ last -Fiw
+
$ last -Fiw > usage_data_file
 +
$ cat usage_data_file
 
rchan    pts/9        10.40.91.236    Tue Feb 13 16:53:42 2018 - Tue Feb 13 16:57:02 2018  (00:03)     
 
rchan    pts/9        10.40.91.236    Tue Feb 13 16:53:42 2018 - Tue Feb 13 16:57:02 2018  (00:03)     
cwsmith  pts/6        10.40.43.94      Tue Feb 13 16:51:47 2018 - Tue Feb 13 16:56:13 2018  (00:04)   
+
cwsmith  pts/10       10.40.105.130   Wed Feb 14 23:09:12 2018 - Thu Feb 15 02:11:23 2018  (03:02)
mlee18  pts/6        10.40.43.94      Tue Feb 13 16:50:20 2018 - Tue Feb 13 16:51:27 2018  (00:01)   
 
hfang    pts/4        24.114.50.50    Tue Feb 13 16:31:38 2018 - Tue Feb 13 17:48:39 2018  (01:17)    
 
bigia    pts/8        24.114.50.50    Tue Feb 13 19:28:43 2018 - Tue Feb 13 20:28:31 2018  (00:59)  
 
 
rchan    pts/2        10.40.91.236    Tue Feb 13 16:22:00 2018 - Tue Feb 13 16:45:00 2018  (00:23)     
 
rchan    pts/2        10.40.91.236    Tue Feb 13 16:22:00 2018 - Tue Feb 13 16:45:00 2018  (00:23)     
 +
rchan    pts/5        10.40.91.236    Tue Feb 15 16:22:00 2018 - Tue Feb 15 16:55:00 2018  (00:33)   
 
asmith  pts/2        10.43.115.162    Tue Feb 13 16:19:29 2018 - Tue Feb 13 16:22:00 2018  (00:02)     
 
asmith  pts/2        10.43.115.162    Tue Feb 13 16:19:29 2018 - Tue Feb 13 16:22:00 2018  (00:02)     
 
tsliu2  pts/4        10.40.105.130    Tue Feb 13 16:17:21 2018 - Tue Feb 13 16:30:10 2018  (00:12)     
 
tsliu2  pts/4        10.40.105.130    Tue Feb 13 16:17:21 2018 - Tue Feb 13 16:30:10 2018  (00:12)     
mshana  pts/13      10.40.91.247    Tue Feb 13 16:07:52 2018 - Tue Feb 13 16:45:52 2018  (00:38)     
+
cwsmith  pts/13      10.40.91.247    Tue Mar 13 18:08:52 2018 - Tue Mar 13 18:46:52 2018  (00:38)     
asmith  pts/11      10.40.105.130    Tue Feb 13 14:07:43 2018 - Tue Feb 13 16:07:43 2018  (02:00)  
+
asmith  pts/11      10.40.105.130    Tue Feb 13 14:07:43 2018 - Tue Feb 13 16:07:43 2018  (02:00)
 
</pre>
 
</pre>
 
It is always desirable to have a daily, weekly, monthly usage reports by user or by remote host based on the above information.
 
It is always desirable to have a daily, weekly, monthly usage reports by user or by remote host based on the above information.
Line 30: Line 31:
 
== Tasks for this assignment ==
 
== Tasks for this assignment ==
 
In this assignment, your should preform the following activities:
 
In this assignment, your should preform the following activities:
# 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.  
+
# Work out an algorithm for producing daily, weekly, and monthly usage reports by user or by remote host based on the information stored in any given files generated from the 'last' command.  
# Once you believe you have a workable algorithm, you should then <b>design the structure of your python script</b> by identifying the appropriate python objects and functions to be used for each task in your algorithm and the main control logic. Make sure to identify all the input data, computation tasks, and outputs.
+
# Once you believe you have a workable algorithm, you should then <b>design the structure of your python script</b> by identifying the appropriate python objects, functions and modules to be used for each task in your algorithm and 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. You can use any built-in functions and functions from the allowed python modules to implement your solution.
+
# implement your computational solution using a single python script. You can use any built-in functions and functions 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 to facilitate better code re-use (this process is called <b>refactoring</b>).
 
# review your working python code to see whether you can improve the interface of each function to facilitate better code re-use (this process is called <b>refactoring</b>).
  
Line 76: Line 77:
  
  
If there is one file name provided at the command line, read the login/logout records from the contents of the given file. The format of each line in the file should be the same as the output of 'last -Fiw'. Filter out incomplete login/logout record (check for the number of fields in each record).
+
If there is only one file name provided at the command line, read the login/logout records from the contents of the given file. The format of each line in the file should be the same as the output of 'last -Fiw'. Filter out incomplete login/logout record (hints: check for the number of fields in each record).
  
 
If there is more than one file name provided, merge all the files together with the first one at the top and the last one at the bottom. Read and process the file contents in that order in your program.
 
If there is more than one file name provided, merge all the files together with the first one at the top and the last one at the bottom. Read and process the file contents in that order in your program.
Line 82: Line 83:
 
=== Header ===
 
=== 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):
+
All your Python codes for this assignment 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 - Winter 2019
+
<source>OPS435 Assignment 2 - Summer 2019
 
Program: ur_[Stduent_id].py
 
Program: ur_[Stduent_id].py
 
Author: "Student Name"
 
Author: "Student Name"
Line 108: Line 109:
 
=============================
 
=============================
 
asmith
 
asmith
bigia
 
 
cwsmith
 
cwsmith
hfang
 
mlee18
 
mshana
 
 
rchan
 
rchan
 
tsliu2
 
tsliu2
Line 127: Line 124:
 
=============================
 
=============================
 
10.40.105.130
 
10.40.105.130
10.40.43.94
 
 
10.40.91.236
 
10.40.91.236
 
10.40.91.247
 
10.40.91.247
 
10.43.115.162
 
10.43.115.162
24.114.50.50
 
 
</pre>
 
</pre>
  
Line 144: Line 139:
 
============================
 
============================
 
Date          Usage in Seconds
 
Date          Usage in Seconds
 +
2018 02 15        1980
 
2018 02 13        1580
 
2018 02 13        1580
Total            1580
+
Total            3560
 +
</pre>
 +
 
 +
<pre>
 +
[rchan@centos a2]$ ./ur.py -u cwsmith -t daily usage_data_file
 +
</pre>
 +
<pre>
 +
Daily Usage Report for cwsmith
 +
==============================
 +
Date          Usage in Seconds
 +
2018 03 13        2280
 +
2018 02 15        7883
 +
2018 02 14        3047
 +
Total            13210
 
</pre>
 
</pre>
  
Line 158: Line 167:
 
====================================
 
====================================
 
Date          Usage in Seconds
 
Date          Usage in Seconds
 +
2018 02 15        7883
 +
2018 02 14        3047
 
2018 02 13        7969
 
2018 02 13        7969
Total             7969
+
Total           18899
 
</pre>
 
</pre>
  
Line 172: Line 183:
 
=============================
 
=============================
 
Week #        Usage in Seconds
 
Week #        Usage in Seconds
2018 07          1580
+
2018 07          3560
Total            1580
+
Total            3560
 +
</pre>
 +
 
 +
<pre>
 +
[rchan@centos7 a2]$ ./ur.py -u cwsmith -t weekly usage_data_file
 +
</pre>
 +
 
 +
<pre>
 +
Weekly Usage Report for cwsmith
 +
===============================
 +
Week #        Usage in Seconds
 +
2018 11          2280
 +
2018 07          10930
 +
Total            13210
 +
 
 
</pre>
 
</pre>
  
Line 186: Line 211:
 
=====================================
 
=====================================
 
Week #        Usage in Seconds
 
Week #        Usage in Seconds
2018 07           7969
+
2018 07         18899
Total             7969
+
Total           18899
 
</pre>
 
</pre>
  
Line 200: Line 225:
 
==============================
 
==============================
 
Month        Usage in Seconds
 
Month        Usage in Seconds
2018 02          1580
+
2018 02          3560
Total            1580
+
Total            3560
 +
</pre>
 +
 
 +
<pre>
 +
[rchan@centos7 a2-2018fall]$ ./ur.py -u cwsmith -t monthly usage_data_file
 +
</pre>
 +
 
 +
<pre>
 +
Monthly Usage Report for cwsmith
 +
================================
 +
Month        Usage in Seconds
 +
2018 03          2280
 +
2018 02          10930
 +
Total            13210
 
</pre>
 
</pre>
  
Line 214: Line 252:
 
======================================
 
======================================
 
Month        Usage in Seconds
 
Month        Usage in Seconds
2018 02           7969
+
2018 02         18899
Total             7969
+
Total           18899
 
</pre>
 
</pre>
  
== Suggested Script Development and Testing ==
+
== Suggested workflow for this assignment ==
The following python functions (to be created) are useful in handling the following sub-tasks:
+
=== create your own user account and a <font color="blue">private</font> repository on github ===
 +
* Use any of your valid email address (Seneca or non-Seneca) to registered for a github account.
 +
* Create a private repository named "ops435-a2" for this assignment.
 +
* Populate your private repository with appropriate files. Please check out the sample repository [https://github.com/rayfreeping/ops435-a2 here]
 +
 
 +
=== Add collaborator to your ops435-a2 private repository ===
 +
* Add your professor's github account as one of the collaborators to your ops435-a2 private repository. This will allow your professor to pull the contents of your ops435-a2 repository and also to make or suggest changes and fixes to your algorithm and/or python script.
 +
* Send an email from your Seneca email address to inform your professor the name of your github account. Your professor need this information to link your github account to your Seneca ID.
 +
* Make sure that your professor accepted your invitation from github.
 +
 
 +
=== Algorithm design ===
 +
Follow the standard computation procedure: input - process - ouput to design your algorithm for this assignment.
 +
==== input ====
 +
* get data (command line arguments/options) from the user using your script
 +
* according to the arguments/options given at the command line, take appropriate processing action.
 +
==== processing ====
 +
* based on the file(s) specified, read the contents of each file and use appropriate objects to store it
 +
* based on the command line arguments/options, process the data accordingly, which includes
 +
** data preprocessing (split a multi-day record into single day record)
 +
** record processing (preform required computation)
 +
==== output ====
 +
* output the required report based on the processed data
 +
==== identify and select appropriate python objects and functions ====
 +
The following python functions (to be created, you may have more) are useful in handling the following sub-tasks:
 
* reads login records from files and filters out unwanted records
 
* reads login records from files and filters out unwanted records
 
* convert login records into proper python object type so that it can be processed using as much built-in functions as possible  
 
* convert login records into proper python object type so that it can be processed using as much built-in functions as possible  
Line 225: Line 286:
 
* create function which generates weekly usage reports by user and/or by remote host
 
* create function which generates weekly usage reports by user and/or by remote host
 
* create function which generates monthly usage reports by user and/or by remote host
 
* create function which generates monthly usage reports by user and/or by remote host
To  help you with this assignment, [[OPS435 A1 Usage Report Template|here is a template]] you can use as a starting point in designing your own Python Usage Report script.
+
To  help you with this assignment, you can use the ur_template.py in the sample ops435-a2 repository as a starting point in designing your own Python Usage Report script.
  
 +
=== Python script coding and debugging ===
 
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.
 
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 mode and verify its correctness.
 
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 mode and verify its correctness.
 
+
=== Final Test===
 
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.
 
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==
 
== Sample login/logout records file and sample test run results==
* [https://scs.senecac.on.ca/~raymond.chan/ops435/a2/ Sample test data files and sample test run results]
+
* will be posted to the sample repository github.com/rayfreeping/ops435-a2
  
 
== Rubric ==
 
== Rubric ==
Line 241: Line 302:
 
! Task !!  Maximum mark !! Actual mark
 
! Task !!  Maximum mark !! Actual mark
 
|-
 
|-
| Algorithm and program design||15 ||
+
| Algorithm and program design||20 ||
|-
 
| Program Authorship Declaration ||5 ||
 
|-
 
| Program usage || 5 ||
 
 
|-
 
|-
| Program Options || 15 ||
+
| Program usage and Options || 20 ||
 
|-
 
|-
 
| Generate user name list || 10 ||
 
| Generate user name list || 10 ||
Line 269: Line 326:
  
 
|}
 
|}
== 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 ==
 
== Submission ==
After fully testing your program, submit your python script ur_[student_id].py and your algorithm and program design report ur_[student_id].pdf in pdf format on Blackboard by August 2, 2019.
+
* Stage 1: upload your algorithm file to your ops435-a2 repository in github by July 19, 2019
 +
* Stage 2: upload your python script for this assignment to your ops435-a2 repository in github by July 26, 2019
 +
* Stage 3: After fully tested and debugged your python script for this assignment, update your algorithm, your python script, and your test results to your ops435-a2 repository in github by August 2, 2019. Also submit the algorithm file and python script to blackboard by August 2, 2019

Latest revision as of 11:37, 19 July 2019


Assignment 2 - Usage Report

Weight: 15% of the overall grade

What you need A github account with a private repository named ops435-a2

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

  • Complete the algorithm by July 19, 2019 on github,
  • Complete the coding from algorithm to Python script by July 26, 2019 on github
  • Complete the testing and debugging by August 2, 2019 on github, and also submit the algorithm file, test results and the python script to blackboard.

Late Penalty: 20% per school day, and note that this assignment must be completed satisfactorily in order to pass the course even if you get zero mark for this assignment.

Overview

Most system administrators would like to know the utilization of their systems by their users. On a Linux system, each user's login records are normally stored in the binary file /var/log/wtmp. The login records in this binary file can not be viewed or edited directly using normal Linux text commands like 'less', 'cat', etc. The 'last' command is often used to display the login records stored in this file in a human readable form. Please check the man page of the 'last' command for available options. The following is the contents of the file named "usage_data_file", which is a sample output of the 'last' command with the '-Fiw' flag on:

$ last -Fiw > usage_data_file
$ cat usage_data_file
rchan    pts/9        10.40.91.236     Tue Feb 13 16:53:42 2018 - Tue Feb 13 16:57:02 2018  (00:03)    
cwsmith  pts/10       10.40.105.130    Wed Feb 14 23:09:12 2018 - Thu Feb 15 02:11:23 2018  (03:02)
rchan    pts/2        10.40.91.236     Tue Feb 13 16:22:00 2018 - Tue Feb 13 16:45:00 2018  (00:23)    
rchan    pts/5        10.40.91.236     Tue Feb 15 16:22:00 2018 - Tue Feb 15 16:55:00 2018  (00:33)    
asmith   pts/2        10.43.115.162    Tue Feb 13 16:19:29 2018 - Tue Feb 13 16:22:00 2018  (00:02)    
tsliu2   pts/4        10.40.105.130    Tue Feb 13 16:17:21 2018 - Tue Feb 13 16:30:10 2018  (00:12)    
cwsmith  pts/13       10.40.91.247     Tue Mar 13 18:08:52 2018 - Tue Mar 13 18:46:52 2018  (00:38)    
asmith   pts/11       10.40.105.130    Tue Feb 13 14:07:43 2018 - Tue Feb 13 16:07:43 2018  (02:00)

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 should preform the following activities:

  1. Work out an algorithm for producing daily, weekly, and monthly usage reports by user or by remote host based on the information stored in any given files generated from the 'last' command.
  2. Once you believe you have a workable algorithm, you should then design the structure of your python script by identifying the appropriate python objects, functions and modules to be used for each task in your algorithm and the main control logic. Make sure to identify all the input data, computation tasks, and outputs.
  3. implement your computational solution using a single python script. You can use any built-in functions and functions from the allowed python modules to implement your solution.
  4. review your working python code to see whether you can improve the interface of each function to facilitate better code re-use (this process is called refactoring).

Allowed Python Modules for this assignment

Instructions

Program Name and valid command line arguments

Name your Python3 script as ur_[student_id].py. 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 link) 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:

[rchan@centos7 a1]$ python3 ./ur.py -h
usage: ur_rchan.py [-h] [-l {user,host}] [-r RHOST] [-t {daily,weekly,monthly}]
             [-u USER] [-v]
             F [F ...]

Usage Report based on the last command

positional arguments:
  F                     list of files to be processed

optional arguments:
  -h, --help            show this help message and exit
  -l {user,host}, --list {user,host}
                        generate user name or remote host IP from the given
                        files
  -r RHOST, --rhost RHOST
                        usage report for the given remote host IP
  -t {daily,weekly,monthly}, --type {daily,weekly,monthly}
                        type of report: daily, weekly, and monthly
  -u USER, --user USER  usage report for the given user name
  -v, --verbose         tune on output verbosity

Copyright 2019 - Raymond Chan 

Replace the last line with your own full name


If there is only one file name provided at the command line, read the login/logout records from the contents of the given file. The format of each line in the file should be the same as the output of 'last -Fiw'. Filter out incomplete login/logout record (hints: check for the number of fields in each record).

If there is more than one file name provided, merge all the files together with the first one at the top and the last one at the bottom. Read and process the file contents in that order in your program.

Header

All your Python codes for this assignment must be placed in a single source file. Please include the following declaration by you as the script level docstring in your Python source code file (replace [Student_id] with your Seneca email user name, and "Student Name" with your own name):

OPS435 Assignment 2 - Summer 2019
Program: ur_[Stduent_id].py
Author: "Student Name"
The python code in this file ur_[Student_id].py is original work written by
"Student Name". No code in this file is copied from any other source 
including any person, textbook, or on-line resource except those provided
by the course instructor. I have not shared this python file 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.

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 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:

[rchan@centos7 a2]$ ./ur.py -l user usage_data_file
User list for usage_data_file
=============================
asmith
cwsmith
rchan
tsliu2

Remote Host List

The following is the remote host list extracted from the usage_file_file created by the command:

[rchan@centos7 a2]$ ./ur.py -l host usage_data_file
Host list for usage_data_file
=============================
10.40.105.130
10.40.91.236
10.40.91.247
10.43.115.162

Daily Usage Report by User

The following is a Daily Usage Report created for user rchan by the following command:

[rchan@centos7 a2]$ ./ur.py -u rchan -t daily usage_data_file
Daily Usage Report for rchan
============================
Date          Usage in Seconds
2018 02 15        1980
2018 02 13        1580
Total             3560
[rchan@centos a2]$ ./ur.py -u cwsmith -t daily usage_data_file
Daily Usage Report for cwsmith
==============================
Date          Usage in Seconds
2018 03 13        2280
2018 02 15        7883
2018 02 14        3047
Total            13210

Daily Usage Report by Remote Host

The following is a Daily Usage Report created for the Remote Host 10.40.105.103 by the command:

[rchan@centos7 a2]$ ./ur.py -r 10.40.105.130 -t daily usage_data_file
Daily Usage Report for 10.40.105.130
====================================
Date          Usage in Seconds
2018 02 15        7883
2018 02 14        3047
2018 02 13        7969
Total            18899

Weekly Usage Report by User

The following is a Weekly Usage Report created for user rchan by the command:

[rchan@centos7 a2]$ ./ur.py -u rchan -t weekly usage_data_file
Weekly Usage Report for rchan
=============================
Week #        Usage in Seconds
2018 07           3560
Total             3560
[rchan@centos7 a2]$ ./ur.py -u cwsmith -t weekly usage_data_file
Weekly Usage Report for cwsmith
===============================
Week #        Usage in Seconds
2018 11           2280
2018 07          10930
Total            13210

Weekly Usage Report by Remote Host

The following is a Weekly Usage Report created for the remote host 10.40.105.130 by the command:

[rchan@centos7 a2]$ ./ur.py -r 10.40.105.130 -t weekly usage_data_file
Weekly Usage Report for 10.40.105.130
=====================================
Week #        Usage in Seconds
2018 07          18899
Total            18899

Monthly Usage Report by User

The following is a Monthly Usage Report created for user rchan by the command:

[rchan@centos7 a2-2018fall]$ ./ur.py -u rchan -t monthly usage_data_file
Monthly Usage Report for rchan
==============================
Month         Usage in Seconds
2018 02           3560
Total             3560
[rchan@centos7 a2-2018fall]$ ./ur.py -u cwsmith -t monthly usage_data_file
Monthly Usage Report for cwsmith
================================
Month         Usage in Seconds
2018 03           2280
2018 02          10930
Total            13210

Monthly Usage Report by Remote Host

The following is a Monthly Usage Report created for remote host 10.40.105.130 by the command:

[rchan@centos7 a2-2018fall]$ ./ur.py -r 10.40.105.130 -t monthly usage_data_file
Monthly Usage Report for 10.40.105.130
======================================
Month         Usage in Seconds
2018 02          18899
Total            18899

Suggested workflow for this assignment

create your own user account and a private repository on github

  • Use any of your valid email address (Seneca or non-Seneca) to registered for a github account.
  • Create a private repository named "ops435-a2" for this assignment.
  • Populate your private repository with appropriate files. Please check out the sample repository here

Add collaborator to your ops435-a2 private repository

  • Add your professor's github account as one of the collaborators to your ops435-a2 private repository. This will allow your professor to pull the contents of your ops435-a2 repository and also to make or suggest changes and fixes to your algorithm and/or python script.
  • Send an email from your Seneca email address to inform your professor the name of your github account. Your professor need this information to link your github account to your Seneca ID.
  • Make sure that your professor accepted your invitation from github.

Algorithm design

Follow the standard computation procedure: input - process - ouput to design your algorithm for this assignment.

input

  • get data (command line arguments/options) from the user using your script
  • according to the arguments/options given at the command line, take appropriate processing action.

processing

  • based on the file(s) specified, read the contents of each file and use appropriate objects to store it
  • based on the command line arguments/options, process the data accordingly, which includes
    • data preprocessing (split a multi-day record into single day record)
    • record processing (preform required computation)

output

  • output the required report based on the processed data

identify and select appropriate python objects and functions

The following python functions (to be created, you may have more) are useful in handling the following sub-tasks:

  • reads login records from files and filters out unwanted records
  • 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
  • create function which generates weekly usage reports by user and/or by remote host
  • create function which generates monthly usage reports by user and/or by remote host

To help you with this assignment, you can use the ur_template.py in the sample ops435-a2 repository as a starting point in designing your own Python Usage Report script.

Python script coding and debugging

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 mode and verify its correctness.

Final Test

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

  • will be posted to the sample repository github.com/rayfreeping/ops435-a2

Rubric

Task Maximum mark Actual mark
Algorithm and program design 20
Program usage and Options 20
Generate user name list 10
Generate remote host IP list 10
Daily Usage Report by User 10
Daily Usage Report by Remote Host 10
Weekly Usage Report by User 5
Weekly Usage Report by Remote Host 5
Monthly Usage Report by User 5
Monthly Usage Report by Remote Host 5
Total 100

Submission

  • Stage 1: upload your algorithm file to your ops435-a2 repository in github by July 19, 2019
  • Stage 2: upload your python script for this assignment to your ops435-a2 repository in github by July 26, 2019
  • Stage 3: After fully tested and debugged your python script for this assignment, update your algorithm, your python script, and your test results to your ops435-a2 repository in github by August 2, 2019. Also submit the algorithm file and python script to blackboard by August 2, 2019