当前位置: 首页>>代码示例>>Python>>正文


Python Period.parse_dt_str方法代码示例

本文整理汇总了Python中periods.Period.parse_dt_str方法的典型用法代码示例。如果您正苦于以下问题:Python Period.parse_dt_str方法的具体用法?Python Period.parse_dt_str怎么用?Python Period.parse_dt_str使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在periods.Period的用法示例。


在下文中一共展示了Period.parse_dt_str方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: scalar_plotpoints

# 需要导入模块: from periods import Period [as 别名]
# 或者: from periods.Period import parse_dt_str [as 别名]
 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
开发者ID:bobwilliams,项目名称:hailwhale,代码行数:34,代码来源:whale.py

示例2: plotpoints

# 需要导入模块: from periods import Period [as 别名]
# 或者: from periods.Period import parse_dt_str [as 别名]
 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
开发者ID:mattseh,项目名称:hailwhale,代码行数:19,代码来源:whale.py

示例3: plotpoints

# 需要导入模块: from periods import Period [as 别名]
# 或者: from periods.Period import parse_dt_str [as 别名]
 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
开发者ID:kyleirwin,项目名称:hailwhale,代码行数:23,代码来源:whale.py

示例4: plotpoints

# 需要导入模块: from periods import Period [as 别名]
# 或者: from periods.Period import parse_dt_str [as 别名]
    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
开发者ID:kamired22,项目名称:hailwhale,代码行数:42,代码来源:whale_crazy.py

示例5: scalar_plotpoints

# 需要导入模块: from periods import Period [as 别名]
# 或者: from periods.Period import parse_dt_str [as 别名]
    def scalar_plotpoints(cls, pk, dimensions=None, metrics=None, at=None,
            depth=0, period=None, flot_time=False, points_type=OrderedDict):
        metrics = metrics or ['hits']
        at = at or times.now()
        if isinstance(metrics, basestring):
            metrics = [metrics]
        p_obj, ats, tzoffset = Period.get_days(period,at)
        p_s = str(p_obj)
        dts = list(p_obj.datetimes_strs(end=Period.parse_dt_str(at)))

        sparse = _retrieve(cls.whale_driver(), pk, dimensions, metrics, period=p_obj)
        nonsparse = defaultdict(dict)
        if flot_time:
            points_type = list
        for dim, mets in sparse.items():
            for met, points in mets.items():
                nonsparse[dim][met] = []
                use_method = False
                met_name = met
                if ':' in met:
                    met_name, use_method = met.split(':')

                const_value = False
                if met_name in TIME_MATRIX:
                    const_value = float(p_obj.getUnits()[0] /
                            TIME_MATRIX[met_name])
                # Try to parse static metrics too
                elif met_name == '_count':
                    const_value = len(dts)
                try:
                    const_value = float(met_name)
                except:
                    pass
                last_value = total = 0
                for dt in dts:
                    dt_obj = Period.parse_dt_str(dt)
                    if met_name == '_days_in_month':
                        from calendar import monthrange
                        const_value = monthrange(dt_obj.year, dt_obj.month)[1]
                    if flot_time:
                        dt_t = to_flot_time(dt_obj)
                    else:
                        dt_t = dt
                    if const_value:
                        value = const_value
                    else:
                        value = points[dt] if dt in points else 0
                    if use_method == 'count' or not use_method:
                        value = value
                    elif use_method in ['+', 'sum', 'add', 'cumulative']:
                        total += value
                        value = total
                    elif use_method in ['_', 'set', 'last', 'level']:
                        if not last_value:
                            last_value = value
                        if not value:
                            value = last_value
                        last_value = value
                    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, at=at, depth=depth - 1, period=period,
                        flot_time=flot_time, points_type=points_type).items())
        return nonsparse
开发者ID:prachi,项目名称:raining,代码行数:69,代码来源:whale.py


注:本文中的periods.Period.parse_dt_str方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。