Skip to content

Commit

Permalink
Add generateseties_*_fast versions for fast stats display at Dashboard.
Browse files Browse the repository at this point in the history
  • Loading branch information
rkorzeniewski committed Dec 15, 2017
1 parent a258aa9 commit cc3950b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions libs/statistic.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,34 @@ def generate_series_stats(parname=None, starttime=None, endtime=None, hours=1, n
return data


def generate_series_nvalue_fast(parname=None, npoints=0, div=1):
if parname is None or npoints == 0:
return None
if div == 0:
div = 1
query = StatData.objects.filter(parid__name=parname).order_by('-time')[:npoints]
rev = reversed(query)
data = []
for i in rev:
timestamp = int((i.time - datetime(1970, 1, 1)).total_seconds() * 1000)
data.append([timestamp, i.nvalue / div])
return data


def generate_series_fvalue_fast(parname=None, npoints=0, div=1):
if parname is None or npoints == 0:
return None
if div == 0:
div = 1
query = StatData.objects.filter(parid__name=parname).order_by('-time')[:npoints]
rev = reversed(query)
data = []
for i in rev:
timestamp = int((i.time - datetime(1970, 1, 1)).total_seconds() * 1000)
data.append([timestamp, i.fvalue / div])
return data


def generate_series_job(name=None, level='F', npoints=0, field=None, div=1):
if name is None or npoints == 0 or field is None:
return None
Expand Down

0 comments on commit cc3950b

Please sign in to comment.