Git Product home page Git Product logo

totemp's Introduction

To Temp logo

ToTemp

package version license pre-commit.ci Documentation Status

ToTemp is a temperature conversion package with Celsius, Delisle, Fahrenheit, Kelvin, Rankine, Réaumur, Newton and Rømer scales.

For more information read the docs.

This package aims to bring the simple and straight to the point, but precise, Object Oriented experience of working with temperature scale data types.


Usage

First of all, install the package:

pip install totemp

or, to have an example in poetry environments:

poetry add totemp

For more information, read the docs: [ToTemp Docs]('insert link here')

The instances:

from totemp import Celsius, Fahrenheit

if __name__ == '__main__':
    temps: list = [Celsius(12), Celsius(25), Celsius(50)]
    print(temps[0])  # '12 ºC'
    print(temps)  # [Celsius(12), Celsius(25), Celsius(50)]

    temps = list(map(Celsius.to_fahrenheit, temps))
    print(temps[0])  # '53.6 ºF'
    print(temps)  # [Fahrenheit(53.6), Fahrenheit(77.0), Fahrenheit(122.0)]

It's representations and properties:

Property symbol is read-only.

from totemp import Fahrenheit

if __name__ == '__main__':
    temp0 = Fahrenheit(53.6)
    print(temp0.__repr__())  # 'Fahrenheit(53.6)'
    print(temp0.__str__())  # '53.6 ºF'
    print(temp0.symbol)  # 'ºF'
    print(temp0.value)  # 53.6

Comparision operations ('==', '!=', '>', '>=', '<',...):

The comparision/arithmetic implementation attempts to convert the value of other (if it is a temperature instance) and then evaluate the expression.

import totemp as tp

if __name__ == '__main__':
    temp0, temp1 = tp.Celsius(0), tp.Fahrenheit(32)

    print(f'temp0: {repr(temp0)}')  # Celsius(0)
    print(f'temp1: {repr(temp1.to_celsius())}')  # Celsius(0.0)

    print(temp0 != temp1)  # False

    print(temp0 > temp1)  # False

    print(temp0 < temp1)  # False

    print(temp0 >= temp1)  # True

    print(temp0 <= temp1)  # True

    print(temp0 == temp1)  # True

Arithmetic operations ('+', '-', '*', '**', '/', '//', '%', ...):

from totemp import Newton, Rankine

if __name__ == '__main__':
    temp0 = Newton(33)
    temp1 = Rankine(671.67)

    temp2 = temp0 + temp1

    print('temp2:', temp2)  # temp2: 65.99999999999999 ºN
    print('temp2:', repr(temp2))  # temp2: Newton(65.99999999999999)
    print('temp2:', temp2.value, temp2.symbol)  # temp2: 65.99999999999999 ºN

    print((temp0 + temp1).rounded())  # 66 ºN
    print(repr((temp0 + temp1).rounded()))  # Newton(66)

    print(temp2 + 12.55)  # 78.54999999999998 ºN
    print((12 + temp2.rounded()))  # 78 ºN

ToTemp classes can work with many built-in Python functions:

from math import floor, ceil, trunc

from totemp import Reaumur

if __name__ == '__main__':
    temp = Reaumur(100.4)

    float(temp)  # 100.4
    int(temp)  # 100
    round(temp)  # Reaumur(100)
    abs(temp)  # Reaumur(100)
    floor(temp)  # Reaumur(100)
    ceil(temp)  # Reaumur(101)
    trunc(temp)  # Reaumur(100)
    divmod(temp, temp0 := Reaumur(25.1))  # (Reaumur(4.0), Reaumur(0.0))

Temperature Instance Conversions:

import totemp

if __name__ == '__main__':
    temp = totemp.Fahrenheit(32)

    print(temp.to_celsius())  # 0.0 ºC
    print(temp.to_fahrenheit())  # 32 ºF
    print(temp.to_delisle())  # 150.0 ºDe
    print(temp.to_kelvin())  # 273.15 K
    print(temp.to_newton())  # 0.0 ºN
    print(temp.to_rankine())  # 491.67 ºR
    print(temp.to_reaumur())  # 0.0 ºRé
    print(temp.to_romer())  # 7.5 ºRø

