Skip to main content

`timeseries`.

Project description

# TimeSeries

[![Build Status](https://travis-ci.org/anthonyalmarza/timeseries.svg?branch=master)](https://travis-ci.org/anthonyalmarza/timeseries)

`timeseries` is a set django application tools designed to facilitate the
collation and maintenance of timeseries data.

## Requirements

Django v1.8+ are supported for projects running on PostgreSQL.

## Installation

`pip install django-timeseries`

## Usage

```python
from datetime import timedelta
from django.db import models
from timeseries.models import TimeSeriesModel, TimeSeriesManager


class Ad(models.Model):

objects = TimeSeriesManager()


class RawAdData(TimeSeriesModel):

TIMESERIES_INTERVAL = timedelta(days=1) # update daily N.B integers in seconds also work

NOT_AVAILABLE = -1

ad = models.ForeignKey(Ad, related_name='rawdata')

views = models.BigIntegerField(default=NOT_AVAILABLE)
clicks = models.BigIntegerField(default=NOT_AVAILABLE)


class MonthlyAdReport(TimeSeriesModel):

TIMESERIES_INTERVAL = timedelta(days=28)

ad = models.ForeignKey(Ad, related_name='monthlyreports')

avg_view_growth = models.FloatField()
avg_click_growth = models.FloatField()


def ad_data_collector(queryset):
"""
should return an iterable that yields dictionaries of data
needed to successfully create a RawAdData instance
"""
return ...


def report_data_collector(queryset):
"""
should return an iterable that yields dictionaries of data
needed to successfully create a MonthlyAdReport instance
"""
return ...


# in a shell
>>> Ad.objects.update_timeseries('rawdata', ad_data_collector)
# this return the results of a bulk_create call from the RawAdData manager
# for ads that hadn't been updated in the last day

>>> Ad.objects.update_timeseries('monthlyreports', report_data_collector)
# this return the results of a bulk_create call from the MonthlyAdReport
# manager for ads that hadn't had a report generated in the last 28 days

>>> ad = Ad.objects.prefetch_latest('rawdata', 'monthlyreports').first()
>>> print ad.latest_rawaddata, ad.latest_monthlyreports

```

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

django-timeseries-0.0.0.tar.gz (3.5 kB view details)

Uploaded Source

File details

Details for the file django-timeseries-0.0.0.tar.gz.

File metadata

File hashes

Hashes for django-timeseries-0.0.0.tar.gz
Algorithm Hash digest
SHA256 2b7f94f89324a2c51a0509ed30014b9552bb9688fc5aebb577f94852925ac8e6
MD5 bbc3f16da9a3f4f63d846015dbbaf4de
BLAKE2b-256 f70a7ab8c09b6b53dc0de002112345f7ba2fdcd02388c198fb564ac024ca2b17

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page