def participate_in_doppleganger_on_new_instance(self): """Simulate participating in a new experiment on a "new" instance. This test works by loading memcache with a copy of all gae/bingo experiments before the doppleganger test exists. After the doppleganger test has been created once, all future calls to this function simulate being run on machines that haven't yet cleared their instance cache and loaded the newly created doppleganger yet. We do this by replacing the instance cache'd state of BingoCache with the deep copy that we made before doppleganger was created. A correctly functioning test will still only create one copy of the experiment even though multiple clients attempted to create a new experiment. """ # First, make a deep copy of the current state of bingo's experiments bingo_clone = memcache.get("bingo_clone") if not bingo_clone: # Set the clone by copying the current bingo cache state memcache.set("bingo_clone", copy.deepcopy(BingoCache.get())) else: # Set the current bingo cache state to the cloned state gae_bingo.instance_cache.set(BingoCache.CACHE_KEY, bingo_clone) return ab_test("doppleganger")
def count_participants_in(self): return sum( map( lambda alternative: alternative.latest_participants_count(), BingoCache.get().get_alternatives(self.request.get("experiment_name")), ) )
def get_experiments(self, archives=False): if archives: bingo_cache = BingoCache.load_from_datastore(archives=True) else: bingo_cache = BingoCache.get() return str(bingo_cache.experiments)
def count_participants_in(self): return reduce( lambda a, b: a + b, map( lambda alternative: alternative.participants, BingoCache.get().get_alternatives( self.request.get("experiment_name"))))
def count_conversions_in(self): dict_conversions = {} for alternative in BingoCache.get().get_alternatives(self.request.get("experiment_name")): dict_conversions[alternative.content] = alternative.latest_conversions_count() return dict_conversions
def flush_hippo_counts_memcache(self): experiments, alternative_lists = BingoCache.get().experiments_and_alternatives_from_canonical_name("hippos") for experiment in experiments: experiment.reset_counters() return True
def delete_all_experiments(self): bingo_cache = BingoCache.get() for experiment_name in bingo_cache.experiments.keys(): bingo_cache.delete_experiment_and_alternatives(bingo_cache.get_experiment(experiment_name)) return len(bingo_cache.experiments)
def flush_hippo_counts_memcache(self): experiments, alternative_lists = BingoCache.get().experiments_and_alternatives_from_canonical_name("hippos") for alternatives in alternative_lists: for alternative in alternatives: memcache.delete("%s:conversions" % alternative.key_for_self()) memcache.delete("%s:participants" % alternative.key_for_self()) return True
def delete_all_experiments(self): bingo_cache = BingoCache.get() for experiment_name in bingo_cache.experiments.keys(): bingo_cache.delete_experiment_and_alternatives(bingo_cache.get_experiment(experiment_name)) bingo_cache_archives = BingoCache.load_from_datastore(archives=True) for experiment_name in bingo_cache_archives.experiments.keys(): bingo_cache_archives.delete_experiment_and_alternatives( bingo_cache_archives.get_experiment(experiment_name) ) return len(bingo_cache.experiments) + len(bingo_cache_archives.experiments)
def delete_all_experiments(self): bingo_cache = BingoCache.get() for experiment_name in bingo_cache.experiments.keys(): bingo_cache.delete_experiment_and_alternatives( bingo_cache.get_experiment(experiment_name)) bingo_cache_archives = BingoCache.load_from_datastore(archives=True) for experiment_name in bingo_cache_archives.experiments.keys(): bingo_cache_archives.delete_experiment_and_alternatives( bingo_cache_archives.get_experiment(experiment_name)) return (len(bingo_cache.experiments) + len(bingo_cache_archives.experiments))
def count_experiments(self): return len(BingoCache.get().experiments)
def count_participants_in(self): return sum( map(lambda alternative: alternative.latest_participants_count(), BingoCache.get().get_alternatives(self.request.get("experiment_name")) ) )
def get_experiments(self): return str(BingoCache.get().experiments)
def end_and_choose(self): with ExperimentController() as dummy: bingo_cache = BingoCache.get() choose_alternative( self.request.get("canonical_name"), int(self.request.get("alternative_number")))
def try_this_bad(self): cache = BingoCache.get() return len(cache.get_experiment_names_by_canonical_name("hippos"))
def end_and_choose(self): bingo_cache = BingoCache.get() choose_alternative(self.request.get("canonical_name"), int(self.request.get("alternative_number")))
def persist(self): BingoCache.get().persist_to_datastore() BingoIdentityCache.persist_buckets_to_datastore() return True
def archive_monkeys(self): bingo_cache = BingoCache.get() bingo_cache.archive_experiment_and_alternatives(bingo_cache.get_experiment("monkeys")) return True
def count_participants_in(self): return reduce(lambda a, b: a + b, map(lambda alternative: alternative.participants, BingoCache.get().get_alternatives(self.request.get("experiment_name")) ) )