def testGetClassifiedRatioWithoutPredictions(self):
    from copy import copy

    # This doesn't really require track points, so let us insert fake data that 
    # has distances, predicted modes and confirmed modes
    # 3 sections are confirmed, 3 sections are not yet predicted, classifiedRatio = 1.0
    (user, dummySection, dummyPredModeMap) = self.setupClientTest()

    for i in range(0, 3):
        predSection = copy(dummySection)
        predSection['_id'] = "%s confirmed" % (i)
        predSection['type'] = 'move'
        predSection['confirmed_mode'] = "5"
        predSection['user_id'] = user.uuid
        get_database.get_section_db().insert(predSection)

        noPredSection = copy(dummySection)
        noPredSection['_id'] = "%s nopred" % (i)
        noPredSection['type'] = 'move'
        noPredSection['user_id'] = user.uuid
        del noPredSection['predicted_mode']
        self.assertIn('predicted_mode', predSection)
        get_database.get_section_db().insert(noPredSection)

    logging.debug("After inserting sections, count is %s" % get_database.get_section_db().find().count())
    logging.debug("Manual query count = %s" % get_database.get_section_db().find({'$and': [{'source': 'Shankari'}, {'user_id': user.uuid}, {'predicted_mode': {'$exists': True}}, {'type': 'move'}]}).count())
    self.assertEqual(common.getClassifiedRatio(user.uuid, self.dayago, self.now), 1)
  def testGetClassifiedRatioWithPredictions(self):
    from copy import copy

    # This doesn't really require track points, so let us insert fake data that 
    # has distances, predicted modes and confirmed modes
    # 3 sections are confirmed, 3 sections are not yet predicted, classifiedRatio = 1.0
    (user, dummySection, dummyPredModeMap) = self.setupClientTest()

    for i in range(0, 3):
        predSection = copy(dummySection)
        predSection['_id'] = "%s confirmed" % (i)
        predSection['type'] = 'move'
        predSection['confirmed_mode'] = "5"
        predSection['user_id'] = user.uuid
        get_database.get_section_db().insert(predSection)

        noPredSection = copy(dummySection)
        noPredSection['_id'] = "%s nopred" % (i)
        noPredSection['type'] = 'move'
        noPredSection['user_id'] = user.uuid
        # moves collect currently sets the confirmed_mode to "", so we must set it here too
        # Otherwise the query won't work
        noPredSection['confirmed_mode'] = ""

        self.assertIn('predicted_mode', predSection)
        self.assertIn('predicted_mode', noPredSection)
        self.assertIn('confirmed_mode', predSection)
        get_database.get_section_db().insert(noPredSection)

    logging.debug("After inserting sections, count is %s" % get_database.get_section_db().find().count())
    logging.debug("Manual query count = %s" % get_database.get_section_db().find({'$and': [{'source': 'Shankari'}, {'user_id': user.uuid}, {'predicted_mode': {'$exists': True}}, {'type': 'move'}]}).count())
    logging.debug("Manual query count classified = %s" % get_database.get_section_db().find({'$and': [{'source': 'Shankari'}, {'user_id': user.uuid}, {'predicted_mode': {'$exists': True}}, {'type': 'move'}, {'confirmed_mode': {"$ne": ''}} ]}).count())

    self.assertEqual(common.getClassifiedRatio(user.uuid, self.dayago, self.now), 3.0/6)
    two_days_ago = datetime.now() - timedelta(days=2)
    self.assertEqual(common.getClassifiedRatio(user.uuid, two_days_ago, self.dayago), 0)
