示例#1
0
  def setUp(self):
    self.testUsers = ["*****@*****.**", "*****@*****.**", "*****@*****.**",
                      "*****@*****.**", "*****@*****.**"]
    self.serverName = 'localhost'

    # Sometimes, we may have entries left behind in the database if one of the tests failed
    # or threw an exception, so let us start by cleaning up all entries
    tests.common.dropAllCollections(get_db())
    self.ModesColl = get_mode_db()
    # self.ModesColl.remove()
    self.assertEquals(self.ModesColl.find().count(), 0)

    self.SectionsColl = get_section_db()
    # self.SectionsColl.remove()
    self.assertEquals(self.SectionsColl.find().count(), 0)

    load_database_json.loadTable(self.serverName, "Stage_Modes", "tests/data/modes.json")
    load_database_json.loadTable(self.serverName, "Stage_Sections", "tests/data/testCarbonFile")

    # Let's make sure that the users are registered so that they have profiles
    for userEmail in self.testUsers:
      User.register(userEmail)

    self.walkExpect = 1057.2524056424411
    self.busExpect = 2162.668467546699
    self.busCarbon = 267.0/1609

    self.now = datetime.now()
    self.dayago = self.now - timedelta(days=1)
    self.weekago = self.now - timedelta(weeks = 1)
    tests.common.updateSections(self)
    def setUp(self):
        self.testUsers = [
            "*****@*****.**", "*****@*****.**", "*****@*****.**",
            "*****@*****.**", "*****@*****.**"
        ]
        self.serverName = 'localhost'

        # Sometimes, we may have entries left behind in the database if one of the tests failed
        # or threw an exception, so let us start by cleaning up all entries
        tests.common.dropAllCollections(get_db())
        self.ModesColl = get_mode_db()
        # self.ModesColl.remove()
        self.assertEquals(self.ModesColl.find().count(), 0)

        self.SectionsColl = get_section_db()
        # self.SectionsColl.remove()
        self.assertEquals(self.SectionsColl.find().count(), 0)

        load_database_json.loadTable(self.serverName, "Stage_Modes",
                                     "tests/data/modes.json")
        load_database_json.loadTable(self.serverName, "Stage_Sections",
                                     "tests/data/testCarbonFile")

        # Let's make sure that the users are registered so that they have profiles
        for userEmail in self.testUsers:
            User.register(userEmail)

        self.walkExpect = 1057.2524056424411
        self.busExpect = 2162.668467546699
        self.busCarbon = 267.0 / 1609

        self.now = datetime.now()
        self.dayago = self.now - timedelta(days=1)
        self.weekago = self.now - timedelta(weeks=1)
        tests.common.updateSections(self)
示例#3
0
    def testRunBackgroundTasksForDay(self):
        self.testUsers = [
            "*****@*****.**", "*****@*****.**", "*****@*****.**",
            "*****@*****.**", "*****@*****.**"
        ]
        load_database_json.loadTable(self.serverName, "Stage_Modes",
                                     "tests/data/modes.json")
        load_database_json.loadTable(self.serverName, "Stage_Sections",
                                     "tests/data/testCarbonFile")

        # Let's make sure that the users are registered so that they have profiles
        for userEmail in self.testUsers:
            User.register(userEmail)

        self.SectionsColl = get_section_db()
        tests.common.updateSections(self)

        self.assertNotEqual(len(self.uuid_list), 0)
        # Can access the zeroth element because we know that then length is greater than zero
        # (see above)
        test_uuid = self.uuid_list[0]
        test_user = User.fromUUID(test_uuid)
        self.assertNotIn('carbon_footprint', test_user.getProfile().keys())
        default.runBackgroundTasks(test_user.uuid)
        self.assertIn('carbon_footprint', test_user.getProfile().keys())
 def testLoadTable(self):
   load_database_json.loadTable(self.serverName, "Test_Groups", "CFC_DataCollector/tests/data/groups.json")
   Testdb = MongoClient(self.serverName).Test_database
   GroupsColl=Testdb.Test_Groups
   self.assertEqual(GroupsColl.find().count(), 5)
   GroupsColl.remove()
   self.assertEqual(GroupsColl.find().count(), 0)
