Example #1
0
    def get(self):
        user = users.get_current_user()
        admin = users.is_current_user_admin()

        AggregateCounterDict.aggregate_stats(LOCAL)

        return {}
Example #2
0
    def post(self):
        cls = self.__class__
        stats = {}
        # todo: define this limit properly.
        work_list = cls.FJ_Queue.pop_request(self.request)
        logging.info("work list len: " + str(len(work_list)))

        def calc_stat(acc, tvs):
            for tv in tvs:
                k = tv[0]
                if k not in acc:
                    acc[k] = (0, 0)

                c, v = acc[k]
                acc[k] = (c + 1, v + tv[1])

            return

        def accumulate(acc, cnts):
            for i in ["aggregate", "timeline"]:
                if i not in acc:
                    acc[i] = {}

                for j in cnts[i]:
                    if j not in acc[i]:
                        acc[i][j] = {}
                    for k in cnts[i][j]:
                        if k not in acc[i][j]:
                            acc[i][j][k] = {}
                        calc_stat(acc[i][j][k], cnts[i][j][k])

        # todo: calculate the stats first. and then read and udpate the current
        # values.
        for w in work_list:
            d = json.loads(str(w.data))
            i = int(d["ph_id"])
            if i not in stats:
                stats[i] = {}

            logging.info(cls.calc_req_tag_val(d))
            accumulate(stats[i], cls.calc_req_tag_val(d))

        # delete the work, because otherwise it eats on datastore quota.
        db.delete(work_list)

        logging.info("stats ")
        logging.info(stats)
        AggregateCounterDict.update_with_stats(stats)
        return