def testQueryUnclassifiedSectionsLowConfidence(self): fakeEmail = "*****@*****.**" client = Client("testclient") client.update(createKey = False) emission.tests.common.makeValid(client) (resultPre, resultReg) = client.preRegister("this_is_the_super_secret_id", fakeEmail) self.assertEqual(resultPre, 0) self.assertEqual(resultReg, 1) user = User.fromEmail(fakeEmail) self.assertEqual(user.getFirstStudy(), 'testclient') queriedUnclassifiedSections = tripManager.queryUnclassifiedSections(User.fromEmail(fakeEmail).uuid) self.assertEqual(queriedUnclassifiedSections.count(), 2) # Set the auto_confirmed values for the trips for section in queriedUnclassifiedSections: print section['_id'] self.SectionsColl.update({'_id': section['_id']}, {'test_auto_confirmed': {'mode': section['mode'], 'prob': 0.95}}) # Now, set the update timestamp to two weeks ago so that we will start filtering emission.tests.common.updateUserCreateTime(user.uuid) queriedUnclassifiedSections = tripManager.queryUnclassifiedSections(User.fromEmail(fakeEmail).uuid) self.assertEqual(queriedUnclassifiedSections.count(), 0)
def testQueryUnclassifiedSectionsWeekAgo(self): # Add some old sections that shouldn't be returned by the query # This one is just over a week old old_sec_1 = self.SectionsColl.find_one({'$and': [{'user_id': User.fromEmail('*****@*****.**').uuid}, {'type':'move'}, {'mode':1}]}) old_sec_1['_id'] = 'old_sec_1' old_sec_1['section_start_datetime'] = self.weekago - timedelta(minutes = 30) old_sec_1['section_end_datetime'] = self.weekago - timedelta(minutes = 5) logging.debug("Inserting old_sec_1 %s" % old_sec_1) self.SectionsColl.insert(old_sec_1) # This one is a month old monthago = self.now - timedelta(days = 30) old_sec_2 = self.SectionsColl.find_one({'$and': [{'user_id':User.fromEmail('*****@*****.**').uuid}, {'type':'move'}, {'mode':4}]}) old_sec_2['_id'] = 'old_sec_2' old_sec_2['section_start_datetime'] = monthago - timedelta(minutes = 30) old_sec_2['section_end_datetime'] = monthago - timedelta(minutes = 5) logging.debug("Inserting old_sec_2 %s" % old_sec_2) self.SectionsColl.insert(old_sec_2) # This one is missing the predicted mode monthago = self.now - timedelta(days = 30) un_pred_sec = self.SectionsColl.find_one({'$and': [{'user_id':User.fromEmail('*****@*****.**').uuid}, {'type':'move'}, {'mode':4}]}) un_pred_sec['_id'] = 'un_pred_sec' del un_pred_sec['predicted_mode'] logging.debug("Inserting un_pred_sec %s" % un_pred_sec) self.SectionsColl.insert(un_pred_sec) queriedUnclassifiedSections = tripManager.queryUnclassifiedSections(User.fromEmail('*****@*****.**').uuid) self.assertEqual(queriedUnclassifiedSections.count(), 2)
def testQueryUnclassifiedSectionsWeekAgo(self): # Add some old sections that shouldn't be returned by the query # This one is just over a week old old_sec_1 = self.SectionsColl.find_one({ '$and': [{ 'user_id': User.fromEmail('*****@*****.**').uuid }, { 'type': 'move' }, { 'mode': 1 }] }) old_sec_1['_id'] = 'old_sec_1' old_sec_1['section_start_datetime'] = self.weekago - timedelta( minutes=30) old_sec_1['section_end_datetime'] = self.weekago - timedelta(minutes=5) logging.debug("Inserting old_sec_1 %s" % old_sec_1) self.SectionsColl.insert(old_sec_1) # This one is a month old monthago = self.now - timedelta(days=30) old_sec_2 = self.SectionsColl.find_one({ '$and': [{ 'user_id': User.fromEmail('*****@*****.**').uuid }, { 'type': 'move' }, { 'mode': 4 }] }) old_sec_2['_id'] = 'old_sec_2' old_sec_2['section_start_datetime'] = monthago - timedelta(minutes=30) old_sec_2['section_end_datetime'] = monthago - timedelta(minutes=5) logging.debug("Inserting old_sec_2 %s" % old_sec_2) self.SectionsColl.insert(old_sec_2) # This one is missing the predicted mode monthago = self.now - timedelta(days=30) un_pred_sec = self.SectionsColl.find_one({ '$and': [{ 'user_id': User.fromEmail('*****@*****.**').uuid }, { 'type': 'move' }, { 'mode': 4 }] }) un_pred_sec['_id'] = 'un_pred_sec' del un_pred_sec['predicted_mode'] logging.debug("Inserting un_pred_sec %s" % un_pred_sec) self.SectionsColl.insert(un_pred_sec) queriedUnclassifiedSections = tripManager.queryUnclassifiedSections( User.fromEmail('*****@*****.**').uuid) self.assertEqual(queriedUnclassifiedSections.count(), 2)
def testQueryUnclassifiedSectionsLowConfidence(self): fakeEmail = "*****@*****.**" client = Client("testclient") client.update(createKey=False) emission.tests.common.makeValid(client) (resultPre, resultReg) = client.preRegister("this_is_the_super_secret_id", fakeEmail) self.assertEqual(resultPre, 0) self.assertEqual(resultReg, 1) user = User.fromEmail(fakeEmail) self.assertEqual(user.getFirstStudy(), 'testclient') queriedUnclassifiedSections = tripManager.queryUnclassifiedSections( User.fromEmail(fakeEmail).uuid) self.assertEqual(queriedUnclassifiedSections.count(), 2) # Set the auto_confirmed values for the trips for section in queriedUnclassifiedSections: print section['_id'] self.SectionsColl.update({'_id': section['_id']}, { 'test_auto_confirmed': { 'mode': section['mode'], 'prob': 0.95 } }) # Now, set the update timestamp to two weeks ago so that we will start filtering emission.tests.common.updateUserCreateTime(user.uuid) queriedUnclassifiedSections = tripManager.queryUnclassifiedSections( User.fromEmail(fakeEmail).uuid) self.assertEqual(queriedUnclassifiedSections.count(), 0)