Skip to main content

A package to provide tools to handle computations with datetime-like data.

Project description

Datetime Coordinates


This python package implements a feature allowing easy coding of datetime-like data without the annoyances of handling datetime-like data. Assim

It provides:

  • high level function decorator datetime_coords
  • lower level class DateTimeCoord for building other more customized decorators.
  • a marker DatetimeLike to indicate which data should be seen as datetime-like.

Installation

Within your python enviroment type

pip install dtcoords

Usage

This simplest way of using it is applying directly the decorator into a function wherein datetime-like data is been processed.

There is only a short protocol to be followed:

  • datetime-like parameters must be argument in a function (whether positional or keyword) and be typehinted with the special marker DatetimeLike provided by the package.

  • function must be defined as generic dictionary kws arguments or the special reserved keys: _unit; _ref or both.

    • valid units for _unit parameter are the ones supported by numpy datetime dtype (numpy datetime units)
    • _ref should be datetime-like and represents the "zeroth" location on the coordinates to which the data is been referenced under the hood.
  • As of now, nesting Datetimelike in Sequence or similar, won't do no good.

Quickstart

Let's have a basic function computing velocity as an average speed. The function should implement the following reasoning:

$$ v_{avg} = (x_2 - x_1) / (t_2 - t_1) $$

Start off by importing basic objects

from dtcoords import datetime_coords, DatetimeLike

They are meant to be used together.

@datetime_coords
def compute_average_seed(t1: DatetimeLike, x1: float, t2: DatetimeLike, x2: float, **kwargs) -> float:
    delta_x = x2 - x1
    delta t = t2 - t1
    return delta_x / delta_t

Note that t1 and t2 are supposed to be datetime-like as a pandas Timestamp or the builtin python datetime, nonetheless within the code they can be regarded as just common numeric data. Thus the code becomes more aligned with how human brain thinks regarding time as quantity. So, regular operations are readily used and the return number is an ordinary float.

The function could then be called within a script as

import datetime
t1 = datetime.datetime(...)
t2 = datetime.datetime(...)
x1: float = ...
x2: float = ...

if x's are given in meters (for instance), then we are determinig our average speed in meters per seconds by requiring computation to be run with time unit in seconds s.

avg_speed = compute_average_speed(t1, x1, t2, x2, _unit='s')

autor: Conrado

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

datetimecoords-0.1.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

datetimecoords-0.1.0-py2.py3-none-any.whl (5.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file datetimecoords-0.1.0.tar.gz.

File metadata

  • Download URL: datetimecoords-0.1.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for datetimecoords-0.1.0.tar.gz
Algorithm Hash digest
SHA256 640921214c60721567ecad03f1470ce3aae6e1027eebce017a571efc4dcef5f0
MD5 bbb56ca1cbf5b811ac09a034d1a190f3
BLAKE2b-256 f92939d50dbfb46815902131d4df371491532e8d97a23a3158f307465136e064

See more details on using hashes here.

File details

Details for the file datetimecoords-0.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for datetimecoords-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 990a1167a866bea61124aec573bb7682ce39ececaf39d53e07ee8493437aed82
MD5 4089ff38569711902b863267c61f0c50
BLAKE2b-256 9fc26810595f1179344cb3d99a214fae3098c0cd7a93daa0df86fc5b32b3b6ac

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