This assignment is based on the concepts of "Decorators". We have created different decorators for different tasks of the assignment.
function called to create a decorator. func is a non local variable.
Function check's current time to see if the current time's second's value is odd or not, if odd, then only function is executed otherwise not For eg: after decorating add function, if add is called at time seconds value is 21 (odd), function will be executed while if second's value is 20(even) it will not execute add function with 1,2 as input for 1st time, the output will be: add has been called 1 times, Result: 1 + 2 = 3
Decorator to make a function run only on odd seconds
function called to create a decorator. func is a non local variable for the inner function.
Print the log of function with details like function name,function documentation, execution time, count of times function is called and function call representation with arguments as string. Also, update the global func_log list which is be used to verify the logging functionality For eg: after decorating add function, if add(1,2) is called, apart from result, log will be showcased like- --- Log for function: add --- Function documentation: add the input variables Function called at: 2020-09-20 20:40:08.767335+00:00 Total time to execute: 1.9999998812636477e-07 Function called: 1 times Call function add(1,2) Result- 3
Decorator to make add log to a function
Decorators factory to create a decorator. func is a non local variable for the inner function.
Creates decorator through factory method for authenticating a function
Call a function after it is authenticated. Otherwise display error For eg: on calling add function, if the user name is correct, then only function will result the output else it will show an error message
Decorator to make add user authentication to a function
decorator factory to create a decorator.
Calls function add, mul or div with input parameters and update a global dictionary "operation" having add, mul and div as its keys while calling the respective function. Function call updates the user specific dictionary and output the result showing how many times this function has been called. It also calls respective function(non local variable fn) with given input and returns the output string. For eg: on calling closure for add function with 1,2 as input for 1st time, the output will be: add has been called 1 times, Result: 1 + 2 = 3
Function to create a decorator called to decorate a function by timing it.
Function check's how much time it takes on an average for n runs to execute a function. For eg: after decorating fact function for repeat = 100, we will get how much time it takes for fact function to run for any given inputs on an average for 100 runs. In this case we will get - fact(5) Function fact takes average run time of 2.3930000179461787e-06 for 100 iterations
Decorator to make add timer to a function
E) Decorator Provides privilege access (has 4 parameters, based on privileges (high, mid, low, no), gives access to all 4, 3, 2 or 1 params)
Get the records of four columns of the df based on the user 4 level of access privilege for the user. If privilege is 1, user can see only Name. if privilege is 2, user can see Name and age and like this if access if 4, user can see all four columns
Provides the user data access based on its privilege
Decorator to make privilege based call for a function
Singledispatch creates three things, a registry, a register and a dispatch function. We have used the singledispatch from functools to create htmlizer.
convert in html format for object type
convert in html format for int type
convert in html format for float type
convert in html format for decimal type
convert in html format for list anf tuple type
convert in html format for dict type
convert in html format for str type
Test for readme exists
Test for readme contents are more than 500 words
Test for all important functions/class described well in your README.md file
Test for readme formatting
Test for source code formatting. No tabs but four spaces are used for indentation
Test for no function is with capitals in source code
Test to check the docstr_len_check is a closure
Test to check the decorator has doc string
Test to check the decorator changed function to be called at odd seconds only
Test to check the add has closure attribute which is required to get Decorator
Test to check the add_logged is working and its logs are generated we are also inserting the logs in global log list(func_log) to check whether the count for log is increasing when the function is called
check the decorator @authenticate is validating user credentials before calling a function
Create a decorator, which when added to any function can execute it given number of times and return the results and gives back the average runtime based for given number of runs
Create a decorator, which when added to any function allows to let the user access a database based on the privilege user has got. To demonstrate the functionality, we have used a user class to create 4 different users with different privileges, 1 being lowest and 4 being highest. We have created a pandas dataframe to store data of four patients with details of name, age, bood_group and Covid_Infected. Rules -> The user named HOD, created with privilege 4 should be able to access all 4 columns The user named Doctor, created with privilege 3 should be able to access first 3 columns as we don't want doctor to be biased against covid patients The user named nurse, created with privilege 2 should be able to access first 2 columns only The user named accountant, created with privilege 1 should be able to access first column to get the patients id for billing purpose we have access_records which is decorated with privilege access and it returns only the data based on users privilege
singledispatch creates three things, a registry, a register and a dispatch function. We have used the singledispatch from functools to create htmlizer. We will test the htmlizer is converting the code properly or not. to check the valid update for counters in user specific dictionary for alternative approach