Skip to main content

Unit Conversion Grader a command-line interface (CLI) program that allows you to convert among units of measurement and grade the users response to determine the result.

Project description

Unit Conversion Grader

Overview

Unit Conversion Grader is a command-line interface (CLI) tool that allows teachers to grade the student's response for the result of converting among units of measurement.

Table of Contents

Installation

Choose either stable release or development.

Python and Pip Installation

Please ensure you download and install python3.9+ and pip in sequence.

Checkout python official website and pip official website for details on download and installation.

Stable Release

  • Run python -m pip install unit-grader --upgrade

  • Test the CLI to verify the installation via running unit-grader -i 100 -f Kelvin -t Celsius -s -173.15

Development

  • Install Python with version 3.9 or higher
  • Follow official documentation to install PDM
  • git clone https://github.com/souyang/unit-grader.git
  • cd unit-grader
  • pdm install
  • python3 -m pip install -e .
  • Test the CLI to verify the installation via running unit-grader -i 100 -f Kelvin -t Celsius -s -173.15

Main Features

  • Teacher provides input-value(input numeric value), from-unit(input unit of measurement), to-unit (a target unit of value), student-response (student's numeric response) as inputs. Check out here for more details.
  • System indicates the response is correct, incorrect or invalid.
  • Student's response is correct if the response is equal to the answer after the response and the answer are both rounded to tenths place. Check out here for more details.
  • Unit Testing code coverage is 100%. Commit will fail if code coverage is less than 100%.
  • Sphinx is used in pre-commit hook and CI/CD pipeline for generating api documentation from source code.
  • A CI/CD pipeline is created. CI will be triggered when a pull request is created with main as the target branch or a commit is merged to main. CD will be triggered after CI is successful.
  • The executable deployment is on pypi and api documentation deployment is on Netlify
  • Versioning and Verbose are both implemented.
  • Pre-Commit hook is set up to ensure best code quality on grammar check, linting and formatting in every commit.
  • Error reporting is provided to the end user when the output is invalid.
  • Informational reporting is provided to the end user when the output is incorrect.
  • User feedback mechanism is set up for future enhancement.
  • Logging is enabled, user will see diagnose information when --verbose or -v as the option is set.
  • Output is colorized for user to distinguish between different types of information.
  • Progress Bar is enabled for long-running tasks.

Future Tasks

Dependencies

In the development of this project, we've leveraged the following third-party dependencies to enhance functionality and streamline development:

  • PDM: A Python project management tool and package installer.
  • Typer: A Python library for building command-line applications.
  • Pre-Commit: A framework for managing and maintaining multi-language pre-commit hooks.
  • codespell: A tool designed to catch spelling mistakes in code.
  • Pytest: A testing framework for Python.
  • Ruff: A linter and formatter for Python.
  • Sphinx: A documentation generator for Python projects.
  • bump-my-version: A small command line tool to simplify releasing software by updating all version strings in code by the correct increment and optionally commit and tag the changes.

For detailed information about each tool and why we chose them, refer to the detailed documentation.

Command Usage

Syntax

unit-grader -i <input-value> -f <from-unit> -t <to-unit> -s <student-response>

General Instructions

  • Provide input-value, from-unit, to-unit, student-response as input.
  • from-unit and to-unit must be in the same unit meansurement category.
  • Expected output: correct, incorrect, invalid.
  • Supported unit meansurement categories include temperature and volume.
  • units supported in the temperature category: Kelvin, Celsius, Fahrenheit and Rankine.
  • units supported in the volume category: liters, tablespoons, cubic-inches, cups, cubic-feet, gallons.
  • Regarding volume units, tablespoons means us tablespoons, cubic-inches means cups means us cups, gallons means us gallons,
  • The name of each unit is case-sensitive.
  • Student's response must match the correct answer after both values are rounded to the tenths place.
  • The rounding strategy follows round half to even (Banker's rounding). For example round(4.65, 1) == 4.6 and round(4.75, 1) == 4.8.

Examples

Sample Command Output
unit-grader -i 50 -f Kelvin -t Celsius -s 30 incorrect
unit-grader -i 100 -f Kelvin -t Celsius -s -173.15 correct
unit-grader -i dog -f Kelvin -t Celsius -s -173.15 invalid

Get Help

  • Run unit-grader --help to get information

Get CLI Version

unit-grader --version
unit-grader -V

Required input for grading response

  - `input-value (i)`: a numeric value
  - `from-unit (f)`: input unit of measure
  - `to-unit (t)`: target unit of measure
  - `student-response (s)` : student's numeric response

Sample use cases:

Sample Command Input Value Input Unit Target Unit Student Response Output
unit-grader -i 50 -f Kelvin -t Celsius -s 30 50 Kelvin Celsius 30 incorrect
unit-grader -i 50 -f Kelvin -t Celsius -s dog 50 Kelvin Celsius dog incorrect
unit-grader -i 100 -f Kelvin -t Celsius -s -173.15 100 Kelvin Celsius -173.15 correct
unit-grader -i 100 -f cups -t liters -s 23.66 100 cups liters 23.66 correct
unit-grader -i dog -f Kelvin -t Celsius -s -173.15 dog Kelvin Celsius 30 invalid
unit-grader -i 100 -f Kelvin -t gallons -s -173.15 100 Kelvin gallons 30 invalid
unit-grader -i 100 -f dog -t gallons -s -173.15 100 dog gallons 30 invalid
unit-grader -i 100 -f Kelvin -t dog -s -173.15 100 dog gallons 30 invalid

Advanced Usage

Detail information in Verbose Mode

You can get detail information about your input in verbose mode for debugging purposes. For example, unit-grader -i 100 -f Kelvin -t dog -s -173.15 -v will print out the messages

Verbose mode is enabled.
input-value: 100
from_unit: Celsius
to_unit: Kelvin
student_response: 305.2

Error Handling

Use Case Sample Command Expected Message Reported to user
Input numeric value is not a number unit-grader -i dog -f Kelvin -t Celsius -s -173.15 Input Error: dog as input_value needs to be a number. Please use --help to see valid options.
Input unit of measure is not supported or invalid unit-grader -i 100 -f Test -t Celsius -s -173.15 Input Error: Test as from_unit is not supported. Select a conversion unit (Kelvin, Celsius, Fahrenheit, Rankine for temperature; liters, tablespoons, cubic-inches, cups, cubic-feet, gallons for volume). Please note that the unit is case-sensitive.
Target unit of measure is not supported or invalid unit-grader -i 100 -f Test -t Celsius -s -173.15 Input Error: Test as from_unit is not supported. Select a conversion unit (Kelvin, Celsius, Fahrenheit, Rankine for temperature; liters, tablespoons, cubic-inches, cups, cubic-feet, gallons for volume). Please note that the unit is case-sensitive.
Input unit of measure and Target unit of measure are not in the same category unit-grader -i 100 -f cups -t Celsius -s -173.15 Input Error: Ensure the selected conversion units match their respective categories for a valid conversion. Select a conversion unit (Kelvin, Celsius, Fahrenheit, Rankine for temperature; liters, tablespoons, cubic-inches, cups, cubic-feet, gallons for volume). Please note that the unit is case-sensitive.

CI/CD Pipeline

This project uses CI/CD pipelines to automate the testing, building, and deployment processes. The main CI/CD tool employed is [GitHub Actions], and the configuration is stored in [.github/workflows/main.yaml, .github/workflows/docs.yaml].

Continuous Integration (CI)

The CI pipeline is triggered on every push to the main branch or when pull requests are submitted. The CI process includes the following steps:

  1. Linting and Formatting: The code is checked for style and formatting using Ruff.
  2. Spelling Check: The code is spellchecked using codespell
  3. Unit Tests: Unit tests are executed to ensure the code functions as expected and coverage reaches 100%. Pytest
  4. Integration Test: Integration tests are executed to ensure the CLI App as expected. Typer.CliRunner

Continuous Deployment (CD)

The CD pipeline is triggered when changes are merged into the main branch, and it is responsible for deploying the application. The deployment process typically involves the following steps:

  1. CLI Deployment to pypi.org: After app's version is bumped to the next patch version, the application is deployed to the pypi.

  2. Document Generation and Deployment to Netlify: After CLI deployment is successful, api documentation is deployed to Netlify.

Documentation

This project's documentation is automatically generated using Sphinx. The documentation includes details about the API, code structure, and usage.

API Documentation

The API documentation is generated from docstrings in the source code. Sphinx extracts these docstrings and formats them into a user-friendly documentation website. To view the latest documentation, visit Documentation Link.

Doc Generation and Deployment in CI/CD Pipeline

The documentation is automatically generated and deployed after the code is deployed. The main steps in the CI/CD pipeline related to documentation are as follows:

  1. Documentation Build: Sphinx is used to build the documentation from the source code.
  2. Deployment: The documentation is deployed to Netlify. Please see here

Viewing the Documentation Locally

To build and view the documentation locally, follow these steps:

# Install Sphinx (if not already installed)
pdm install
# Build doc
pdm doc
# View doc
cd docs && open _build/html/index.html

Contributing Guideline

We welcome contributions! Please follow our contribution guidelines.

License

This project is licensed under the MIT License.

Discussion

Most development discussions take place on GitHub in this repo, via the GitHub issue tracker.


Go to Top

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unit_grader-1.0.13.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

unit_grader-1.0.13-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file unit_grader-1.0.13.tar.gz.

File metadata

  • Download URL: unit_grader-1.0.13.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.10.4 CPython/3.10.12

File hashes

Hashes for unit_grader-1.0.13.tar.gz
Algorithm Hash digest
SHA256 98a8e56540a285ffe6ca0fba8fc74e28a0e919ef4e5c6ba155a292a0822ab0e3
MD5 db14229800ff70e0617857e0cf003193
BLAKE2b-256 e163c556283ef2e0eabc1143fed0fda8d9bd5cd126fc6fa28311b31a14ec2019

See more details on using hashes here.

File details

Details for the file unit_grader-1.0.13-py3-none-any.whl.

File metadata

  • Download URL: unit_grader-1.0.13-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.10.4 CPython/3.10.12

File hashes

Hashes for unit_grader-1.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 dab04677e5d25d5baab7cd4db57ccc924ec092faf226da2029dfc48190155384
MD5 f95782768a97237b96b1ffa2f2cfbef6
BLAKE2b-256 8d66a5d0d05711e5e883e123337c9d171cf21c0be8728f5ba023f4f3888cce85

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page