示例#3
0
    def testGetClassifiedRatioWithoutPredictions(self):
        from copy import copy

        # This doesn't really require track points, so let us insert fake data that
        # has distances, predicted modes and confirmed modes
        # 3 sections are confirmed, 3 sections are not yet predicted, classifiedRatio = 1.0
        (user, dummySection, dummyPredModeMap) = self.setupClientTest()

        for i in range(0, 3):
            predSection = copy(dummySection)
            predSection['_id'] = "%s confirmed" % (i)
            predSection['type'] = 'move'
            predSection['confirmed_mode'] = "5"
            predSection['user_id'] = user.uuid
            get_database.get_section_db().insert(predSection)

            noPredSection = copy(dummySection)
            noPredSection['_id'] = "%s nopred" % (i)
            noPredSection['type'] = 'move'
            noPredSection['user_id'] = user.uuid
            del noPredSection['predicted_mode']
            self.assertIn('predicted_mode', predSection)
            get_database.get_section_db().insert(noPredSection)

        logging.debug("After inserting sections, count is %s" %
                      get_database.get_section_db().find().count())
        logging.debug("Manual query count = %s" %
                      get_database.get_section_db().find({
                          '$and': [{
                              'source': 'Shankari'
                          }, {
                              'user_id': user.uuid
                          }, {
                              'predicted_mode': {
                                  '$exists': True
                              }
                          }, {
                              'type': 'move'
                          }]
                      }).count())
        self.assertEqual(
            common.getClassifiedRatio(user.uuid, self.dayago, self.now), 1)
示例#4
0
    def testGetClassifiedRatioWithPredictions(self):
        from copy import copy

        # This doesn't really require track points, so let us insert fake data that
        # has distances, predicted modes and confirmed modes
        # 3 sections are confirmed, 3 sections are not yet predicted, classifiedRatio = 1.0
        (user, dummySection, dummyPredModeMap) = self.setupClientTest()

        for i in range(0, 3):
            predSection = copy(dummySection)
            predSection['_id'] = "%s confirmed" % (i)
            predSection['type'] = 'move'
            predSection['confirmed_mode'] = "5"
            predSection['user_id'] = user.uuid
            get_database.get_section_db().insert(predSection)

            noPredSection = copy(dummySection)
            noPredSection['_id'] = "%s nopred" % (i)
            noPredSection['type'] = 'move'
            noPredSection['user_id'] = user.uuid
            # moves collect currently sets the confirmed_mode to "", so we must set it here too
            # Otherwise the query won't work
            noPredSection['confirmed_mode'] = ""

            self.assertIn('predicted_mode', predSection)
            self.assertIn('predicted_mode', noPredSection)
            self.assertIn('confirmed_mode', predSection)
            get_database.get_section_db().insert(noPredSection)

        logging.debug("After inserting sections, count is %s" %
                      get_database.get_section_db().find().count())
        logging.debug("Manual query count = %s" %
                      get_database.get_section_db().find({
                          '$and': [{
                              'source': 'Shankari'
                          }, {
                              'user_id': user.uuid
                          }, {
                              'predicted_mode': {
                                  '$exists': True
                              }
                          }, {
                              'type': 'move'
                          }]
                      }).count())
        logging.debug("Manual query count classified = %s" %
                      get_database.get_section_db().find({
                          '$and': [{
                              'source': 'Shankari'
                          }, {
                              'user_id': user.uuid
                          }, {
                              'predicted_mode': {
                                  '$exists': True
                              }
                          }, {
                              'type': 'move'
                          }, {
                              'confirmed_mode': {
                                  "$ne": ''
                              }
                          }]
                      }).count())

        self.assertEqual(
            common.getClassifiedRatio(user.uuid, self.dayago, self.now),
            3.0 / 6)
        two_days_ago = datetime.now() - timedelta(days=2)
        self.assertEqual(
            common.getClassifiedRatio(user.uuid, two_days_ago, self.dayago), 0)
示例#5
0
    def testGetClassifiedRatioNoTrips(self):

        self.assertEqual(
            common.getClassifiedRatio('this is fake', self.dayago, self.now),
            0)
  def testGetClassifiedRatioNoTrips(self):

    self.assertEqual(common.getClassifiedRatio('this is fake', self.dayago, self.now), 0)