<!-- [](https://pypi.python.org/pypi/traces) -->
<!-- [](https://pypi.python.org/pypi/traces) -->
<!-- [](https://traces.readthedocs.io/en/master/?badge=master) -->
<!-- [](https://img.shields.io/github/v/release/stringertheory/traces) -->
[](https://github.com/stringertheory/traces/actions/workflows/main.yml?query=branch%3Amain)
[](https://codecov.io/gh/stringertheory/traces)
[](https://img.shields.io/github/commit-activity/m/stringertheory/traces)
# traces
A Python library for unevenly-spaced time series analysis.
## Why?
Taking measurements at irregular intervals is common, but most tools are
primarily designed for evenly-spaced measurements. Also, in the real
world, time series have missing observations or you may have multiple
series with different frequencies: it can be useful to model these as
unevenly-spaced.
Traces was designed by the team at
[Datascope](<[https://datascopeanalytics.com/](https://en.wikipedia.org/wiki/Datascope_Analytics)>) based on several practical
applications in different domains, because it turns out [unevenly-spaced
data is actually pretty great, particularly for sensor data
analysis](https://traces.readthedocs.io/).
## Installation
To install traces, run this command in your terminal:
```shell
$ pip install traces
```
## Quickstart: using traces
To see a basic use of traces, let's look at these data from a light
switch, also known as _Big Data from the Internet of Things_.

The main object in traces is a [TimeSeries](https://traces.readthedocs.io/en/master/api_reference.html#timeseries), which you
create just like a dictionary, adding the five measurements at 6:00am,
7:45:56am, etc.
```pycon
>>> time_series = traces.TimeSeries()
>>> time_series[datetime(2042, 2, 1, 6, 0, 0)] = 0 # 6:00:00am
>>> time_series[datetime(2042, 2, 1, 7, 45, 56)] = 1 # 7:45:56am
>>> time_series[datetime(2042, 2, 1, 8, 51, 42)] = 0 # 8:51:42am
>>> time_series[datetime(2042, 2, 1, 12, 3, 56)] = 1 # 12:03:56am
>>> time_series[datetime(2042, 2, 1, 12, 7, 13)] = 0 # 12:07:13am
```
What if you want to know if the light was on at 11am? Unlike a python
dictionary, you can look up the value at any time even if it's not one
of the measurement times.
```pycon
>>> time_series[datetime(2042, 2, 1, 11, 0, 0)] # 11:00am
0
```
The `distribution` function gives you the fraction of time that the
`TimeSeries` is in each state.
```pycon
>>> time_series.distribution(
>>> start=datetime(2042, 2, 1, 6, 0, 0), # 6:00am
>>> end=datetime(2042, 2, 1, 13, 0, 0) # 1:00pm
>>> )
Histogram({0: 0.8355952380952381, 1: 0.16440476190476191})
```
The light was on about 16% of the time between 6am and 1pm.
### Adding more data...
Now let's get a little more complicated and look at the sensor readings
from forty lights in a house.

How many lights are on throughout the day? The merge function takes the
forty individual `TimeSeries` and efficiently merges them into one
`TimeSeries` where the each value is a list of all lights.
```pycon
>>> trace_list = [... list of forty traces.TimeSeries ...]
>>> count = traces.TimeSeries.merge(trace_list, operation=sum)
```
We also applied a `sum` operation to the list of states to get the
`TimeSeries` of the number of lights that are on.

How many lights are on in the building on average during business hours,
from 8am to 6pm?
```pycon
>>> histogram = count.distribution(
>>> start=datetime(2042, 2, 1, 8, 0, 0), # 8:00am
>>> end=datetime(2042, 2, 1, 12 + 6, 0, 0) # 6:00pm
>>> )
>>> histogram.median()
17
```
The `distribution` function returns a [Histogram](https://traces.readthedocs.io/en/master/api_reference.html#histogram) that
can be used to get summary metrics such as the mean or quantiles.
### It's flexible
The measurements points (keys) in a `TimeSeries` can be in any units as
long as they can be ordered. The values can be anything.
For example, you can use a `TimeSeries` to keep track the contents of a
grocery basket by the number of minutes within a shopping trip.
```pycon
>>> time_series = traces.TimeSeries()
>>> time_series[1.2] = {'broccoli'}
>>> time_series[1.7] = {'broccoli', 'apple'}
>>> time_series[2.2] = {'apple'} # puts broccoli back
>>> time_series[3.5] = {'apple', 'beets'} # mmm, beets
```
## More info
To learn more, check the [examples](https://traces.readthedocs.io/en/master/examples.html) and the detailed [reference](https://traces.readthedocs.io/en/master/api_reference.html#).
## Contributing
Contributions are welcome and greatly appreciated! Please visit our [guidelines](https://github.com/datascopeanalytics/traces/blob/master/CONTRIBUTING.md)
for more info.
Raw data
{
"_id": null,
"home_page": "https://github.com/stringertheory/traces",
"name": "traces",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8",
"maintainer_email": null,
"keywords": null,
"author": "Mike Stringer",
"author_email": "mike.stringer.internet@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/bd/26/84a8fd19ba32a03bb669f03d836c76099100671e73f2fca9d73ae5c8e8c6/traces-0.6.4.tar.gz",
"platform": null,
"description": "<!-- [](https://pypi.python.org/pypi/traces) -->\n<!-- [](https://pypi.python.org/pypi/traces) -->\n<!-- [](https://traces.readthedocs.io/en/master/?badge=master) -->\n<!-- [](https://img.shields.io/github/v/release/stringertheory/traces) -->\n\n[](https://github.com/stringertheory/traces/actions/workflows/main.yml?query=branch%3Amain)\n[](https://codecov.io/gh/stringertheory/traces)\n[](https://img.shields.io/github/commit-activity/m/stringertheory/traces)\n\n# traces\n\nA Python library for unevenly-spaced time series analysis.\n\n## Why?\n\nTaking measurements at irregular intervals is common, but most tools are\nprimarily designed for evenly-spaced measurements. Also, in the real\nworld, time series have missing observations or you may have multiple\nseries with different frequencies: it can be useful to model these as\nunevenly-spaced.\n\nTraces was designed by the team at\n[Datascope](<[https://datascopeanalytics.com/](https://en.wikipedia.org/wiki/Datascope_Analytics)>) based on several practical\napplications in different domains, because it turns out [unevenly-spaced\ndata is actually pretty great, particularly for sensor data\nanalysis](https://traces.readthedocs.io/).\n\n## Installation\n\nTo install traces, run this command in your terminal:\n\n```shell\n$ pip install traces\n```\n\n## Quickstart: using traces\n\nTo see a basic use of traces, let's look at these data from a light\nswitch, also known as _Big Data from the Internet of Things_.\n\n\n\nThe main object in traces is a [TimeSeries](https://traces.readthedocs.io/en/master/api_reference.html#timeseries), which you\ncreate just like a dictionary, adding the five measurements at 6:00am,\n7:45:56am, etc.\n\n```pycon\n>>> time_series = traces.TimeSeries()\n>>> time_series[datetime(2042, 2, 1, 6, 0, 0)] = 0 # 6:00:00am\n>>> time_series[datetime(2042, 2, 1, 7, 45, 56)] = 1 # 7:45:56am\n>>> time_series[datetime(2042, 2, 1, 8, 51, 42)] = 0 # 8:51:42am\n>>> time_series[datetime(2042, 2, 1, 12, 3, 56)] = 1 # 12:03:56am\n>>> time_series[datetime(2042, 2, 1, 12, 7, 13)] = 0 # 12:07:13am\n```\n\nWhat if you want to know if the light was on at 11am? Unlike a python\ndictionary, you can look up the value at any time even if it's not one\nof the measurement times.\n\n```pycon\n>>> time_series[datetime(2042, 2, 1, 11, 0, 0)] # 11:00am\n0\n```\n\nThe `distribution` function gives you the fraction of time that the\n`TimeSeries` is in each state.\n\n```pycon\n>>> time_series.distribution(\n>>> start=datetime(2042, 2, 1, 6, 0, 0), # 6:00am\n>>> end=datetime(2042, 2, 1, 13, 0, 0) # 1:00pm\n>>> )\nHistogram({0: 0.8355952380952381, 1: 0.16440476190476191})\n```\n\nThe light was on about 16% of the time between 6am and 1pm.\n\n### Adding more data...\n\nNow let's get a little more complicated and look at the sensor readings\nfrom forty lights in a house.\n\n\n\nHow many lights are on throughout the day? The merge function takes the\nforty individual `TimeSeries` and efficiently merges them into one\n`TimeSeries` where the each value is a list of all lights.\n\n```pycon\n>>> trace_list = [... list of forty traces.TimeSeries ...]\n>>> count = traces.TimeSeries.merge(trace_list, operation=sum)\n```\n\nWe also applied a `sum` operation to the list of states to get the\n`TimeSeries` of the number of lights that are on.\n\n\n\nHow many lights are on in the building on average during business hours,\nfrom 8am to 6pm?\n\n```pycon\n>>> histogram = count.distribution(\n>>> start=datetime(2042, 2, 1, 8, 0, 0), # 8:00am\n>>> end=datetime(2042, 2, 1, 12 + 6, 0, 0) # 6:00pm\n>>> )\n>>> histogram.median()\n17\n```\n\nThe `distribution` function returns a [Histogram](https://traces.readthedocs.io/en/master/api_reference.html#histogram) that\ncan be used to get summary metrics such as the mean or quantiles.\n\n### It's flexible\n\nThe measurements points (keys) in a `TimeSeries` can be in any units as\nlong as they can be ordered. The values can be anything.\n\nFor example, you can use a `TimeSeries` to keep track the contents of a\ngrocery basket by the number of minutes within a shopping trip.\n\n```pycon\n>>> time_series = traces.TimeSeries()\n>>> time_series[1.2] = {'broccoli'}\n>>> time_series[1.7] = {'broccoli', 'apple'}\n>>> time_series[2.2] = {'apple'} # puts broccoli back\n>>> time_series[3.5] = {'apple', 'beets'} # mmm, beets\n```\n\n## More info\n\nTo learn more, check the [examples](https://traces.readthedocs.io/en/master/examples.html) and the detailed [reference](https://traces.readthedocs.io/en/master/api_reference.html#).\n\n## Contributing\n\nContributions are welcome and greatly appreciated! Please visit our [guidelines](https://github.com/datascopeanalytics/traces/blob/master/CONTRIBUTING.md)\nfor more info.\n",
"bugtrack_url": null,
"license": null,
"summary": "A Python library for unevenly-spaced time series analysis",
"version": "0.6.4",
"project_urls": {
"Documentation": "https://stringertheory.github.io/traces/",
"Homepage": "https://github.com/stringertheory/traces",
"Repository": "https://github.com/stringertheory/traces"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2f073cbcc1e6cc477545de1371591eda3a946a7ff20bf02cb32923a8a7b664f2",
"md5": "32d50681533af1288ffcda8938738aea",
"sha256": "7af3e9a0c16b83aa260da79bbc0a46ea494b2b15e022309c5ee15073f8f233cc"
},
"downloads": -1,
"filename": "traces-0.6.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "32d50681533af1288ffcda8938738aea",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8",
"size": 23172,
"upload_time": "2024-08-06T02:29:17",
"upload_time_iso_8601": "2024-08-06T02:29:17.551972Z",
"url": "https://files.pythonhosted.org/packages/2f/07/3cbcc1e6cc477545de1371591eda3a946a7ff20bf02cb32923a8a7b664f2/traces-0.6.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "bd2684a8fd19ba32a03bb669f03d836c76099100671e73f2fca9d73ae5c8e8c6",
"md5": "5c1af19451b7352e24fc2210baea63ec",
"sha256": "2f85999f05470071a388a38808debc691da8c4b11baafe6a40383299a2ff6cf6"
},
"downloads": -1,
"filename": "traces-0.6.4.tar.gz",
"has_sig": false,
"md5_digest": "5c1af19451b7352e24fc2210baea63ec",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8",
"size": 23757,
"upload_time": "2024-08-06T02:29:19",
"upload_time_iso_8601": "2024-08-06T02:29:19.214222Z",
"url": "https://files.pythonhosted.org/packages/bd/26/84a8fd19ba32a03bb669f03d836c76099100671e73f2fca9d73ae5c8e8c6/traces-0.6.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-06 02:29:19",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "stringertheory",
"github_project": "traces",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "traces"
}