示例#1
0
文件: combiners.py 项目: dtaht/flent
 def reduce(self, resultset, series, data=None):
     key = series['data']
     source = Glob.expand_list(series['source'], resultset.series_names,
                               exclude=self.filter_series, args=series)
     values = []
     for key in source:
         values.append(super(FairnessReducer, self).reduce(resultset, None, resultset[key]))
     valsum = math.fsum([x**2 for x in values])
     if not valsum:
         return None
     return math.fsum(values)**2/(len(values)*valsum)
示例#2
0
文件: combiners.py 项目: zi0r/flent
 def reduce(self, resultset, series, data=None):
     key = series['data']
     source = Glob.expand_list(series['source'], resultset.series_names,
                               exclude=self.filter_series, args=series)
     values = []
     for key in source:
         v = super(FairnessReducer, self).reduce(
             resultset, None, resultset[key])
         if v is not None:
             values.append(v)
     valsum = math.fsum([x**2 for x in values])
     if not valsum:
         return None
     return math.fsum(values)**2 / (len(values) * valsum)
示例#3
0
文件: plotters.py 项目: mmlb/flent
 def expand_plot_config(self, config, data):
     if not 'series' in config:
         return config
     new_series = []
     for s in config['series']:
         if isinstance(s['data'], Glob):
             for d in Glob.expand_list(s['data'], data.keys()):
                 if 'label' in s and 'id' in data[d]:
                     new_series.append(dict(s, data=d, label='%s -- %s' % (s['label'], data[d]['id'])))
                 else:
                     new_series.append(dict(s, data=d))
         else:
             new_series.append(s)
     return dict(config, series=new_series)
示例#4
0
文件: runners.py 项目: dtaht/flent
    def result(self, res):
        if not self.keys:
            return res

        new_res = []
        keys = Glob.expand_list(self.keys,res.series_names,[self.name])

        for r in res.zipped(keys):
            values = [v for v in r[1:] if v is not None]
            if not values:
                new_res.append(None)
            else:
                new_res.append(self.compute(values))

        meta = res.meta('SERIES_META') if 'SERIES_META' in res.meta() else {}
        meta[self.name] = {}
        for mk in self.supported_meta:
            vals = []
            for k in keys:
                if k in meta and mk in meta[k] and meta[k][mk] is not None:
                    vals.append(meta[k][mk])
            if vals:
                try:
                    meta[self.name][mk] = self.compute(vals)
                except TypeError:
                    meta[self.name][mk] = None

        for mk in self.copied_meta:
            vals = []
            for k in keys:
                if k in meta and mk in meta[k]:
                    vals.append(meta[k][mk])
            if vals:
                # If all the source values of the copied metadata are the same,
                # just use that value, otherwise include all of them.
                meta[self.name][mk] = vals if len(set(vals)) > 1 else vals[0]

        res.add_result(self.name, new_res)
        return res
    def result(self, res):
        if not self.keys:
            return res

        new_res = []
        keys = Glob.expand_list(self.keys, res.series_names, [self.name])

        for r in res.zipped(keys):
            values = [v for v in r[1:] if v is not None]
            if not values:
                new_res.append(None)
            else:
                new_res.append(self.compute(values))

        meta = res.meta('SERIES_META') if 'SERIES_META' in res.meta() else {}
        meta[self.name] = {}
        for mk in self.supported_meta:
            vals = []
            for k in keys:
                if k in meta and mk in meta[k] and meta[k][mk] is not None:
                    vals.append(meta[k][mk])
            if vals:
                try:
                    meta[self.name][mk] = self.compute(vals)
                except TypeError:
                    meta[self.name][mk] = None

        for mk in self.copied_meta:
            vals = []
            for k in keys:
                if k in meta and mk in meta[k]:
                    vals.append(meta[k][mk])
            if vals:
                # If all the source values of the copied metadata are the same,
                # just use that value, otherwise include all of them.
                meta[self.name][mk] = vals if len(set(vals)) > 1 else vals[0]

        res.add_result(self.name, new_res)
        return res