Esempio n. 1
0
    def _generate_chart_data(self, granularity, count):

        counts = []
        time_series_limits = time_series_generator(granularity, count)

        def _compute_count(a_range):
            column_start = convert_time_to_uuid(a_range[0], lowest_val=True)
            # start_datetime = utc_timestamp2datetime(a_range[0])
            column_finish = convert_time_to_uuid(a_range[1], lowest_val=False)
            # end_datetime = utc_timestamp2datetime(a_range[1])
            row_key = ymd_from_epoch(float(a_range[0]))
            count = self._get_cf_logs().get_count(
                row_key,
                column_start=column_start,
                column_finish=column_finish)

            return count # to be used by `_json_cache()`

        for a_range in time_series_limits:
            start_datetime = utc_timestamp2datetime(a_range[0])
            end_datetime = utc_timestamp2datetime(a_range[1])

            # Whe shouldn't use cache for the last period
            if self._cache_enabled and a_range != time_series_limits[-1]:
                cache_key = "daedalus:chart:{0}-{1}".format(a_range[0], a_range[1])
                count = _json_cache(cache_key,
                    60,
                    _compute_count, a_range)
            else:
                count = _compute_count(a_range)

            counts.append((start_datetime, end_datetime, count,))

        return counts
Esempio n. 2
0
    def _generate_chart_data(self, granularity, count):

        counts = []
        time_series_limits = time_series_generator(granularity, count)

        def _compute_count(a_range):
            column_start = convert_time_to_uuid(a_range[0], lowest_val=True)
            # start_datetime = utc_timestamp2datetime(a_range[0])
            column_finish = convert_time_to_uuid(a_range[1], lowest_val=False)
            # end_datetime = utc_timestamp2datetime(a_range[1])
            row_key = ymd_from_epoch(float(a_range[0]))
            count = self._get_cf_logs().get_count(row_key,
                                                  column_start=column_start,
                                                  column_finish=column_finish)

            return count  # to be used by `_json_cache()`

        for a_range in time_series_limits:
            start_datetime = utc_timestamp2datetime(a_range[0])
            end_datetime = utc_timestamp2datetime(a_range[1])

            # Whe shouldn't use cache for the last period
            if self._cache_enabled and a_range != time_series_limits[-1]:
                cache_key = "daedalus:chart:{0}-{1}".format(
                    a_range[0], a_range[1])
                count = _json_cache(cache_key, 60, _compute_count, a_range)
            else:
                count = _compute_count(a_range)

            counts.append((
                start_datetime,
                end_datetime,
                count,
            ))

        return counts
Esempio n. 3
0
def main():
    d_now = datetime.datetime.now()
    d_utcnow = datetime.datetime.utcnow()

    d_now_tz = d_now.replace(tzinfo=pytz.utc)
    d_utcnow_tz = d_utcnow.replace(tzinfo=pytz.utc)

    dates = (
        ("d_now", d_now),
        ("d_now_tz", d_now_tz),
        ("d_utcnow", d_utcnow),
        ("d_utcnow_tz", d_utcnow_tz),
    )

    print "{0:>30}: {1}".format("TZ", os.environ.get('TZ', ''))
    print "{0:>30}: {1}".format("time.time()", time.time())
    print ""

    for desc, date_var in dates:
        timestamp = "{0}.{1:06}".format(calendar.timegm(date_var.timetuple()),
                                        date_var.microsecond)
        from_timestamp = time.gmtime(float(timestamp))
        print "{0:>30}".format(desc)
        print "{0:>30}: {1}".format("type()", type(date_var))
        print "{0:>30}: {1}".format("str()", str(date_var))
        print "{0:>30}: {1}".format("utctimetuple()", date_var.utctimetuple())
        print "{0:>30}: {1}".format("calendar.timegm()",
                                    calendar.timegm(date_var.timetuple()))
        print "{0:>30}: {1}".format("microsecond", date_var.microsecond)
        print "{0:>30}: {1}".format("timestamp", timestamp)
        print "{0:>30}: {1}".format("from_timestamp", from_timestamp)
        print "{0:>30}: {1}".format("type(from_timestamp)",
                                    type(from_timestamp))
        print "{0:>30}: {1}".format(
            "datetime.utcfromtimestamp()",
            datetime.datetime.utcfromtimestamp(float(timestamp)))
        print ""

    current_utc_str_timestamp = utc_str_timestamp()
    print "utc_str_timestamp():", current_utc_str_timestamp
    print " + de-serialized:", utc_timestamp2datetime(
        current_utc_str_timestamp)
Esempio n. 4
0
def main():
    d_now = datetime.datetime.now()
    d_utcnow = datetime.datetime.utcnow()

    d_now_tz = d_now.replace(tzinfo=pytz.utc)
    d_utcnow_tz = d_utcnow.replace(tzinfo=pytz.utc)

    dates = (
        ("d_now", d_now),
        ("d_now_tz", d_now_tz),
        ("d_utcnow", d_utcnow),
        ("d_utcnow_tz", d_utcnow_tz),
    )

    print "{0:>30}: {1}".format("TZ", os.environ.get('TZ', ''))
    print "{0:>30}: {1}".format("time.time()", time.time())
    print ""

    for desc, date_var in dates:
        timestamp = "{0}.{1:06}".format(calendar.timegm(date_var.timetuple()), date_var.microsecond)
        from_timestamp = time.gmtime(float(timestamp))
        print "{0:>30}".format(desc)
        print "{0:>30}: {1}".format("type()", type(date_var))
        print "{0:>30}: {1}".format("str()", str(date_var))
        print "{0:>30}: {1}".format("utctimetuple()", date_var.utctimetuple())
        print "{0:>30}: {1}".format("calendar.timegm()", calendar.timegm(date_var.timetuple()))
        print "{0:>30}: {1}".format("microsecond", date_var.microsecond)
        print "{0:>30}: {1}".format("timestamp", timestamp)
        print "{0:>30}: {1}".format("from_timestamp", from_timestamp)
        print "{0:>30}: {1}".format("type(from_timestamp)", type(from_timestamp))
        print "{0:>30}: {1}".format("datetime.utcfromtimestamp()",
            datetime.datetime.utcfromtimestamp(float(timestamp)))
        print ""

    current_utc_str_timestamp = utc_str_timestamp()
    print "utc_str_timestamp():", current_utc_str_timestamp
    print " + de-serialized:", utc_timestamp2datetime(current_utc_str_timestamp)