當前位置: 首頁>>代碼示例>>Python>>正文


Python TimeFilter.profiler_minutes方法代碼示例

本文整理匯總了Python中steelscript.netprofiler.core.filters.TimeFilter.profiler_minutes方法的典型用法代碼示例。如果您正苦於以下問題:Python TimeFilter.profiler_minutes方法的具體用法?Python TimeFilter.profiler_minutes怎麽用?Python TimeFilter.profiler_minutes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在steelscript.netprofiler.core.filters.TimeFilter的用法示例。


在下文中一共展示了TimeFilter.profiler_minutes方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: generate_traffic

# 需要導入模塊: from steelscript.netprofiler.core.filters import TimeFilter [as 別名]
# 或者: from steelscript.netprofiler.core.filters.TimeFilter import profiler_minutes [as 別名]
    def generate_traffic(self, activity, legend_keys, report_type):
        """ Generate traffic data during the time the user was logged-in.
        """
        cache = {}
        combined_activity = []
        for event in activity:
            # handle dns names in host along with IP address
            host = event[0].split('|', 1)[0]

            timefilter = TimeFilter(string_to_datetime(event[1]),
                                    string_to_datetime(event[2]))
            # if event occurs in less than a minute, add extra minute to report
            while len(timefilter.profiler_minutes()) == 1:
                timefilter.end += datetime.timedelta(minutes=1)

            # normalize times to minute increments
            mins = timefilter.profiler_minutes()
            tf = TimeFilter(mins[0], mins[-1])

            if self.options.usecache and report_type == 'timeseries':
                # only consider a hit when whole time period is covered
                minutes = tf.profiler_minutes(astimestamp=True)

                if host in cache and all(t in cache[host] for t in minutes):
                    data = [cache[host][t] for t in minutes]
                else:
                    legend, data = self.traffic_report(host, tf, report_type)
                    # store results in cache by host->times->data
                    cache.setdefault(host, {}).update((int(x[0]), x) for x in data)
            else:
                legend, data = self.traffic_report(host, tf, report_type)

            if data:
                if self.options.aggregate and report_type == 'timeseries':
                    # generate running averages over data samples received
                    # first convert empty strings to zeros, then run averages
                    columns = map(lambda c: [0 if x == '' else x for x in c],
                                                                itertools.izip(*data))
                    aggmap = [x[1] for x in TCOLUMNS]
                    aggregates = [aggmap[i](x) for i, x in enumerate(columns)]
                    combined_activity.append(list(event) + aggregates)
                elif report_type == 'timeseries' or report_type == 'summary':
                    # create entry for each element in report
                    for row in data:
                        r = ['--' if x == '' else x for x in row]
                        combined_activity.append(list(event) + r)
                else:
                    raise RuntimeError('unknown report type: %s' % report_type)

            else:
                # populate result with blanks
                combined_activity.append(list(event) + ['--'] * len(legend))

        traffic_legend = [c.key for c in legend]

        legend = legend_keys + traffic_legend
        return legend, combined_activity
開發者ID:carriercomm,項目名稱:steelscript-netprofiler,代碼行數:59,代碼來源:identity_report.py


注:本文中的steelscript.netprofiler.core.filters.TimeFilter.profiler_minutes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。