示例#5
0
 def setUp(self):
   # Make sure we start with a clean slate every time
   self.serverName = 'localhost'
   common.dropAllCollections(get_db())
   logging.info("After setup, client count = %d, profile count = %d, uuid count = %d" % 
     (get_client_db().find().count(), get_profile_db().count(), get_uuid_db().count()))
   load_database_json.loadTable(self.serverName, "Stage_Modes", "tests/data/modes.json")
示例#6
0
    def setUp(self):
        import tests.common
        from copy import copy

        self.testUsers = ["*****@*****.**", "*****@*****.**", "*****@*****.**",
                      "*****@*****.**", "*****@*****.**"]
        self.serverName = 'localhost'

        # Sometimes, we may have entries left behind in the database if one of the tests failed
        # or threw an exception, so let us start by cleaning up all entries
        tests.common.dropAllCollections(get_db())
        self.ModesColl = get_mode_db()
        self.assertEquals(self.ModesColl.find().count(), 0)

        self.setupUserAndClient()

        load_database_json.loadTable(self.serverName, "Stage_Modes", "tests/data/modes.json")
        load_database_json.loadTable(self.serverName, "Stage_Sections", "tests/data/testCarbonFile")
        self.SectionsColl = get_section_db()

        self.walkExpect = 1057.2524056424411
        self.busExpect = 2162.668467546699
        self.busCarbon = 267.0/1609
        self.airCarbon = 217.0/1609
        self.driveCarbon = 278.0/1609
        self.busOptimalCarbon = 92.0/1609

        self.allDriveExpect = (self.busExpect * self.driveCarbon + self.walkExpect * self.driveCarbon)/1000
        self.myFootprintExpect = float(self.busExpect * self.busCarbon)/1000
        self.sb375GoalExpect = 40.142892/7

        self.mineMinusOptimalExpect = 0
        self.allDriveMinusMineExpect = float(self.allDriveExpect - self.myFootprintExpect)/self.allDriveExpect
        self.sb375DailyGoalMinusMineExpect = float(self.sb375GoalExpect - self.myFootprintExpect)/self.sb375GoalExpect

        self.now = datetime.now()
        self.twodaysago = self.now - timedelta(days=2)
        self.weekago = self.now - timedelta(weeks = 1)

        for section in self.SectionsColl.find():
            section['section_start_datetime'] = self.twodaysago
            section['section_end_datetime'] = self.twodaysago + timedelta(hours = 1)
            section['predicted_mode'] = {'walking': 1.0}
            if section['user_id'] == '*****@*****.**':
                logging.debug("Setting user_id for section %s, %s = %s" %
                    (section['trip_id'], section['section_id'], self.user.uuid))
                section['user_id'] = self.user.uuid
            if section['confirmed_mode'] == 5:
                airSection = copy(section)
                airSection['confirmed_mode'] = 9
                airSection['_id'] = section['_id'] + "_air"
                self.SectionsColl.insert(airSection)
                airSection['confirmed_mode'] = ''
                airSection['_id'] = section['_id'] + "_unconf"
                self.SectionsColl.insert(airSection)
          
            # print("Section start = %s, section end = %s" %
            #   (section['section_start_datetime'], section['section_end_datetime']))
            self.SectionsColl.save(section)
示例#7
0
 def testLoadTable(self):
     load_database_json.loadTable(
         self.serverName, "Test_Groups",
         "CFC_DataCollector/tests/data/groups.json")
     Testdb = MongoClient(self.serverName).Test_database
     GroupsColl = Testdb.Test_Groups
     self.assertEqual(GroupsColl.find().count(), 5)
     GroupsColl.remove()
     self.assertEqual(GroupsColl.find().count(), 0)
