From f29bfd7bb55b542c864cbada92eebf2454fa9aac Mon Sep 17 00:00:00 2001 From: Zachary Sloan Date: Fri, 28 Feb 2014 00:02:13 +0000 Subject: Made some changes/comments to Lei's load_genotypes.py file --- wqflask/base/trait_collection.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'wqflask/base') diff --git a/wqflask/base/trait_collection.py b/wqflask/base/trait_collection.py index 797a4d63..49b0eaea 100644 --- a/wqflask/base/trait_collection.py +++ b/wqflask/base/trait_collection.py @@ -22,6 +22,45 @@ from sqlalchemy import (Column, Integer, String, Table, ForeignKey, Unicode, Boo Text, Index) from sqlalchemy.orm import relationship, backref +#from redis import StrictRedis +import redis +Redis = redis.StrictRedis() + from wqflask.database import Base, init_db class TraitCollection(object): + + +class AnonCollection(TraitCollection): + + def __init__(self, anon_id) + self.anon_id = anon_id + self.collection_members = Redis.smembers(self.anon_id) + print("self.collection_members is:", self.collection_members) + self.num_members = len(self.collection_members) + + + @app.route("/collections/remove", methods=('POST',)) + def remove_traits(traits_to_remove): + print("traits_to_remove:", traits_to_remove) + for trait in traits_to_remove: + Redis.srem(self.anon_id, trait) + members_now = self.collection_members - traits_to_remove + print("members_now:", members_now) + print("Went from {} to {} members in set.".format(len(self.collection_members), len(members_now))) + + # We need to return something so we'll return this...maybe in the future + # we can use it to check the results + return str(len(members_now)) + + @property + def num_members(self): + print("members are:", json.loads(self.members)) + return len(json.loads(self.members)) + + #@property + #def display_num_members(self): + # return display_collapsible(self.num_members) + + def members_as_set(self): + return set(json.loads(self.members)) \ No newline at end of file -- cgit v1.2.3