File: aggregates.py

package info (click to toggle)
python-django-timescaledb 0.2.13-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 304 kB
  • sloc: python: 512; sh: 20; makefile: 6; sql: 4
file content (40 lines) | stat: -rw-r--r-- 1,099 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from django.db import models
from django.contrib.postgres.fields import ArrayField
from django.db.models.fields import FloatField


class Histogram(models.Aggregate):
    """
    Implementation of the histogram function from Timescale. 

    Read more about it here - https://docs.timescale.com/latest/using-timescaledb/reading-data#histogram

    Response:

    <TimescaleQuerySet [{'histogram': [0, 0, 0, 87, 93, 125, 99, 59, 0, 0, 0, 0], 'device__count': 463}]>

    """
    function = 'histogram'
    name = 'histogram'
    output_field = ArrayField(models.FloatField())

    def __init__(self, expression, min_value, max_value, bucket):
        super().__init__(expression, min_value, max_value, bucket)


class Last(models.Aggregate):
    function = 'last'
    name = 'last'
    output_field = FloatField()

    def __init__(self, expression, bucket):
        super().__init__(expression, bucket)


class First(models.Aggregate):
    function = 'first'
    name = 'first'
    output_field = FloatField()

    def __init__(self, expression, bucket):
        super().__init__(expression, bucket)