示例#8
0
    def setUp(self):
        import tests.common
        from copy import copy

        self.testUsers = [
            "*****@*****.**", "*****@*****.**", "*****@*****.**",
            "*****@*****.**", "*****@*****.**"
        ]
        self.serverName = 'localhost'

        # Sometimes, we may have entries left behind in the database if one of the tests failed
        # or threw an exception, so let us start by cleaning up all entries
        tests.common.dropAllCollections(get_db())
        self.ModesColl = get_mode_db()
        self.assertEquals(self.ModesColl.find().count(), 0)

        load_database_json.loadTable(self.serverName, "Stage_Modes",
                                     "tests/data/modes.json")
        load_database_json.loadTable(self.serverName, "Stage_Sections",
                                     "tests/data/testCarbonFile")
        self.SectionsColl = get_section_db()

        self.walkExpect = 1057.2524056424411
        self.busExpect = 2162.668467546699
        self.busCarbon = 267.0 / 1609
        self.airCarbon = 217.0 / 1609
        self.driveCarbon = 278.0 / 1609
        self.busOptimalCarbon = 92.0 / 1609

        self.now = datetime.now()
        self.dayago = self.now - timedelta(days=1)
        self.weekago = self.now - timedelta(weeks=1)

        for section in self.SectionsColl.find():
            section['section_start_datetime'] = self.dayago
            section['section_end_datetime'] = self.dayago + timedelta(hours=1)
            # Note that we currently only search by the date/time of the section, not the points.
            # If we ever change that, this test will start failing and will need to be fixed as well
            track_pt_array = []
            for i in range(10):
                track_pt_array.append({
                    'time': '20140829T170451-0700',
                    'track_location': {
                        'coordinates': [-122.114642519, 37.4021455446],
                        'type': 'Point'
                    }
                })
                track_pt_array.append({
                    'time': '20140829T170620-0700',
                    'track_location': {
                        'coordinates': [-122.1099155383, 37.399523614],
                        'type': 'Point'
                    }
                })
            section['track_points'] = track_pt_array
            self.SectionsColl.save(section)
  def testDumpTable(self):
    rawFile = "CFC_DataCollector/tests/data/groups.json"
    dumpedFile = "/tmp/dumpedGroups"

    load_database_json.loadTable(self.serverName, "Test_Groups", rawFile)
    dump_database_json.dumpTable(self.serverName, "Test_Groups", dumpedFile)

    expectedStr = open(rawFile).readline()
    dumpedStr = open(dumpedFile).readline() + "\n"

    self.assertEqual(len(dumpedStr), len(expectedStr))
    self.assertEqual(dumpedStr, expectedStr)
示例#10
0
  def setUp(self):
    import tests.common

    self.serverName = 'localhost'

    # Make sure we start with a clean slate every time
    tests.common.dropAllCollections(get_db())
    
    # Load modes, otherwise the queries won't work properly
    load_database_json.loadTable(self.serverName, "Stage_Modes", "tests/data/modes.json")
    self.dayago = datetime.now() - timedelta(days=1)
    self.now = datetime.now()
示例#11
0
    def setUp(self):
        self.testUsers = [
            "*****@*****.**", "*****@*****.**", "*****@*****.**",
            "*****@*****.**", "*****@*****.**"
        ]
        self.serverName = 'localhost'

        # Sometimes, we may have entries left behind in the database if one of the tests failed
        # or threw an exception, so let us start by cleaning up all entries
        tests.common.dropAllCollections(get_db())

        self.ModesColl = get_mode_db()
        self.assertEquals(self.ModesColl.find().count(), 0)

        self.SectionsColl = get_section_db()
        self.assertEquals(self.SectionsColl.find().count(), 0)

        load_database_json.loadTable(self.serverName, "Stage_Modes",
                                     "tests/data/modes.json")
        load_database_json.loadTable(self.serverName, "Stage_Sections",
                                     "tests/data/testModeInferFile")

        # Let's make sure that the users are registered so that they have profiles
        for userEmail in self.testUsers:
            User.register(userEmail)

        self.now = datetime.now()
        self.dayago = self.now - timedelta(days=1)
        self.weekago = self.now - timedelta(weeks=1)

        for section in self.SectionsColl.find():
            section['section_start_datetime'] = self.dayago
            section['section_end_datetime'] = self.dayago + timedelta(hours=1)
            if (section['confirmed_mode'] == 5):
                # We only cluster bus and train trips
                # And our test data only has bus trips
                section['section_start_point'] = {
                    u'type': u'Point',
                    u'coordinates': [-122.270039042, 37.8800285728]
                }
                section['section_end_point'] = {
                    u'type': u'Point',
                    u'coordinates': [-122.2690412952, 37.8739578595]
                }
            # print("Section start = %s, section end = %s" %
            #   (section['section_start_datetime'], section['section_end_datetime']))
            # Replace the user email with the UUID
            section['user_id'] = User.fromEmail(section['user_id']).uuid
            self.SectionsColl.save(section)

        self.pipeline = pipeline.ModeInferencePipeline()
        self.testLoadTrainingData()
