예제 #1
0
파일: models.py 프로젝트: ciju/perf-hier
        def updt_fn(stat, cnts):
            for dimp in stat:
                ts = utils.str2ts(dimp)
                ms = utils.month_start(now=ts)

                for dims in stat[dimp]:
                    if dims not in cnts:
                        cnts[dims] = []
                    updt_cnts(cnts[dims], stat[dimp][dims], ts, ms)

            # get the time stamp.
            # for each of the tags, append the time stamp with the cnt and value.

            # todo: stat has the timestamp and corresponding [cnt, val] for the
            # stats to be updated. find out the corresponding place and update
            # them if they exist. else create the place in timeline without any
            # gap.

            # calculate the index from the timestamp.
            return cnts
예제 #2
0
파일: models.py 프로젝트: ciju/perf-hier
    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