Esempio n. 1
0
    def get_dim_and_met(cls, req, time):
        d = cls.get_non_meta_dimentions_and_metrics(req)
        m = cls.get_meta_dimentions(datetime.datetime.fromtimestamp(time))

        default = [(slashify("aggregate", i[0]), i[1]) for i in d]
        meta = [(slashify("timeline", i[0], i[1], j[0]), j[1]) for i in d for j in m]

        return {"aggregate": default, "timeline": meta}
Esempio n. 2
0
    def get_dimentions(cls, proj):
        h = {}
        for i in cls.keys_with_prefix(cls.get_key(proj, slashify(proj))):
            d = i.key().name().split("/")[-1]
            h[d] = [j for j in json.loads(i.stat)]

        return h
Esempio n. 3
0
    def get_timeline(cls, proj, typ, tag=None):
        # todo: the f**k, how could u hard code these things.
        prv_obj = cls.get_obj(proj, utils.slashify(typ, "hour_by_month", utils.month_tag(utils.last_month())))
        obj = cls.get_obj(proj, utils.slashify(typ, "hour_by_month", utils.month_tag()))

        def fill_entries(lst, ms, hrs):
            if len(lst) < last_month_hrs:
                lst.extend([str(utils.add_hrs(j, ms)), [0, 0]] for j in range(len(lst), last_month_hrs))
            return lst

        last_month_hrs = utils.last_month().day * 24
        ms = utils.month_start(now=utils.last_month())

        def normalize(res, ms, last_month_hrs):
            for i in res:
                res[i] = fill_entries(res[i], ms, last_month_hrs)
            return res

        if not prv_obj and not obj:
            return {}

        if prv_obj:
            res = normalize(json.loads(prv_obj.stat), ms, last_month_hrs)

        if obj:
            nres = json.loads(obj.stat)
            if not prv_obj:
                res = nres
            else:
                for t in nres:
                    if not t in res:
                        res[t] = fill_entries([], ms, last_month_hrs)
                    res[t].extend(nres[t])

        if tag:
            return res[tag]

        return res
Esempio n. 4
0
    def get_hierarchy(cls, tag=''):
        hier = {}
        def update_hier(tag):
            lh = hier
            entries = tag.split('/')
            for e in entries:
                if not e in lh:
                    lh[e] = {}
                lh = lh[e]

        for t in Tags.all():
            update_hier( utils.slashify(t.tag) )

        return hier
Esempio n. 5
0
    def calc_req_tag_val(cls, req):
        "(dimention, (tag,value)) pairs"
        ph_id = req.get("ph_id")
        log(json.loads(req.get("data")))
        entries = cls.__entry_list(json.loads(req.get("data")))
        cats = Dimentions.get_dim_and_met(req, req.get("time"))

        result = {"aggregate": {}, "timeline": {}}
        for i in ["aggregate", "timeline"]:
            res = result[i]
            stat = cats[i]
            for c in stat:
                typ = slashify(ph_id, c[0])
                if typ in res:
                    logging.error(" the string should be unique for a single request:" + typ)
                res[typ] = {c[1]: entries}

        return result
Esempio n. 6
0
 def get_dimentions(cls):
     d = cls.get_non_meta_dimentions()
     m = cls.meta_dimentions
     return [slashify(i) for i in d] + [slashify(i, j) for i in d for j in m]
Esempio n. 7
0
 def get_key(cls, proj, typ):
     return "stat:timeline:" + slashify(str(proj), typ)
Esempio n. 8
0
 def get_key(cls, proj, typ):
     return "stat:aggregate:" + slashify(str(proj), typ)
Esempio n. 9
0
 def rpc_get_csv_timelines(self, project, typ="general/aggregate", tag=None):
     return Timeline.get_timeline(project.ph_id, slashify(project.ph_id, "timeline", typ), tag)
Esempio n. 10
0
 def rpc_get_aggregate_metrics(self, project, typ="general/aggregate"):
     d, m = typ.split("/")
     res = Aggregate.get_aggregate(project.ph_id, slashify(project.ph_id, "aggregate", d))
     return res[m]