示例#12
0
    def testDumpTable(self):
        rawFile = "CFC_DataCollector/tests/data/groups.json"
        dumpedFile = "/tmp/dumpedGroups"

        load_database_json.loadTable(self.serverName, "Test_Groups", rawFile)
        dump_database_json.dumpTable(self.serverName, "Test_Groups",
                                     dumpedFile)

        expectedStr = open(rawFile).readline()
        dumpedStr = open(dumpedFile).readline() + "\n"

        self.assertEqual(len(dumpedStr), len(expectedStr))
        self.assertEqual(dumpedStr, expectedStr)
示例#13
0
    def setUp(self):
        import tests.common
        from copy import copy

        self.testUsers = [
            "*****@*****.**", "*****@*****.**", "*****@*****.**",
            "*****@*****.**", "*****@*****.**"
        ]
        self.serverName = 'localhost'

        # Sometimes, we may have entries left behind in the database if one of the tests failed
        # or threw an exception, so let us start by cleaning up all entries
        tests.common.dropAllCollections(get_db())
        self.ModesColl = get_mode_db()
        self.assertEquals(self.ModesColl.find().count(), 0)

        load_database_json.loadTable(self.serverName, "Stage_Modes",
                                     "tests/data/modes.json")
        load_database_json.loadTable(self.serverName, "Stage_Sections",
                                     "tests/data/testCarbonFile")
        self.SectionsColl = get_section_db()

        self.walkExpect = 1057.2524056424411
        self.busExpect = 2162.668467546699
        self.busCarbon = 267.0 / 1609
        self.airCarbon = 217.0 / 1609
        self.driveCarbon = 278.0 / 1609
        self.busOptimalCarbon = 92.0 / 1609

        self.now = datetime.now()
        self.dayago = self.now - timedelta(days=1)
        self.weekago = self.now - timedelta(weeks=1)

        for section in self.SectionsColl.find():
            section['section_start_datetime'] = self.dayago
            section['section_end_datetime'] = self.dayago + timedelta(hours=1)
            if section['confirmed_mode'] == 5:
                airSection = copy(section)
                airSection['confirmed_mode'] = 9
                airSection['_id'] = section['_id'] + "_air"
                self.SectionsColl.insert(airSection)

            # print("Section start = %s, section end = %s" %
            #   (section['section_start_datetime'], section['section_end_datetime']))
            self.SectionsColl.save(section)
示例#14
0
  def setUp(self):
    import tests.common
    from copy import copy

    self.testUsers = ["*****@*****.**", "*****@*****.**", "*****@*****.**",
                      "*****@*****.**", "*****@*****.**"]
    self.serverName = 'localhost'

    # Sometimes, we may have entries left behind in the database if one of the tests failed
    # or threw an exception, so let us start by cleaning up all entries
    tests.common.dropAllCollections(get_db())
    self.ModesColl = get_mode_db()
    self.assertEquals(self.ModesColl.find().count(), 0)

    load_database_json.loadTable(self.serverName, "Stage_Modes", "tests/data/modes.json")
    load_database_json.loadTable(self.serverName, "Stage_Sections", "tests/data/testCarbonFile")
    self.SectionsColl = get_section_db()

    self.walkExpect = 1057.2524056424411
    self.busExpect = 2162.668467546699
    self.busCarbon = 267.0/1609
    self.airCarbon = 217.0/1609
    self.driveCarbon = 278.0/1609
    self.busOptimalCarbon = 92.0/1609

    self.now = datetime.now()
    self.dayago = self.now - timedelta(days=1)
    self.weekago = self.now - timedelta(weeks = 1)

    for section in self.SectionsColl.find():
      section['section_start_datetime'] = self.dayago
      section['section_end_datetime'] = self.dayago + timedelta(hours = 1)
      # Note that we currently only search by the date/time of the section, not the points.
      # If we ever change that, this test will start failing and will need to be fixed as well
      track_pt_array = []
      for i in range(10):
          track_pt_array.append({'time': '20140829T170451-0700',
                 'track_location': {'coordinates': [-122.114642519, 37.4021455446],
                                            'type': 'Point'}})
          track_pt_array.append({'time': '20140829T170620-0700',
                   'track_location': {'coordinates': [-122.1099155383, 37.399523614],
                    'type': 'Point'}})
      section['track_points'] = track_pt_array
      self.SectionsColl.save(section)
