def testStatsList(self): us = UserStats('userid', 'itemid') us.save(1,2) us.save(1,3) us.save(1,4) us.save(2,2) us.save(2,3) us.save(3,4) us.save(4,4) toplist = us.get_Top_N('userid', 3) print toplist self.assertEqual(len(toplist), 3, "toplist has not enough entries") toplist = us.get_Top_N('userid', 4) self.assertEqual(len(toplist), 4, "toplist has not enough entries") self.assertEqual(int(toplist[0][0]), 1, "") self.assertEqual(int(toplist[0][1]), 3, "")
timestamp = message['timestamp'] domainid = message['domainid'] additional_filter = {'domainid': domainid} if config_global.SAVE_RANDOM_RECOMMENDER in backends: fb = Random_Recommender() fb.set_recommendables(itemid, additional_filter) if config_global.SAVE_HADOOP_SINK in backends: hS = HadoopSink(append=True) rating = 1 hS.save_mode2(userid, itemid, domainid, timestamp) if config_global.SAVE_USER_STATS in backends: us = UserStats('userid', 'itemid') us.save(userid, itemid) #save sync else: body_message = {'message': message, 'api': api, 'backends': backends} body_message = pickle.dumps(body_message) self.enqueue(body_message) #from contest.packages.queues.RawJsonDumpWorker import rawJsonDumpWorker #raw = rawJsonDumpWorker(mode='redis') #raw.enqueue(message)
if (SAVE_DIMENSION_LIST): dimension = 'user_ids' dL = DimensionListModel( dimension ) if(debug): print "userid:\t" + str(flattenedJson['client_id']) dL.save( dimension_id = flattenedJson['client_id'], timestamp = timestamp_sec ) """ n += 1 if ( n % cycle_count == 0 and debug2): print n if (not debug3): result = r.fetch_row(maxrows = n_maxrows) # fetch N row maximum else: result = False if (not debug3): db.close() #close the database connection replay_time = time2.time() - replay_time print "time it took: " + str(replay_time) print 'It took {0:1f} seconds per item'.format(replay_time/n) us = UserStats('userid', 'itemid') the_list = us.get_Top_N('userid', 100) print the_list pH = Plot_Helper() pH.make_plot(the_list)