Difference between revisions of "OPS435 A1 Usage Report Template"

From CDOT Wiki
Jump to: navigation, search
(Usage Report Template)
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
[[Category:OPS435]][[Category:rchan]]
 
[[Category:OPS435]][[Category:rchan]]
= A1 Usage Report Template =
+
= Usage Report Template =
 
Please note that the following listing contains some actual python codes, but mostly are pseudo code.
 
Please note that the following listing contains some actual python codes, but mostly are pseudo code.
 
<pre>
 
<pre>
 
#!/usr/bin/env python3
 
#!/usr/bin/env python3
#
+
'''
# authorship declaration
+
  authorship declaration
#
+
 
# Author: Raymond Chan
+
  __author__ Raymond Chan
# Date: Feb 2018
+
  __date__ March 2019
#
+
  __version__ 1.0
 +
 +
  text to describe the purpose of this script
 +
'''
  
 
import os  
 
import os  
 
import sys
 
import sys
 
+
import time
import ...
+
import argparse
 
 
def menu(title,items,choice):
 
    selection = ''
 
    while selection not in choice:
 
        print(title)
 
        print('=' * len(title))
 
        for item in items:
 
            print(item)
 
        selection = input('menu choice -->')
 
    return selection
 
  
 
def get_login_rec():
 
def get_login_rec():
     # get records from the last command
+
     ''' docstring for this fucntion
     # filter out the unwanted records
+
    get records from the last command
     # add filtered record to list (login_recs)
+
     filter out the unwanted records
 +
     add filtered record to list (login_recs)'''
 +
    [ put your python code for this function here ]
 
     return login_recs
 
     return login_recs
 
   
 
   
 
def read_login_rec(filelist):
 
def read_login_rec(filelist):
     # get records from given filelist
+
     ''' docstring for this function
     # open and read each file from the filelist
+
    get records from given filelist
     # filter out the unwanted records
+
     open and read each file from the filelist
     # add filtered record to list (login_recs)  
+
     filter out the unwanted records
 +
     add filtered record to list (login_recs)'''
 +
    [ put your python code for this function here ]
 
     return login_rec
 
     return login_rec
  
def cal_daily_usage(subject,login_recs)
+
def cal_daily_usage(subject,login_recs):
     # check number of subjects in login_recs
+
     ''' docstring for this function
     # if less than 10, display subject selection menu
+
     generate daily usage report for the given
     # for each subject, process daily usage
+
     subject (user or remote host)'''
     # dispaly daily usage
+
     [ put your python code for this function here ]
     return 0
+
     return daily_usage
  
def cal_weekly_usage(subject,login_recs)
+
def cal_weekly_usage(subject,login_recs):
     # check number of subjects in login_recs
+
     ''' docstring for this function
     # if less than 10, display subject selection menu
+
     generate weekly usage report for the given
     # for each subject, process weekly usage
+
     subject (user or remote host)'''
     # display weekly usage
+
     [ put your python code for this function here ]
     return 0
+
     return weekly_usage
  
def cal_monthly_usage(subject,login_recs)
+
def cal_monthly_usage(subject,login_recs):
     # check numbe of subjects in login_recs
+
     ''' docstring for this function
     # if less than 10, display subject selection menu
+
     generate monthly usage report fro the given
     # for each subject, process monthly usage
+
     subject (user or remote host)'''
     # display monthly usage
+
     [ put your python code for this function here ]
     return 0
+
     return monthly_usage
 
      
 
      
 
if __name__ == '__main__':
 
if __name__ == '__main__':
     # retrieve command line argument