示例#15
0
    def testGetUnclassifiedSectionsFiltered(self):
        """
    Tests that queryUnclassifiedSections never returns 
    a section with section['retained'] == False. A section is only returned if 
    section['retained'] == True  and all other query conditions are met    
    """
        # Clear previous Stage_Sections data and load new data
        # specific to filtering
        self.SectionsColl.remove()
        load_database_json.loadTable(self.serverName, "Stage_Sections",
                                     "tests/data/testFilterFile")
        tests.common.updateSections(self)
        # Extra updates to Sections necessary for testing filtering
        for section in self.SectionsColl.find():
            section['section_start_point'] = "filler start point"
            section['section_end_point'] = "filler end point"
            self.SectionsColl.save(section)

        from dao.user import User
        fakeEmail = "*****@*****.**"

        client = Client("testclient")
        client.update(createKey=False)
        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')

        unclassifiedSections = tripManager.getUnclassifiedSections(
            User.fromEmail(fakeEmail).uuid)['sections']
        # Check that of the valid sections in the testFilterFile (2/3), only one of them is returned by the query
        self.assertEqual(len(unclassifiedSections), 1)
        # Check that the second entry in the testFilterFile is the only section
        # that is loaded into the database
        self.assertEqual('20140401T095742-0700',
                         unclassifiedSections[0]['trip_id'])
示例#16
0
  def setUp(self):
    self.testUsers = ["*****@*****.**", "*****@*****.**", "*****@*****.**",
                      "*****@*****.**", "*****@*****.**"]
    self.serverName = 'localhost'

    # Sometimes, we may have entries left behind in the database if one of the tests failed
    # or threw an exception, so let us start by cleaning up all entries
    tests.common.dropAllCollections(get_db())
    self.ModesColl = get_mode_db()
    # self.ModesColl.remove()
    self.assertEquals(self.ModesColl.find().count(), 0)

    self.SectionsColl = get_section_db()
    # self.SectionsColl.remove()
    self.assertEquals(self.SectionsColl.find().count(), 0)

    load_database_json.loadTable(self.serverName, "Stage_Modes", "tests/data/modes.json")
    load_database_json.loadTable(self.serverName, "Stage_Sections", "tests/data/testCarbonFile")

    # Let's make sure that the users are registered so that they have profiles
    for userEmail in self.testUsers:
      User.register(userEmail)

    self.walkExpect = 1057.2524056424411
    self.busExpect = 2162.668467546699
    self.busCarbon = 267.0/1609

    self.now = datetime.now()
    self.dayago = self.now - timedelta(days=1)
    self.weekago = self.now - timedelta(weeks = 1)

    for section in self.SectionsColl.find():
      section['section_start_datetime'] = self.dayago
      section['section_end_datetime'] = self.dayago + timedelta(hours = 1)
      section['predicted_mode'] = [0, 0.4, 0.6, 0]
      section['confirmed_mode'] = ''
      # print("Section start = %s, section end = %s" %
      #   (section['section_start_datetime'], section['section_end_datetime']))
      # Replace the user email with the UUID
      section['user_id'] = User.fromEmail(section['user_id']).uuid
      self.SectionsColl.save(section)
