def _train_relations_all(self, tags): import itertools if not len(tags) > 1: return combiantions = itertools.combinations(tags.keys(), 2) for a, b in combiantions: min, max = get_min_max(a, b) value = float(tags[min]/tags[max]) key_min = cache_key(TRAIN_RELATION_ALL_PREFIX, min) key_max = cache_key(TRAIN_RELATION_ALL_PREFIX, max) cache.zincrby(name=key_min, value=max, amount=value) cache.zincrby(name=key_max, value=min, amount=value)
def _train_relations(self, tags): import itertools if not len(tags) > 1: return total = reduce(lambda x, y: x+y, tags.values()) real_tags = {} for tag in tags: if tags[tag]/total > threshold: real_tags.update({tag: tags[tag]}) if not len(real_tags) > 1: return combiantions = itertools.combinations(real_tags.keys(), 2) for a, b in combiantions: min, max = get_min_max(a, b) value = float(real_tags[min]/real_tags[max]) key_min = cache_key(TRAIN_RELATION_PREFIX, min) key_max = cache_key(TRAIN_RELATION_PREFIX, max) cache.zincrby(name=key_min, value=max, amount=value) cache.zincrby(name=key_max, value=min, amount=value)