当前位置: 首页>>代码示例>>Python>>正文


Python user.User类代码示例

本文整理汇总了Python中emission.core.wrapper.user.User的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testChangeUpdateTs

  def testChangeUpdateTs(self):
    from datetime import datetime, timedelta

    user = User.register('[email protected]')
    self.assertTrue(User.isRegistered('[email protected]'))
    user.changeUpdateTs(timedelta(days = -20))
    self.assertEqual((datetime.now() - user.getUpdateTS()).days, 20)
开发者ID:juemura,项目名称:e-mission-server,代码行数:7,代码来源:TestUser.py

示例2: testClientSpecificPrecompute

    def testClientSpecificPrecompute(self):
        for email in self.testUsers:
            currUser = User.fromEmail(email)
            self.assertEqual(currUser.getProfile().get("testfield1"), None)
            self.assertEqual(currUser.getProfile().get("testfield2"), None)
            self.assertEqual(data.getCarbonFootprint(currUser), None)

        fakeEmail = "[email protected]"

        client = Client("testclient")
        client.update(createKey = False)
        emission.tests.common.makeValid(client)

        (resultPre, resultReg) = client.preRegister("this_is_the_super_secret_id", fakeEmail)
        user = User.fromEmail(fakeEmail)
        self.assertEqual(user.getFirstStudy(), 'testclient')

        self.pr.precomputeResults()

        self.assertEqual(user.getProfile()['testfield1'], 'value1')
        self.assertEqual(user.getProfile()['testfield2'], 'value2')

        for email in self.testUsers:
            if email != fakeEmail:
                currUser = User.fromEmail(email)

                carbonFootprint = data.getCarbonFootprint(currUser)
                self.assertEqual(len(carbonFootprint), 12)
开发者ID:adambrown13,项目名称:e-mission-server,代码行数:28,代码来源:TestPrecomputeResults.py

示例3: testQueryUnclassifiedSectionsLowConfidence

  def testQueryUnclassifiedSectionsLowConfidence(self):

    fakeEmail = "[email protected]"

    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)
开发者ID:adambrown13,项目名称:e-mission-server,代码行数:27,代码来源:TestTripManager.py

示例4: testQueryUnclassifiedSectionsWeekAgo

  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('[email protected]').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('[email protected]').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('[email protected]').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('[email protected]').uuid)
    self.assertEqual(queriedUnclassifiedSections.count(), 2)
开发者ID:adambrown13,项目名称:e-mission-server,代码行数:29,代码来源:TestTripManager.py