示例#17
0
  def setUp(self):
    import tests.common
    from copy import copy

    self.testUsers = ["*****@*****.**", "*****@*****.**", "*****@*****.**",
                      "*****@*****.**", "*****@*****.**"]
    self.serverName = 'localhost'

    # Sometimes, we may have entries left behind in the database if one of the tests failed
    # or threw an exception, so let us start by cleaning up all entries
    tests.common.dropAllCollections(get_db())
    self.ModesColl = get_mode_db()
    self.assertEquals(self.ModesColl.find().count(), 0)

    load_database_json.loadTable(self.serverName, "Stage_Modes", "tests/data/modes.json")
    load_database_json.loadTable(self.serverName, "Stage_Sections", "tests/data/testCarbonFile")
    self.SectionsColl = get_section_db()

    self.walkExpect = 1057.2524056424411
    self.busExpect = 2162.668467546699
    self.busCarbon = 267.0/1609
    self.airCarbon = 217.0/1609
    self.driveCarbon = 278.0/1609
    self.busOptimalCarbon = 92.0/1609

    self.now = datetime.now()
    self.dayago = self.now - timedelta(days=1)
    self.weekago = self.now - timedelta(weeks = 1)

    for section in self.SectionsColl.find():
      section['section_start_datetime'] = self.dayago
      section['section_end_datetime'] = self.dayago + timedelta(hours = 1)
      if section['confirmed_mode'] == 5:
        airSection = copy(section)
        airSection['confirmed_mode'] = 9
        airSection['_id'] = section['_id'] + "_air"
        self.SectionsColl.insert(airSection)
          
      # print("Section start = %s, section end = %s" %
      #   (section['section_start_datetime'], section['section_end_datetime']))
      self.SectionsColl.save(section)
示例#18
0
    def testRunBackgroundTasksForDay(self):
        self.testUsers = ["*****@*****.**", "*****@*****.**", "*****@*****.**",
                          "*****@*****.**", "*****@*****.**"]
        load_database_json.loadTable(self.serverName, "Stage_Modes", "tests/data/modes.json")
        load_database_json.loadTable(self.serverName, "Stage_Sections", "tests/data/testCarbonFile")

        # Let's make sure that the users are registered so that they have profiles
        for userEmail in self.testUsers:
          User.register(userEmail)

        self.SectionsColl = get_section_db()
        tests.common.updateSections(self)

        self.assertNotEqual(len(self.uuid_list), 0)
        # Can access the zeroth element because we know that then length is greater than zero
        # (see above)
        test_uuid = self.uuid_list[0]
        test_user = User.fromUUID(test_uuid)
        self.assertNotIn('carbon_footprint', test_user.getProfile().keys())
        data.runBackgroundTasks(test_user.uuid)
        self.assertIn('carbon_footprint', test_user.getProfile().keys())
    def setUp(self):
        self.testUsers = ["*****@*****.**", "*****@*****.**", "*****@*****.**",
                          "*****@*****.**", "*****@*****.**"]
        self.serverName = 'localhost'

        # Sometimes, we may have entries left behind in the database if one of the tests failed
        # or threw an exception, so let us start by cleaning up all entries
        tests.common.dropAllCollections(get_db())

        self.ModesColl = get_mode_db()
        self.assertEquals(self.ModesColl.find().count(), 0)

        self.SectionsColl = get_section_db()
        self.assertEquals(self.SectionsColl.find().count(), 0)

        load_database_json.loadTable(self.serverName, "Stage_Modes", "tests/data/modes.json")
        load_database_json.loadTable(self.serverName, "Stage_Sections", "tests/data/testModeInferFile")

        # Let's make sure that the users are registered so that they have profiles
        for userEmail in self.testUsers:
          User.register(userEmail)

        self.now = datetime.now()
        self.dayago = self.now - timedelta(days=1)
        self.weekago = self.now - timedelta(weeks = 1)

        for section in self.SectionsColl.find():
          section['section_start_datetime'] = self.dayago
          section['section_end_datetime'] = self.dayago + timedelta(hours = 1)
          if (section['confirmed_mode'] == 5):
            # We only cluster bus and train trips
            # And our test data only has bus trips
            section['section_start_point'] = {u'type': u'Point', u'coordinates': [-122.270039042, 37.8800285728]}
            section['section_end_point'] = {u'type': u'Point', u'coordinates': [-122.2690412952, 37.8739578595]}
          # print("Section start = %s, section end = %s" %
          #   (section['section_start_datetime'], section['section_end_datetime']))
          # Replace the user email with the UUID
          section['user_id'] = User.fromEmail(section['user_id']).uuid
          self.SectionsColl.save(section)
          self.pr = precompute_results.PrecomputeResults()
