Ejemplo n.º 1
0
    def _aggregate_stats_for_proj(cls, p, till_b4_hr, now, local=False):
        from_hr = p.last_hr  # last hr when stats were taken
        if from_hr is None:
            from_hr = utils.hr_before(4)  # todo: wtf
        from_hr += datetime.timedelta(hours=1)

        log(from_hr, till_b4_hr, now)
        if local:  # just for testing.
            till_b4_hr += datetime.timedelta(hours=1)
            from_hr = utils.hr_before(1)

        while from_hr < till_b4_hr:
            hr_stats = cls.get_hour_stats(p.key().id(), from_hr)
            if hr_stats:
                log("----------")
                logging.info(
                    "#### aggregate - [(project) "
                    + p.name
                    + "  till: "
                    + str(till_b4_hr)
                    + "]  [(hr) "
                    + str(from_hr.hour)
                    + "]  "
                    + str(len(hr_stats))
                )
                aggregate = hr_stats["aggregate"]
                timeline = hr_stats["timeline"]

                for i in aggregate:
                    Aggregate.save_aggregate(p.key().id(), i, aggregate[i])

                for i in timeline:
                    Timeline.save_timeline(p.key().id(), i, timeline[i])

            p.last_hr = from_hr
            from_hr += datetime.timedelta(hours=1)
Ejemplo n.º 2
0
    def aggregate_stats(cls, local=False):
        """Aggregate hourly stats, to the main stats
        """
        now = datetime.datetime.now()
        if now.minute > 15 or local:
            hrd = 0
        else:
            hrd = 1

        till_b4_hr = utils.hr_before(hr_delta=hrd, now=now)

        for p in Project.all().fetch(PROJECT_LIMIT):
            try:
                cls._aggregate_stats_for_proj(p, till_b4_hr, now, local)
            finally:
                p.put()