Changelog


  • 0.1.0:

    • Yanked, not functional;
  • 0.2.0:

    • Functional;
    • Can convert Celsius to Delisle, Fahrenheit, Kelvin, Newton, Rankine, Réaumur and Rømer.
  • 0.3.0:

    • Changed methods implementations and adds Fahrenheit conversions;
      • <scale_value> parameter is now positional-only;
      • Adds new parameter -> float_ret -> Float Return (True by default, keyword-only);
      • Celsius class methods were updated and enhanced;
      • Can now convert Fahrenheit to Celsius, Delisle, Kelvin, Newton, Rankine, Réaumur and Rømer.
  • 0.4.0:

    • There are two new Classes, Kelvin and Delisle, functional and ready-to-use.
  • 0.5.1:

    • The implementation has been completely refactored:

      1 - All classes inhehits from AbstractTemperature (our new abstract Base Class);

      2 - All classes now available:

      • Celsius;
      • Fahrenheit;
      • Delisle;
      • Kelvin;
      • (*New) Newton;
      • (*New) Rankine;
      • (*New) Réaumur;
      • (*New) Rømer.

      3 - New features:

      • The majority of Python's built-in functions works with the instances;
      • More pythonic properties and methods implementations;
      • Arithmetic operations;
      • Comparision operations;
      • convert_to() method;

      4 - Removals:

      • precise() method;
      • float_ret() param;
      • differentiating int/float;

      5 - Known problemns:

      • pow() doesn't work as intended;

License

For more information, check LICENSE file.

totemp's People

Contributors

daniil-berg avatar davilos avatar eddyyxxyy avatar pre-commit-ci[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

totemp's Issues

Adapt Kelvin Class implementation for all convertions and tests

On Branch Develop-0.5.0

Features to be changed in Kelvin Class:

  • to_celsius()
  • to_fahrenheit()
  • to_delisle()
  • to_newton()
  • to_rankine()
  • to_reaumur()
  • to_romer()

And change tests to all those methods, it will be 2 tests per method:

  • Dynamic Type Return test;
  • Precise and Rounded Return checks.

Adapt Celsius Class implementation for all convertions and tests

On Branch Develop-0.5.0

Features to be changed in Celsius Class:

  • to_fahrenheit()
  • to_delisle()
  • to_kelvin()
  • to_newton()
  • to_rankine()
  • to_reaumur()
  • to_romer()

And change tests to all those methods, it will be 2 tests per method:

  • Dynamic Type Return test;
  • Precise and Rounded Return checks.

Implement Rømer Class methods for all convertions and tests

For 0.5.0 version
Features to be implemented in Rømer Class:

  • to_celsius()
  • to_fahrenheit()
  • to_delisle()
  • to_kelvin()
  • to_newton()
  • to_rankine()
  • to_reaumur()

And 2 tests to all those methods:

  • Dynamic Type Return test;
  • Precise and Rounded Return checks.

Adapt Fahrenheit Class implementation for all convertions and tests

On Branch Develop-0.5.0

Features to be changed in Fahrenheit Class:

  • to_celsius()
  • to_delisle()
  • to_kelvin()
  • to_newton()
  • to_rankine()
  • to_reaumur()
  • to_romer()

And change tests to all those methods, it will be 2 tests per method:

  • Dynamic Type Return test;
  • Precise and Rounded Return checks.

Adapt Newton Class implementation for all convertions and tests

On Branch Develop-0.5.0

Features to be changed in Newton Class:

  • to_celsius()
  • to_fahrenheit()
  • to_delisle()
  • to_kelvin()
  • to_rankine()
  • to_reaumur()
  • to_romer()

And change tests to all those methods, it will be 2 tests per method:

  • Dynamic Type Return test;
  • Precise and Rounded Return checks.

Implement Réaumur Class methods for all convertions and tests

For future releases

Features to be implemented in Réaumur Class:

  • to_celsius()
  • to_fahrenheit()
  • to_delisle()
  • to_kelvin()
  • to_newton()
  • to_rankine()
  • to_romer()

And 2 tests to all those methods:

  • Dynamic Type Return test;
  • Precise and Rounded Return checks.

Adapt Delisle Class implementation for all convertions and tests

On Branch Develop-0.5.0

Features to be changed in Delisle Class:

  • to_celsius()
  • to_fahrenheit()
  • to_kelvin()
  • to_newton()
  • to_rankine()
  • to_reaumur()
  • to_romer()

And change tests to all those methods, it will be 2 tests per method:

  • Dynamic Type Return test;
  • Precise and Rounded Return checks.

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.