示例#20
0
  def testGetUnclassifiedSectionsFiltered(self):
    """
    Tests that queryUnclassifiedSections never returns 
    a section with section['retained'] == False. A section is only returned if 
    section['retained'] == True  and all other query conditions are met    
    """
    # Clear previous Stage_Sections data and load new data
    # specific to filtering
    self.SectionsColl.remove()
    load_database_json.loadTable(self.serverName, "Stage_Sections", "tests/data/testFilterFile")   
    tests.common.updateSections(self) 
    # Extra updates to Sections necessary for testing filtering
    for section in self.SectionsColl.find():
      section['section_start_point'] = "filler start point"
      section['section_end_point'] = "filler end point"   
      self.SectionsColl.save(section)

    from dao.user import User
    fakeEmail = "*****@*****.**"

    client = Client("testclient")
    client.update(createKey = False)
    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')

    unclassifiedSections = tripManager.getUnclassifiedSections(User.fromEmail(fakeEmail).uuid)['sections']
    # Check that of the valid sections in the testFilterFile (2/3), only one of them is returned by the query
    self.assertEqual(len(unclassifiedSections), 1)
    # Check that the second entry in the testFilterFile is the only section 
    # that is loaded into the database
    self.assertEqual('20140401T095742-0700',unclassifiedSections[0]['trip_id'])                     
示例#21
0
    def setUp(self):
        import tests.common
        from copy import copy

        self.testUsers = [
            "*****@*****.**", "*****@*****.**", "*****@*****.**",
            "*****@*****.**", "*****@*****.**"
        ]
        self.serverName = 'localhost'

        # Sometimes, we may have entries left behind in the database if one of the tests failed
        # or threw an exception, so let us start by cleaning up all entries
        tests.common.dropAllCollections(get_db())
        self.ModesColl = get_mode_db()
        self.assertEquals(self.ModesColl.find().count(), 0)

        self.setupUserAndClient()

        load_database_json.loadTable(self.serverName, "Stage_Modes",
                                     "tests/data/modes.json")
        load_database_json.loadTable(self.serverName, "Stage_Sections",
                                     "tests/data/testCarbonFile")
        self.SectionsColl = get_section_db()

        self.walkExpect = 1057.2524056424411
        self.busExpect = 2162.668467546699
        self.busCarbon = 267.0 / 1609
        self.airCarbon = 217.0 / 1609
        self.driveCarbon = 278.0 / 1609
        self.busOptimalCarbon = 92.0 / 1609

        self.allDriveExpect = (self.busExpect * self.driveCarbon +
                               self.walkExpect * self.driveCarbon) / 1000
        self.myFootprintExpect = (self.busExpect * self.busCarbon) / 1000
        self.sb375GoalExpect = 40.142892 / 7

        self.mineMinusOptimalExpect = 0
        self.allDriveMinusMineExpect = (
            self.allDriveExpect - self.myFootprintExpect) / self.allDriveExpect
        self.sb375DailyGoalMinusMineExpect = (
            self.sb375GoalExpect -
            self.myFootprintExpect) / self.sb375GoalExpect

        self.now = datetime.now()
        self.twodaysago = self.now - timedelta(days=2)
        self.weekago = self.now - timedelta(weeks=1)

        for section in self.SectionsColl.find():
            section['section_start_datetime'] = self.twodaysago
            section['section_end_datetime'] = self.twodaysago + timedelta(
                hours=1)
            section['predicted_mode'] = {'walking': 1.0}
            if section['user_id'] == '*****@*****.**':
                logging.debug("Setting user_id for section %s, %s = %s" %
                              (section['trip_id'], section['section_id'],
                               self.user.uuid))
                section['user_id'] = self.user.uuid
            if section['confirmed_mode'] == 5:
                airSection = copy(section)
                airSection['confirmed_mode'] = 9
                airSection['_id'] = section['_id'] + "_air"
                self.SectionsColl.insert(airSection)
                airSection['confirmed_mode'] = ''
                airSection['_id'] = section['_id'] + "_unconf"
                self.SectionsColl.insert(airSection)

            # print("Section start = %s, section end = %s" %
            #   (section['section_start_datetime'], section['section_end_datetime']))
            self.SectionsColl.save(section)
示例#22
0
def setupForTesting(serverName):
  load_database_json.loadTable(serverName, "Test_Groups", "tests/data/groups.json")
  load_database_json.loadTable(serverName, "Test_Modes", "tests/data/modes.json")