Ejemplo n.º 1
0
 def scalar_plotpoints(
     cls, pk, dimensions=None, metrics=None, depth=0, period=None, flot_time=False, points_type=dict
 ):
     metrics = metrics or ["hits"]
     if isinstance(metrics, basestring):
         metrics = [metrics]
     period = Period.get(period)
     sparse = cls.whale_driver().retrieve(pk, dimensions, metrics, period=period)
     nonsparse = defaultdict(dict)
     if flot_time:
         points_type = list
     for dim, mets in sparse.items():
         for met, points in mets.items():
             dts = period.datetimes_strs()
             nonsparse[dim][met] = []
             for dt in dts:
                 if flot_time:
                     dt_t = to_flot_time(Period.parse_dt_str(dt))
                 else:
                     dt_t = dt
                 value = points[dt] if dt in points else 0
                 nonsparse[dim][met].append([dt_t, float(value)])
             nonsparse[dim][met] = points_type(nonsparse[dim][met])
     if depth > 0:
         for sub in cls.get_subdimensions(pk, dimensions):
             nonsparse = dict(
                 nonsparse.items()
                 + cls.plotpoints(
                     pk, sub, metrics, depth=depth - 1, period=period, flot_time=flot_time, points_type=points_type
                 ).items()
             )
     return nonsparse
Ejemplo n.º 2
0
 def plotpoints(cls, pk, dimensions=None, metrics=None,
         period=None, overall=True):
     metrics = metrics or ['hits',]
     period = period or Period.default_size()
     sparse = cls.whale_driver().retrieve(pk,dimensions,metrics,
             period=period, overall=overall)
     nonsparse = defaultdict(dict)
     for dimensions, metrics in sparse.items():
         for metric, points in metrics.items():
             dts = Period(*period.split('x')).datetimes_strs()
             nonsparse[dimensions][metric] = []
             for dt in dts:
                 flot_time = to_flot_time(Period.parse_dt_str(dt))
                 value = points[dt] if dt in points else 0
                 nonsparse[dimensions][metric].append([flot_time,
                     float(value)])
     return nonsparse
Ejemplo n.º 3
0
 def plotpoints(self, categories=None, dimensions=None, metrics=None,
         period=None, depth=0):
     categories = categories or ''
     dimensions = dimensions or json.dumps(list(list()))
     # Convert categories to a list, if it's not
     if type(categories) in [str,unicode]: categories = [categories,]
     metrics = metrics or ['hits',]
     period = period or Period.default_size()
     sparse = self.driver().retrieve(categories,dimensions,metrics,
             period=period, depth=depth)
     nonsparse = defaultdict(dict)
     for dimensions, metrics in sparse.items():
         for metric, points in metrics.items():
             dts = Period(*period.split('x')).datetimes_strs()
             nonsparse[dimensions][metric] = []
             for dt in dts:
                 flot_time = to_flot_time(Period.parse_dt_str(dt))
                 value = points[dt] if dt in points else 0
                 nonsparse[dimensions][metric].append([flot_time,
                     float(value)])
     return nonsparse
Ejemplo n.º 4
0
    def plotpoints(cls, pk, dimensions=None, metrics=None,
            depth=0, period=None, flot_time=False, points_type=dict):
        metrics = metrics or ['hits']
        if isinstance(metrics, basestring):
            metrics = [metrics]
        period = Period.get(period)
        dts = period.datetimes_strs()
        nonsparse = defaultdict(defaultdict)

        # Hardwire time-based metrics for lulz
        time_metrics = {'second': 1, 'minute': 60, 'hour': 3600, 'day': 3600*24, 'week': 3600*24*7}
        #for t_m, factor in time_metrics.items():
        #    if t_m in metrics:
        #        metrics.remove(t_m)
        #        for dimension in dimensions:
        #            nonsparse[dimension][t_m] = list()
        #            for dt in dts:
        #                if flot_time:
        #                    dt = to_flot_time(Period.parse_dt_str(dt))
        #                nonsparse[dimension][t_m].append([dt, period.interval / factor])
        #            nonsparse[dimension][t_m] = points_type(nonsparse[dimension][t_m])
        # Pull the plotpoints that exist from Redis
        sparse = cls.whale_driver().retrieve(pk, dimensions, metrics, period=period)
        
        for dimensions, metrics in sparse.items():
            for metric, points in metrics.items():
                #if metric in time_metrics: continue
                nonsparse[dimensions][metric] = []
                for dt in dts:
                    if flot_time:
                        dt = to_flot_time(Period.parse_dt_str(dt))
                    value = points[dt] if dt in points else 0
                    nonsparse[dimensions][metric].append([dt, float(value)])
                nonsparse[dimensions][metric] = points_type(nonsparse[dimensions][metric])
        if depth > 0:
            for sub in cls.get_subdimensions(pk, dimensions):
                nonsparse = dict(nonsparse.items() +
                    cls.plotpoints(pk, sub, metrics, depth=depth - 1, period=period,
                        flot_time=flot_time, points_type=points_type).items())
        return nonsparse