def prepare()

in mozetl/graphics/graphics_telemetry_trends.py [0:0]


    def prepare(self):
        self.cache = self.fetch_json()
        if self.cache is None:
            self.cache = {"created": jstime(datetime.datetime.utcnow()), "trend": []}

        # Make sure trends are sorted in ascending order.
        self.cache["trend"] = self.cache["trend"] or []
        self.cache["trend"] = sorted(self.cache["trend"], key=lambda o: o["start"])

        if len(self.cache["trend"]) and not ForceMaxBackfill:
            last_data_point = self.cache["trend"][-1]
            last_data_point_start = datetime.datetime.utcfromtimestamp(
                last_data_point["start"]
            )
            last_data_point_end = datetime.datetime.utcfromtimestamp(
                last_data_point["end"]
            )
            print(last_data_point, last_data_point_start, last_data_point_end)
            if last_data_point_end - last_data_point_start < datetime.timedelta(7):
                # The last data point had less than a full week, so we stop at the
                # previous week, and remove the incomplete datapoint.
                self.lastFullWeek = last_data_point_start - datetime.timedelta(7)
                self.cache["trend"].pop()
            else:
                # The last data point covered a full week, so that's our stopping
                # point.
                self.lastFullWeek = last_data_point_start
                print(self.lastFullWeek)

        return True