示例#1
0
def migrate(replace=False,yearsback=10,dryrun=False):
    api = eeDbAPI()
    devices = api.getPeriphList()
    eetsdb  = eeTSDB('localhost',4242)
    client = RESTOpenTSDBClient("localhost",4242)
    for dev in devices:
        # check that the metric is in eetsdbMapping
        if not dev.periph_id in eetsdbMapping:
            print(("Skipping", dev.periph_id, dev.name, dev.room_name, dev.usage_name))
            continue
        # check if the TS is there already. If yes, look for the last point and continue from there
        ts = eetsdb.mkTimeseries(dev)
        if not dryrun: eetsdb.registerTS(ts)
        begin = datetime.now()-relativedelta(years=yearsback)
        try:
            res = client.search("LOOKUP",metric=ts.metric, tags=ts.tags)
            if res["totalResults"]>1 :
                print("Time series:")
                pprint.pprint(ts.getMap())
                print("Search result:")
                pprint.pprint(res)
                raise RuntimeError("The timeseries is ambiguous. This should not happen.")
            elif res["totalResults"]==1:
                tsuid = res["results"][0]["tsuid"]
                sq = OpenTSDBtsuidSubQuery("sum",[tsuid])
                if replace:
                    query = OpenTSDBQuery([sq],"%dy-ago"%yearsback,delete=True)
                    if not dryrun: answer = client.query(query)
                    begin = datetime.now()-relativedelta(years=yearsback)
                    time.sleep(5)
                else:
                    query = OpenTSDBQuery([sq],"%dy-ago"%yearsback)
                    answer = client.query(query)
                    if len(answer)>0:
                        last = max([ int(k) for k in list(answer[0]["dps"].keys()) ])
                        begin = datetime.fromtimestamp(last+1)
            # migrate that dev
            print(("migrating",dev.periph_id, dev.name, dev.room_name, dev.usage_name, "from", begin))
            if not dryrun: eetsdb.migrate(device=dev,start_date=begin, end_date=None)
        except OpenTSDBError as e:
            print(("Exception while processing",dev.periph_id, dev.name, dev.room_name, dev.usage_name,"Skipping."))
            raise
示例#2
0
def migrate(replace=False,yearsback=10):
    api = eeDbAPI()
    devices = api.getPeriphList()
    eetsdb  = eeTSDB('localhost',4242)
    client = RESTOpenTSDBClient("localhost",4242)
    for dev in devices:
        # check that the metric is in eetsdbMapping
        if not dev.periph_id in eetsdbMapping:
            print "Skipping", dev.periph_id, dev.name, dev.room_name, dev.usage_name
            continue
        # check if the TS is there already. If yes, look for the last point and continue from there
        ts = eetsdb.mkTimeseries(dev)
        eetsdb.registerTS(ts)
        begin = datetime.now()-relativedelta(years=yearsback)
        try:
            res = client.search("LOOKUP",metric=ts.metric, tags=ts.tags)
            if res["totalResults"]>1 :
                print "Time series:"
                pprint.pprint(ts.getMap())
                print "Search result:"
                pprint.pprint(res)
                raise RuntimeError("The timeseries is ambiguous. This should not happen.")
            elif res["totalResults"]==1:
                tsuid = res["results"][0]["tsuid"]
                sq = OpenTSDBtsuidSubQuery("sum",[tsuid])
                if replace:
                    query = OpenTSDBQuery([sq],"%dy-ago"%yearsback,delete=True)
                    answer = client.query(query)
                    begin = datetime.now()-relativedelta(years=yearsback)
                    time.sleep(5)
                else:
                    query = OpenTSDBQuery([sq],"%dy-ago"%yearsback)
                    answer = client.query(query)
                    if len(answer)>0:
                        last = max([ int(k) for k in answer[0]["dps"].keys() ])
                        begin = datetime.fromtimestamp(last+1)
            # migrate that dev
            print "migrating",dev.periph_id, dev.name, dev.room_name, dev.usage_name, "from", begin
            eetsdb.migrate(device=dev,start_date=begin, end_date=None)
        except OpenTSDBError as e:
            print "Exception while processing",dev.periph_id, dev.name, dev.room_name, dev.usage_name,"Skipping."
            raise
示例#3
0
文件: plot.py 项目: delaere/eedbsync
# -*- coding: utf8 -*-

from eedomus import findDevice
from eedb import eeDbAPI
import ROOT
from datetime import datetime
from dateutil.relativedelta import relativedelta


def graphFromHistory(history):
    time = ROOT.TDatime()
    graph = ROOT.TGraph()
    for i,(to,do) in enumerate(history):
        time.Set(do.strftime("%Y-%m-%d %H:%M:%S"))
        graph.SetPoint(i,time.Convert(),ROOT.Double(float(to)))
    return graph

api = eeDbAPI()
devs = api.getPeriphList()
temps = findDevice(devs,usage_name="Température")
outside = temps[0].getHistory()
inside = temps[3].getHistory()

c1 = ROOT.TCanvas()
gr = graphFromHistory(outside)
gr.Draw()

c2 = ROOT.TCanvas()
gr2 = graphFromHistory(inside)
gr2.Draw()
示例#4
0
文件: plot.py 项目: delaere/eedbsync
# -*- coding: utf8 -*-

from eedomus import findDevice
from eedb import eeDbAPI
import ROOT
from datetime import datetime
from dateutil.relativedelta import relativedelta


def graphFromHistory(history):
    time = ROOT.TDatime()
    graph = ROOT.TGraph()
    for i,(to,do) in enumerate(history):
        time.Set(do.strftime("%Y-%m-%d %H:%M:%S"))
        graph.SetPoint(i,time.Convert(),ROOT.Double(float(to)))
    return graph

api = eeDbAPI()
devs = api.getPeriphList()
temps = findDevice(devs,usage_name=u"Température")
outside = temps[0].getHistory()
inside = temps[3].getHistory()

c1 = ROOT.TCanvas()
gr = graphFromHistory(outside)
gr.Draw()

c2 = ROOT.TCanvas()
gr2 = graphFromHistory(inside)
gr2.Draw()