update results as well
@@ -377,8 +377,8 @@ class Experiment(ExperimentData):
derived_kpis (list): definition of additional KPIs derived from the
primary ones, e.g.
[{'name':'return_rate', 'formula':'returned/ordered'}]
- derived kpi names are alphanumerical starting with a
- letter, i.e. [a-zA-Z][0-9a-zA-Z_]+
+ the original kpi column names are alphanumerical
+ starting with a letter, i.e. [a-zA-Z][0-9a-zA-Z_]+
variant_subset (list): Variants to use compare against baseline. If
set to None all variants are used.
@@ -408,6 +408,7 @@ class Experiment(ExperimentData):
res.metadata['reference_kpi'] = {}
res.metadata['weighted_kpis'] = weighted_kpis
+ pattern = '([a-zA-Z][0-9a-zA-Z_]*)'
# determine the complete KPI name list
kpis_to_analyse = self.kpi_names.copy()
if derived_kpis is not None:
@@ -415,10 +416,10 @@ class Experiment(ExperimentData):
kpis_to_analyse.update([dk['name']])
# assuming the columns in the formula can all be cast into float
# and create the derived KPI as an additional column
- self.kpis.loc[:,dk['name']] = eval(re.sub('([a-zA-Z][0-9a-zA-Z_]*)', r'self.kpis.\1.astype(float)', dk['formula']))
+ self.kpis.loc[:,dk['name']] = eval(re.sub(pattern, r'self.kpis.\1.astype(float)', dk['formula']))
# store the reference metric name to be used in the weighting
# TODO: only works for ratios
- res.metadata['reference_kpi'][dk['name']] = re.sub('([a-zA-Z_]+)/', '', dk['formula'])
+ res.metadata['reference_kpi'][dk['name']] = re.sub(pattern+'/', '', dk['formula'])
if kpi_subset is not None:
kpis_to_analyse.intersection_update(kpi_subset)
