############################################################## # # Name: userprofile.py # # Description: userprofile class for each peer # # Usage: data structure and manipulation for user profiling # # Author: Jun Wang j.wang@ewi.tudelft.nl June 2005 # ############################################################## # # PlayList data structure based on dictionary: # {'itemid':{'rating':rating,'time':time},...} # class userprofile(dict): def __init__(self, peerid = -1 ): self.peerID = peerid def add(self,ratings): #[itemid,rating,time] [itemid,rating,time] = ratings self[itemid] = {'rating':rating,'time':time} def get(self): return self def _print(self): for a in self.keys(): print 'peerid:', self.peerID, 'itemid:', a , self[a] def new(self,userprofile): self.clear() self.update(userprofile) if '__main__'== __name__: a = userprofile(0) a.add([1,3,1]) a.add([2,3,1]) del a[2] a.add([3,3,1]) a.add([4,3,1]) #a._print() print a.get() profile = {1:{'rating':'2','time':11},2:{'rating':2,'time':11}} a.clear() a.new(profile) print 'print something here' a._print()