`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
```
[![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
File details
Details for the file django-timeseries-0.0.0.tar.gz
.
File metadata
- Download URL: django-timeseries-0.0.0.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b7f94f89324a2c51a0509ed30014b9552bb9688fc5aebb577f94852925ac8e6 |
|
MD5 | bbc3f16da9a3f4f63d846015dbbaf4de |
|
BLAKE2b-256 | f70a7ab8c09b6b53dc0de002112345f7ba2fdcd02388c198fb564ac024ca2b17 |