Git Product home page Git Product logo

tempera's Introduction

Tempera

Description

Create temperature objects which return their value in a set 'global' unit scale - either Celsius, Fahrenheit, or Kelvin - using the method getTemperature(). When the Global temperature scale is changed, all temperature objects are returned in that scale.

I created this module to easily convert multiple temperatures displayed on a GUI when a user selects a different scale. I imagine it could be useful any time one has multiple persistant temperatures that need to undergo unit conversion at will.

Using this Module

The Global temperature scale can be set with the method self.setGlobalScale(), which accepts a string representing a unit scale - either 'c', 'f', or 'k', or the full word ('celsius', etc). All Temperature objects will return in this scale with self.getTemperature().

Set or return from a specific scale using self.c for Celsius, self.f for Fahrenheit, and self.k for Kelvin.

See examples file for a more thorough outline of features.

Local Scales

If you want a specific Temperature object to return self.getTemperature() in a different scale regardless of the current global scale, use self.setLocalScale(). Can return to using global scale with self.setLocalScale(False) or self.useGlobalScale().

Rounding

Set the number of decimal places with the decimal_place keyword argument:

from tempera import Temperature

temp1 = Temperature(12, decimal_place=2)

Or with self.setDecimalPlace(int), where int is an integer. The default decimal place is 2. Setting to None will always return a rounded integer.

Intervals

Temperature objects can also represent intervals instead of actual temperatures with the keyword argument isinterval=True. For example, if you wanted to represent an interval of 3 celsius units:

temp_interval = Temperature(3, isinterval=True)

print(temp1.C + temp_interval.C)  # Adds 3 celsius to temp1 and prints

How it functions

The temperature is stored internally in celsius. All setting and getting of the temperature in different scales is a conversion from this 'private' celsius attribute. This attribute is not rounded. Any rounding is done when getTemperature() (or a similar method) is called, so setting a decimal place does not affect the internally stored temperature.

tempera's People

Watchers

 avatar

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.