This package contains common classes and helper methods for the CSE 351 course.
Python and pip must be installed on your system already. Make sure Python has been added to your system path. If running one of these commands python --version
or python3 --version
or py --version
does not return a Python version do not continue until you have correctly installed Python. Note that the returned Python version should be at least 3.11 or greater.
Windows
-
Open a command prompt.
-
Install the package using
python -m pip
:python -m pip install git+https://github.com/byui-cse/cse351-py-package.git
If you have Python 3 installed as the default, you might use:
python3 -m pip install git+https://github.com/byui-cse/cse351-py-package.git
If you have Python installed and added to PATH as
py
, you can also use:py -m pip install git+https://github.com/byui-cse/cse351-py-package.git
MacOS
-
Open a terminal.
-
Install the package using
python -m pip
:python -m pip install git+https://github.com/byui-cse/cse351-py-package.git
If you have Python 3 installed as the default, you might use:
python3 -m pip install git+https://github.com/byui-cse/cse351-py-package.git
Linux
-
Open a terminal.
-
Install the package using
python -m pip
:python -m pip install git+https://github.com/byui-cse/cse351-py-package.git
If you have Python 3 installed as the default, you might use:
python3 -m pip install git+https://github.com/byui-cse/cse351-py-package.git
You can import this package into your assignments by adding the following with your import statements:
from cse351 import *
This utility package provides a set of convenient tools for data analysis and visualization. It offers the following key features:
-
Setting Script Working Directory:
- Easily set the current working directory using the
set_working_directory
function.
- Easily set the current working directory using the
-
Logging Utility:
- The
Log
class facilitates efficient logging, providing both console output (stdout) and log file recording. Users can conveniently manage log messages, warnings, errors, and timing information. The logger supports customization options such as log file naming, formatting, and verbosity.
- The
-
JSON File Handling:
- Use the
load_json_file
function to effortlessly load and parse JSON files. This function enhances the convenience of working with JSON data, supporting seamless integration into data processing workflows.
- Use the
-
Matplotlib Plotting Support:
- The
Plots
class simplifies the creation of line and bar plots usingmatplotlib
. It offers a straightforward interface for users to generate visually appealing plots with customizable titles, labels, and saving options.
- The
This utility is designed to be easily installable using the Python package manager, pip. Installing this package will auto install the following dependencies:
- matplotlib: For creating high-quality plots and visualizations.
- numpy: A powerful library for numerical operations.
- pillow: An imaging library for opening, manipulating, and saving various image file formats.
- requests: A versatile library for making HTTP requests.
- opencv-python: A computer vision library for image and video processing.
- Luc Comeau
- Hunter Wilhelm
- Christopher Keers
MIT License
Sets the current working directory to the specified folder.
Parameters:
file_path
(str): The path to the folder to use as the working directory.
Displays a dictionary in a structured format.
Parameters:
dict
(dict): The dictionary to pretty print.title
[str]: A title line to print before the dictionary if desired.indent
[int]: How much to indent each succeeding level of the dictionary; default 2.
Attempts to load and parse a JSON file.
Parameters:
filename
(str): The path including filename of the JSON file to attempt to open.
Returns:
dict
: The parsed JSON or an empty dictionary.
filename_log
[str]: Name of the log file; default is [timestamp].log.linefmt
[str]: Logger format; default%(message)s
.show_levels
[bool]: Set to True to record levels when necessary; default False.include_time
[bool]: Set to False to exclude timestamps; default True.append_mode
[bool]: Set to True to append to previous log; default False (overwrite).
Starts (restarts) the timer.
Parameters:
message
[str]: Optional message to print as you restart the timer.
Gets the current timer value.
Parameters:
message
[str]: Optional message to print as you restart the timer.
Returns:
float
: Current timer value.
Stops the timer and reports the elapsed time.
Parameters:
message
[str]: Optional message to print as you restart the timer.
Returns:
float
: Elapsed time.
Gets the current timer value.
Returns:
float
: Current timer value.
Writes a blank line to the log file.
Writes an info message to the log file.
Parameters:
message
(str): Message to be written to the log file.
Writes a warning message to the log file.
Parameters:
message
(str): Warning message to be written to the log file.
Writes an error message to the log file.
Parameters:
message
(str): Error message to be written to the log file.
title
(str): Title for the plot graph.
Creates a line plot.
Parameters:
xdata
: X-axis data.ydata
: Y-axis data.desc
[str]: Description of the plot.title
[str]: Title of the plot.x_label
[str]: Label for the X-axis.y_label
[str]: Label for the Y-axis.show_plot
[bool]: Whether to display the plot.filename
[str]: Filename to save the plot.
Creates a bar plot.
Parameters:
xdata
: X-axis data.ydata
: Y-axis data.desc
[str]: Description of the plot.title
[str]: Title of the plot.x_label
[str]: Label for the X-axis.y_label
[str]: Label for the Y-axis.show_plot
[bool]: Whether to display the plot.filename
[str]: Filename to save the plot.