示例#1
0
    def test_SaveMessage_interpretedJson_async(self):
        ''' tests the generation of the writeBack of the interpreted data coming in from the contest messages
        '''
        backends = [config_global.SAVE_HADOOP_SINK, config_global.SAVE_RANDOM_RECOMMENDER]
        userid = 5678
        domainid = 8

        sM = SaveMessage()
        for itemid in xrange(5):
            timestamp = getTimestamp.gettimeStampInMicroseconds()
            id_list = {'userid': userid, 'itemid': itemid, 'timestamp': timestamp, 'domainid': domainid}

            sM.save(id_list, async=True, api='id_list', backends=backends)
示例#2
0
    def saveJson(self, backends):
        messages = []

        message = "{\"msg\":\"impression\",\"id\":3,\"client\":{\"id\":2},\"domain\":{\"id\":\"418\"},\"item\":{\"id\":\"5678\",\"title\":\"Inter\u00adna\u00adtional Emmy-Awards\",\"url\":\"http:\/\/www.ksta.de\/html\/fotolines\/1321650273296\/rahmen.shtml?1\",\"created\":1321957664,\"text\":\"Talkshow-Mode\u00adra\u00adtorin Wendy Williams bei den 39. inter\u00adna\u00adtio\u00adnalen Emmy-Awards. (Bild: AFP)\",\"img\":null,\"recommendable\":true},\"config\":{\"timeout\":null,\"recommend\":true,\"limit\":1,\"team\":{\"id\":\"22\"}},\"version\":\"1.0\"}"
        messages.append(message)

        message = "{\"msg\":\"impression\",\"id\":4,\"client\":{\"id\":2},\"domain\":{\"id\":\"418\"},\"item\":{\"id\":\"5678\",\"title\":\"Inter\u00adna\u00adtional Emmy-Awards\",\"url\":\"http:\/\/www.ksta.de\/html\/fotolines\/1321650273296\/rahmen.shtml?1\",\"created\":1321957664,\"text\":\"Talkshow-Mode\u00adra\u00adtorin Wendy Williams bei den 39. inter\u00adna\u00adtio\u00adnalen Emmy-Awards. (Bild: AFP)\",\"img\":null,\"recommendable\":true},\"config\":{\"timeout\":null,\"recommend\":true,\"limit\":1,\"team\":{\"id\":\"22\"}},\"version\":\"1.0\"}"
        messages.append(message)

        message = "{\"msg\":\"impression\",\"id\":5,\"client\":{\"id\":2},\"domain\":{\"id\":\"418\"},\"item\":{\"id\":\"5678\",\"title\":\"Inter\u00adna\u00adtional Emmy-Awards\",\"url\":\"http:\/\/www.ksta.de\/html\/fotolines\/1321650273296\/rahmen.shtml?1\",\"created\":1321957664,\"text\":\"Talkshow-Mode\u00adra\u00adtorin Wendy Williams bei den 39. inter\u00adna\u00adtio\u00adnalen Emmy-Awards. (Bild: AFP)\",\"img\":null,\"recommendable\":true},\"config\":{\"timeout\":null,\"recommend\":true,\"limit\":1,\"team\":{\"id\":\"22\"}},\"version\":\"1.0\"}"
        messages.append(message)

        for m in messages:
            sM = SaveMessage()
            sM.save(m, async=False, api='contest', backends=backends)
    def importTrainingData(self, backends):
        if not self.debug:
            self.getResults()
            n_maxrows = 10 #amount of items fetched for training
            result = r.fetch_row(maxrows=n_maxrows) # fetch N row maximum
        else:
            result = self.wfb.mockMysqlResults_domain418()
            result2 = self.wfb.mockMysqlResults_domain800()

        constraints = {'domainid': 418}
        for result_item in result:
            json_string = result_item[3]
            sM = SaveMessage()
            sM.save(json_string, async=False, api='contest', backends=backends, constraints=constraints)

        constraints = {'domainid': 800}
        for result_item in result2:
            json_string = result_item[3]
            sM = SaveMessage()
            sM.save(json_string, async=False, api='contest', backends=backends, constraints=constraints)

        for result_item in result:
            json_string = result_item[3]
            sM = SaveMessage()
            sM.save(json_string, async=False, api='contest', backends=backends, constraints={})

        for result_item in result2:
            json_string = result_item[3]
            sM = SaveMessage()
            sM.save(json_string, async=False, api='contest', backends=backends, constraints={})
		for result_item in result:
			
			the_id = result_item[0]
			userid = int(result_item[0])
			itemid = int(result_item[1])
			timestamp = str(result_item[2])
			domainid = 	int(result_item[3])

			id_list = {'userid' : userid,
					   'itemid' : itemid,
					   'timestamp' : timestamp,
					   'domainid' : domainid}
				
			current_time = time2.time()

			sM = SaveMessage()
			sM.save( id_list, async = False, api = 'id_list', backends = [ config_global.SAVE_USER_STATS ] )

			"""
			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