+
      
 
+
    [ code to retrieve command line argument using the argparse module [
    # set menu and submenu display text
+
     ...
    menu_title = 'Usage Report - Main Menu'
+
     [ based on the command line option,  
    menu_items = []
+
      call the appropriate functions defined about
     menu_items.append('d) Diaily Usage Report')
+
      to read the login records,
    menu_items.append('w) Weekly Usage Report')
+
      to process the login records
    menu_items.append('m) Monthly Usage Report')
+
      to generate and print
    menu_items.append('q) Quit')
+
      the requested usage report ]
     menu_options = ['d','w','m','q']
+
     ...
 
 
    dumenu_title = 'Daily Usage Report Menu'
 
    dumenu_items = []
 
    dumenu_items.append('u) By User')
 
    dumenu_items.append('h) By Remote Host')
 
    dumenu_items.append('r) Return to Main Menu')
 
    dumenu_options = ['u','h','r']
 
 
 
    wumenu_title = 'Weekly Usage Report Menu'
 
    wumenu_items = []
 
    wumenu_items.append('u) By User')
 
    wumenu_items.append('h) By Remote Host')
 
    wumenu_items.append('r) Return to Main Menu')
 
    wumenu_options = ['u','h','r']
 
 
 
    mumenu_title = 'Monthly Usage Report Menu'
 
    mumenu_items = []
 
    mumenu_items.append('u) By User')
 
    mumenu_items.append('h) By Remote Host')
 
    mumenu_items.append('r) Return to Main Menu')
 
    mumenu_options = ['u','h','r']
 
 
 
    menu_selected = ''
 
     while menu_selected != 'q':
 
        menu_selected = menu(menu_title,menu_items,menu_options)
 
        print('You have selected:', menu_selected)
 
 
 
        if menu_selected == 'd':
 
            dumenu_selected = ''
 
            while dumenu_selected != 'r':
 
                dumenu_selected = menu(dumenu_title,dumenu_items,dumenu_options)
 
                print('You have selected:',dumenu_selected)
 
                if dumenu_selected == 'u':
 
                    print('Call Daily Usage Report by User.')
 
 
 
                if dumenu_selected == 'h':
 
                    print('Call Daily Usage Report by Remote host.')
 
 
 
        if menu_selected == 'w':
 
            # call Weekly Usage report menu and submenu
 
 
 
        if menu_selected == 'm':
 
            # call Monthly Usage report menu and submenu
 
 
 
    print('Thank you for using this Python program.')
 
 
</pre>
 
</pre>

Latest revision as of 10:39, 14 March 2019

Usage Report Template

Please note that the following listing contains some actual python codes, but mostly are pseudo code.

#!/usr/bin/env python3
'''
   authorship declaration

   __author__ Raymond Chan
   __date__ March 2019
   __version__ 1.0
 
   text to describe the purpose of this script
'''

import os 
import sys
import time
import argparse

def get_login_rec():
    ''' docstring for this fucntion
    get records from the last command
    filter out the unwanted records
    add filtered record to list (login_recs)'''
    [ put your python code for this function here ]
    return login_recs
 
def read_login_rec(filelist):
    ''' docstring for this function
    get records from given filelist
    open and read each file from the filelist
    filter out the unwanted records
    add filtered record to list (login_recs)''' 
    [ put your python code for this function here ]
    return login_rec

def cal_daily_usage(subject,login_recs):
    ''' docstring for this function
    generate daily usage report for the given 
    subject (user or remote host)'''
    [ put your python code for this function here ]
    return daily_usage

def cal_weekly_usage(subject,login_recs):
    ''' docstring for this function
    generate weekly usage report for the given 
    subject (user or remote host)'''
    [ put your python code for this function here ]
    return weekly_usage

def cal_monthly_usage(subject,login_recs):
    ''' docstring for this function
    generate monthly usage report fro the given
    subject (user or remote host)'''
    [ put your python code for this function here ]
    return monthly_usage
     
if __name__ == '__main__':
    
    [ code to retrieve command line argument using the argparse module [
    ...
    [ based on the command line option, 
      call the appropriate functions defined about 
      to read the login records,
      to process the login records
      to generate and print 
      the requested usage report ]
    ...