Git Product home page Git Product logo

tempconv-py's Introduction

pretty-temperature-conversion-library

This module can convert from/to Kelvin, Celsius, Rankine, Reaumur[1], and Romer[1] using formulas from Wikipedia.org[2].

The aim of the temperature conversion library is to create an easy to use, syntactically simple way to convert between temperature units of measurement. It does not require the developer, who is referencing the library, to use a special function to convert. Instead, the conversion happens in the background when the original temperature is set, and when the new temperature is referenced.

Instead of...

celsius = 100
fahrenheit = t.convertToFahrenheit(celsius)
print(fahrenheit) # 212 F

We do this...

t.celsius = 100
print(t.fahrenheit) # 212 F

Usage

Step 1. Initiate the class

I recommend not using the word temp, because it sounds like a temporary variable name.

t = Temperature

Step 2. Set your temperature in original unit of measurement

t.celsius = 100

OR

t.fahrenheit = 100

OR

t.kelvin = 100

Step 3. Reference temperature in desired unit of measurement

Here are some print examples:

print(t.celsius)

print(t.fahrenheit)

print(t.kelvin)

How it works

The library works by using Python decorators, setters, and getters to automatically calculate and store temperatures in Kelvins. Whenever Temperature.fahrenheit or Temperature.celsius are referenced, a Python getter calculates them based off the stored Kelvin value. Temperature.kelvin can also be referenced and changed directly.

Performance

The aim of this library is to provide easy-to-use syntax for Temperature conversion. But because the library does two calculations to convert from Celsius to Fahrenheit, it goes without saying that it isn't the best choice for large-scale massively parallel computing operations. But you wouldn't be using a Python library for that, would you?

Performance can be improved by converting directly from Fahrenheit to Celsius... Or using something like C or Fortran.

Testing

To test the library, run the testing library.

Footnotes

[1] Used in this library without diacritical marks (i.e. not Réaumur or Rømer)

[2] https://en.wikipedia.org/wiki/Conversion_of_units_of_temperature

tempconv-py's People

Stargazers

 avatar

tempconv-py's Issues

Convert from floating point to Decimal for accuracy

Thank goodness for unit testing. Without it, I wouldn't have figured out that my temperature calculations are inaccurate, due to using floating point numbers. I should use the Decimal library to increase the accuracy.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.