Exemplo n.º 1
0
    def testRawJsonModel_GETN_Cassandra(self):
        message = '{"msg":"impression","id":2,"client":{"id":1},"domain":{"id":"418"},"item":{"id":"1234","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"}'
        raw = rawJsonModel(json_string=message)
        raw.save()

        self.assertEqual(len(raw.getN(N=1)), 1, "the result has the wrong length")

        # self.assertNotEqual(len(raw.getN(N=1000)), 1000, "the result has the wrong length")
        for i in xrange(100):
            raw = rawJsonModel(json_string=message)
            raw.save()

        self.assertEqual(len(raw.getN(N=100)), 100, "the result has the wrong length")
Exemplo n.º 2
0
    def _testRawJsonModel_GETN_Redis(self):
        """ @fixme: this is broken """
        message = "ABC"
        raw = rawJsonModel(json_string=message, mode="redis")
        raw.save()

        self.assertEqual(len(raw.getN(N=1)), 1, "the result has the wrong length")

        # self.assertNotEqual(len(raw.getN(N=1000)), 1000, "the result has the wrong length")
        for i in xrange(5):
            raw = rawJsonModel(json_string=message, mode="redis")
            time.sleep(1)
            print raw.save()

        print raw.getN(N=5)
Exemplo n.º 3
0
	def callback(self, ch, method, properties, body):

		print body

		# todo get the message from the body
		# todo parse relevant options from the body
		#print "rawJsonDump received a task %r" % (body)
		timestamp = time.time()
		
		raw = rawJsonModel( self.mode )
		raw.parse(body)
		raw.save()
Exemplo n.º 4
0
    def test_SaveMessage_rawJsonModel(self):
        backend = [config_global.SAVE_RAW_JSON]
        self.saveJson(backend)

        N = 2
        raw = rawJsonModel()
        rawJson = raw.getN(N)
        self.assertEqual(N, len(rawJson))

        N = 4
        rawJson = raw.getN(N)
        self.assertEqual(N, len(rawJson))
Exemplo n.º 5
0
    def save(self, message, async=False, api='contest', backends=(), constraints={}):
        """
        """

        if not async: # save the data instantly

            if api == 'contest':
                fullParsedDataModel = FullContestMessageParser()
                fullParsedDataModel.parse(message)
                fullParsedDataModel.save()

                item_id = fullParsedDataModel.item_id

                if config_global.SAVE_RAW_JSON in backends:
                    raw = rawJsonModel(message, mode='redis')
                    raw.save()

                if config_global.SAVE_RANDOM_RECOMMENDER in backends:
                    fb = Random_Recommender()
                    domain_id = fullParsedDataModel.domain_id
                    ## todo the recommender has to decide on its own what to save and therefore save constraints, even though the constrain management should be centralized
                    #constraints = {'domainid': domain_id}
                    fb.set_recommendables(item_id, constraints)

            if api == 'orp':
                # todo throw not implemented error
                pass


            elif api == 'id_list': ## this for debugging purposes