class UnitTest(unittest.TestCase): def setUp(self): self.db = MongoInterface() self.services = ["Twitter", "Google Plus", "Facebook", "Reddit"] def test_algorithm1(self): for service in self.services: messages = self.db.messageByService(service) for message in messages: self.assertEqual(message["service"], service) messages.rewind() num = Algorithm1.getAlgorithmNumber() res = Algorithm1.getResult(messages) self.assertIsInstance(num, int) self.assertIsInstance(res, float) def test_algorithm2(self): for service in self.services: messages = self.db.messageByService(service) for message in messages: self.assertEqual(message["service"], service) messages.rewind() num = Algorithm2.getAlgorithmNumber() res = Algorithm2.getResult(messages) self.assertIsInstance(num, int) self.assertIsInstance(res, float) def test_algorithm3(self): for service in self.services: messages = self.db.messageByService(service) for message in messages: self.assertEqual(message["service"], service) messages.rewind() num = Algorithm3.getAlgorithmNumber() res = Algorithm3.getResult(messages) self.assertIsInstance(num, int) self.assertIsInstance(res, float) self.assertGreater(res, -0.5) self.assertLess(res, 0.5)
from database.MongoInterface import MongoInterface from algorithms.Algorithm1 import Algorithm1 from algorithms.Algorithm2 import Algorithm2 from algorithms.Algorithm3 import Algorithm3 import time db = MongoInterface() total = 0 now = time.time() services = ["Twitter", "Google Plus", "Facebook", "Reddit"] for service in services: messages = db.messageByService(service) res = Algorithm1.getResult(messages) db.saveResult(now, service, Algorithm1.getAlgorithmNumber(), res) total += res print total total = 0 for service in services: messages = db.messageByService(service) res = Algorithm2.getResult(messages) db.saveResult(now, service, Algorithm2.getAlgorithmNumber(), res) total += res print total total = 0
from database.MongoInterface import MongoInterface from algorithms.Algorithm1 import Algorithm1 from algorithms.Algorithm2 import Algorithm2 from algorithms.Algorithm3 import Algorithm3 import time db = MongoInterface() total = 0 now = time.time() #services = ["Twitter", "Google Plus", "Facebook", "Reddit"] services = [ "Facebook" ] days = 0 while ( days < 9): end = now - ((days+1) * 24 * 60 * 60) start = now - ((days+2) * 24 * 60 * 60) for service in services: messages = db.messageByService(service, start, end) res = Algorithm1.getResult(messages) db.saveResult(end, service, Algorithm1.getAlgorithmNumber(), res) total += res print total total = 0 for service in services: messages = db.messageByService(service, start, end)
def setUp(self): self.db = MongoInterface() self.services = ["Twitter", "Google Plus", "Facebook", "Reddit"]