示例5: setUp

  def setUp(self):
    self.testUsers = ["[email protected]", "[email protected]", "[email protected]",
                      "[email protected]", "[email protected]"]
    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
    emission.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)

    emission.tests.common.loadTable(self.serverName, "Stage_Modes", "emission/tests/data/modes.json")
    emission.tests.common.loadTable(self.serverName, "Stage_Sections", "emission/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)
    emission.tests.common.updateSections(self)
开发者ID:adambrown13,项目名称:e-mission-server,代码行数:31,代码来源:TestTripManager.py

示例6: register_user

def register_user(userEmail):
    """
        Does some sanity checking and then registers the user with the specified email address.
        This is useful for testing.
    """
    if User.fromEmail(userEmail) is not None:
        raise RuntimeError("User with email %s already exists" % userEmail)
    
    userObj = User.register(userEmail)
    
    print "Registration successful!"
    print "User profile is %s" % userObj.getProfile();
开发者ID:adambrown13,项目名称:e-mission-server,代码行数:12,代码来源:create_test_user.py

示例7: testSetClientSpecificFields

  def testSetClientSpecificFields(self):
    user = User.register('[email protected]')
    self.assertTrue(User.isRegistered('[email protected]'))

    # Check that the field doesn't exist initially    
    self.assertTrue(user.getProfile().get('test_field', 'blank'), 'blank')

    # Check that a simple value update works
    user.setClientSpecificProfileFields({'test_field': 'something beautiful'})
    self.assertTrue(user.getProfile().get('test_field', 'blank'), 'something beautiful')

    # Check that a data structure update works
    user.setClientSpecificProfileFields({'test_field': {'something': 'beautiful'}})
    self.assertTrue(user.getProfile().get('test_field', 'blank'), {'something': 'beautiful'})
开发者ID:juemura,项目名称:e-mission-server,代码行数:14,代码来源:TestUser.py

示例8: testGetFirstStudy

  def testGetFirstStudy(self):
    user = User.register('[email protected]')
    self.assertTrue(User.isRegistered('[email protected]'))

    client = Client("testclient")
    client.update(createKey = False)
    common.makeValid(client)

    (resultPre, resultReg) = client.preRegister("this_is_the_super_secret_id", "[email protected]")
    self.assertEqual(resultPre, 0)
    self.assertEqual(resultReg, 1)

    user = User.fromEmail('[email protected]')
    self.assertEqual(user.getFirstStudy(), 'testclient')
开发者ID:juemura,项目名称:e-mission-server,代码行数:14,代码来源:TestUser.py

示例9: testUnsetStudyExists

  def testUnsetStudyExists(self):
    user = User.register('[email protected]')
    user.setStudy('testclient')
    self.assertEquals(userclient.countForStudy('testclient'), 1)

    user.unsetStudy('testclient')
    self.assertEquals(userclient.countForStudy('testclient'), 0)
开发者ID:juemura,项目名称:e-mission-server,代码行数:7,代码来源:TestUser.py

示例10: setUp

 def setUp(self):
     import emission.tests.common
     # 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
     emission.tests.common.dropAllCollections(get_db())
     user = User.register("[email protected]")
     self.uuid = user.uuid
开发者ID:juemura,项目名称:e-mission-server,代码行数:7,代码来源:TestChoice.py

示例11: runBackgroundTasksForDay

def runBackgroundTasksForDay(user_uuid, today):
  today_dt = datetime.combine(today, time.max)
  user = User.fromUUID(user_uuid)

  # carbon compare results is a tuple. Tuples are converted to arrays
  # by mongodb
  # In [44]: testUser.setScores(('a','b', 'c', 'd'), ('s', 't', 'u', 'v'))
  # In [45]: testUser.getScore()
  # Out[45]: ([u'a', u'b', u'c', u'd'], [u's', u't', u'u', u'v'])
  weekago = today_dt - timedelta(days=7)
  carbonCompareResults = carbon.getFootprintCompareForRange(user_uuid, weekago, today_dt)
  setCarbonFootprint(user, carbonCompareResults)

  (myModeShareCount, avgModeShareCount,
     myModeShareDistance, avgModeShareDistance,
     myModeCarbonFootprint, avgModeCarbonFootprint,
     myModeCarbonFootprintNoLongMotorized, avgModeCarbonFootprintNoLongMotorized, # ignored
     myOptimalCarbonFootprint, avgOptimalCarbonFootprint,
     myOptimalCarbonFootprintNoLongMotorized, avgOptimalCarbonFootprintNoLongMotorized) = carbonCompareResults
  # We only compute server stats in the background, because including them in
  # the set call means that they may be invoked when the user makes a call and
  # the cached value is None, which would potentially slow down user response time
  msNow = systime.time()
  stats.storeResultEntry(user_uuid, stats.STAT_MY_CARBON_FOOTPRINT, msNow, getCategorySum(myModeCarbonFootprint))
  stats.storeResultEntry(user_uuid, stats.STAT_MY_CARBON_FOOTPRINT_NO_AIR, msNow, getCategorySum(myModeCarbonFootprintNoLongMotorized))
  stats.storeResultEntry(user_uuid, stats.STAT_MY_OPTIMAL_FOOTPRINT, msNow, getCategorySum(myOptimalCarbonFootprint))
  stats.storeResultEntry(user_uuid, stats.STAT_MY_OPTIMAL_FOOTPRINT_NO_AIR, msNow, getCategorySum(myOptimalCarbonFootprintNoLongMotorized))
  stats.storeResultEntry(user_uuid, stats.STAT_MY_ALLDRIVE_FOOTPRINT, msNow, getCategorySum(myModeShareDistance) * (278.0/(1609 * 1000)))
  stats.storeResultEntry(user_uuid, stats.STAT_MEAN_FOOTPRINT, msNow, getCategorySum(avgModeCarbonFootprint))
  stats.storeResultEntry(user_uuid, stats.STAT_MEAN_FOOTPRINT_NO_AIR, msNow, getCategorySum(avgModeCarbonFootprintNoLongMotorized))
开发者ID:adambrown13,项目名称:e-mission-server,代码行数:30,代码来源:data.py

示例12: setupClientTest

  def setupClientTest(self):
    # At this point, the more important test is to execute the query and see
    # how well it works

    fakeEmail = "[email protected]"

    client = Client("testclient")
    client.update(createKey = False)
    emission.tests.common.makeValid(client)

    (resultPre, resultReg) = client.preRegister("this_is_the_super_secret_id", fakeEmail)
    studyList = Client.getPendingClientRegs(fakeEmail)
    self.assertEqual(studyList, ["testclient"])

    user = User.register("[email protected]")
    self.assertEqual(user.getFirstStudy(), 'testclient')

    dummyPredModeMap = {'walking': 1.0}
    dummySection = emission.tests.common.createDummySection(
        startTime = datetime.now() - timedelta(seconds = 60 * 60),
        endTime = datetime.now(),
        startLoc = [-122, 34],
        endLoc = [-122, 35],
        predictedMode = dummyPredModeMap)
    return (user, dummySection, dummyPredModeMap)
开发者ID:adambrown13,项目名称:e-mission-server,代码行数:25,代码来源:TestCommon.py

示例13: testSavePredictionsStepWithClient

  def testSavePredictionsStepWithClient(self):
    from emission.core.wrapper.user import User

    fakeEmail = "[email protected]"

    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')

    self.testPredictedProb()
    self.pipeline.savePredictionsStep()
    # Confirm that the predictions are saved correctly

    test_id_1_sec = self.SectionsColl.find_one({'_id': 'test_id_1'})
    self.assertIsNotNone(test_id_1_sec['predicted_mode'])
    self.assertEquals(test_id_1_sec['predicted_mode'], {'walking': 1})
    self.assertEquals(test_id_1_sec['test_auto_confirmed'], {'mode': 1, 'prob': 1.0})

    test_id_2_sec = self.SectionsColl.find_one({'_id': 'test_id_2'})
    self.assertIsNotNone(test_id_2_sec['predicted_mode'])
    self.assertEquals(test_id_2_sec['predicted_mode'], {'bus': 1})
    self.assertEquals(test_id_2_sec['test_auto_confirmed'], {'mode': 5, 'prob': 1.0})

    # Let's make sure that we didn't accidentally mess up other fields
    self.assertIsNotNone(test_id_1_sec['distance'])
    self.assertIsNotNone(test_id_2_sec['trip_id'])
开发者ID:adambrown13,项目名称:e-mission-server,代码行数:33,代码来源:TestPipeline.py

示例14: testClientSpecificSettersWithOverride

  def testClientSpecificSettersWithOverride(self):
    fakeEmail = "[email protected]"

    client = Client("testclient")
    client.update(createKey = False)
    common.makeValid(client)

    (resultPre, resultReg) = client.preRegister("this_is_the_super_secret_id", fakeEmail)
    studyList = Client.getPendingClientRegs(fakeEmail)
    self.assertEqual(studyList, ["testclient"])

    user = User.register("[email protected]")
    self.assertEqual(user.getFirstStudy(), 'testclient')

    dummyPredModeMap = {'walking': 1.0}
    dummySection = common.createDummySection(startTime = datetime.now() - timedelta(seconds = 60 * 60),
        endTime = datetime.now(),
        startLoc = [-122, 34],
        endLoc = [-122, 35],
        predictedMode = dummyPredModeMap)

    clientSetQuery = client.clientSpecificSetters(user.uuid, dummySection['_id'], dummyPredModeMap)
    self.assertEqual(clientSetQuery, {'$set': {'test_auto_confirmed': {'mode': 1, 'prob': 1.0}}})

    # Apply the change
    get_section_db().update({'_id': dummySection['_id']}, clientSetQuery)
    retrievedSection = get_section_db().find_one({'_id': dummySection['_id']})
    self.assertEqual(retrievedSection['test_auto_confirmed']['mode'], 1)
开发者ID:adambrown13,项目名称:e-mission-server,代码行数:28,代码来源:TestClient.py

示例15: getResult

def getResult(user_uuid):
  # This is in here, as opposed to the top level as recommended by the PEP
  # because then we don't have to worry about loading bottle in the unit tests
  from bottle import template

  user = User.fromUUID(user_uuid)
  currFootprint = getCarbonFootprint(user)

  if currFootprint is None:
    currFootprint = carbon.getFootprintCompare(user_uuid)
    setCarbonFootprint(user, currFootprint)

  (myModeShareCount, avgModeShareCount,
     myModeShareDistance, avgModeShareDistance,
     myModeCarbonFootprint, avgModeCarbonFootprint,
     myModeCarbonFootprintNoLongMotorized, avgModeCarbonFootprintNoLongMotorized, # ignored
     myOptimalCarbonFootprint, avgOptimalCarbonFootprint,
     myOptimalCarbonFootprintNoLongMotorized, avgOptimalCarbonFootprintNoLongMotorized) = currFootprint

  renderedTemplate = template("clients/data/result_template.html",
                      myModeShareCount = json.dumps(myModeShareCount),
                      avgModeShareCount = json.dumps(avgModeShareCount),
                      myModeShareDistance = json.dumps(myModeShareDistance),
                      avgModeShareDistance = json.dumps(avgModeShareDistance),
                      myModeCarbonFootprint = json.dumps(myModeCarbonFootprint),
                      avgModeCarbonFootprint = json.dumps(avgModeCarbonFootprint),
                      myOptimalCarbonFootprint = json.dumps(myOptimalCarbonFootprint),
                      avgOptimalCarbonFootprint = json.dumps(avgOptimalCarbonFootprint))
                  
  # logging.debug(renderedTemplate)
  return renderedTemplate
开发者ID:adambrown13,项目名称:e-mission-server,代码行数:31,代码来源:data.py


注:本文中的emission.core.wrapper.user.User类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。