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


Python User.fromUUID方法代码示例

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


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

示例1: getScoreComponents

# 需要导入模块: from emission.core.wrapper.user import User [as 别名]
# 或者: from emission.core.wrapper.user.User import fromUUID [as 别名]
def getScoreComponents(user_uuid, start, end):
  # The score is based on the following components:
  # - Percentage of trips classified. We are not auto-classifying high
  # confidence trips, so don't need to handle those here
  user = User.fromUUID(user_uuid)

  pctClassified = common.getClassifiedRatio(user_uuid, start, end)

  (myModeShareCount, avgModeShareCount,
   myModeShareDistance, avgModeShareDistance,
   myModeCarbonFootprint, avgModeCarbonFootprint,
   myModeCarbonFootprintNoLongMotorized, avgModeCarbonFootprintNoLongMotorized,
   myOptimalCarbonFootprint, avgOptimalCarbonFootprint,
   myOptimalCarbonFootprintNoLongMotorized, avgOptimalCarbonFootprintNoLongMotorized) = carbon.getFootprintCompareForRange(user.uuid, start, end)

  carbon.delLongMotorizedModes(myModeShareDistance)
  myAllDrive = carbon.getAllDrive(user.uuid, myModeShareDistance)
  myCarbonFootprintSum = sum(myModeCarbonFootprintNoLongMotorized.values())
  myOptimalFootprintSum = sum(myOptimalCarbonFootprintNoLongMotorized.values())
  logging.debug("myCarbonFootprintSum = %s, myOptimalFootprintSum = %s, myAllDrive = %s" %
        (myCarbonFootprintSum, myOptimalFootprintSum, myAllDrive))
  handleZero = lambda x, y: 0 if y == 0 else float(x)/y
  components = [pctClassified,
                handleZero(myCarbonFootprintSum - myOptimalFootprintSum, myOptimalFootprintSum),
                handleZero(myAllDrive - myCarbonFootprintSum, myAllDrive),
                handleZero(sb375DailyGoal - myCarbonFootprintSum, sb375DailyGoal)]
  return components
开发者ID:adambrown13,项目名称:e-mission-server,代码行数:29,代码来源:gamified.py

示例2: getResult

# 需要导入模块: from emission.core.wrapper.user import User [as 别名]
# 或者: from emission.core.wrapper.user.User import fromUUID [as 别名]
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,代码行数:33,代码来源:data.py

示例3: runBackgroundTasksForDay

# 需要导入模块: from emission.core.wrapper.user import User [as 别名]
# 或者: from emission.core.wrapper.user.User import fromUUID [as 别名]
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,代码行数:32,代码来源:data.py

示例4: getCurrView

# 需要导入模块: from emission.core.wrapper.user import User [as 别名]
# 或者: from emission.core.wrapper.user.User import fromUUID [as 别名]
def getCurrView(uuid):
  user = User.fromUUID(uuid)
  profile = user.getProfile()
  if profile is None:
    logging.debug("profile is None, returning data")
    return "data"
  logging.debug("profile.get('curr_view', 'dummy') is %s" % profile.get("curr_view", "data"))
  return profile.get("curr_view", "data")
开发者ID:adambrown13,项目名称:e-mission-server,代码行数:10,代码来源:choice.py

示例5: updateUserProfile

# 需要导入模块: from emission.core.wrapper.user import User [as 别名]
# 或者: from emission.core.wrapper.user.User import fromUUID [as 别名]
def updateUserProfile():
  logging.debug("Called updateUserProfile")
  user_uuid = getUUID(request)
  user = User.fromUUID(user_uuid)
  new_fields = request.json['update_doc']
  to_return = user.update(new_fields)
  logging.debug("Successfully updated profile for user %s" % user_uuid)
  return {"update": True}
开发者ID:e-mission,项目名称:e-mission-server,代码行数:10,代码来源:cfc_webapp.py

示例6: testCarbonFootprintStore

# 需要导入模块: from emission.core.wrapper.user import User [as 别名]
# 或者: from emission.core.wrapper.user.User import fromUUID [as 别名]
 def testCarbonFootprintStore(self):
     user = User.fromUUID(self.uuid)
     # Tuple of JSON objects, similar to the real footprint
     dummyCarbonFootprint = ({'myModeShareCount': 10}, {'avgModeShareCount': 20})
     self.assertEquals(data.getCarbonFootprint(user), None)
     data.setCarbonFootprint(user, dummyCarbonFootprint)
     # recall that pymongo converts tuples to lists somewhere down the line
     self.assertEquals(data.getCarbonFootprint(user), list(dummyCarbonFootprint))
开发者ID:juemura,项目名称:e-mission-server,代码行数:10,代码来源:TestData.py

示例7: getUserClient

# 需要导入模块: from emission.core.wrapper.user import User [as 别名]
# 或者: from emission.core.wrapper.user.User import fromUUID [as 别名]
def getUserClient(user_uuid):
    study = User.fromUUID(user_uuid).getFirstStudy()
    if study != None:
      client = Client(study)
      return client
    else:
      # User is not part of any study, so no additional filtering is needed
      return None
开发者ID:e-mission,项目名称:e-mission-server,代码行数:10,代码来源:userclient.py

示例8: getResult

# 需要导入模块: from emission.core.wrapper.user import User [as 别名]
# 或者: from emission.core.wrapper.user.User import fromUUID [as 别名]
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
  (prevScore, currScore) = getStoredScore(User.fromUUID(user_uuid))
  (level, sublevel) = getLevel(currScore)

  otherCurrScoreList = []
  for user_uuid_dict in get_uuid_db().find({}, {'uuid': 1, '_id': 0}):
    (currPrevScore, currCurrScore) = getStoredScore(User.fromUUID(user_uuid_dict['uuid']))
    otherCurrScoreList.append(currCurrScore)

  otherCurrScoreList.sort()
  renderedTemplate = template("clients/leaderboard/result_template.html",
                               level_picture_filename = getFileName(level, sublevel),
                               prevScore = prevScore,
                               currScore = currScore,
                               otherCurrScoreList = otherCurrScoreList)
  return renderedTemplate
开发者ID:adambrown13,项目名称:e-mission-server,代码行数:21,代码来源:leaderboard.py

示例9: getResult

# 需要导入模块: from emission.core.wrapper.user import User [as 别名]
# 或者: from emission.core.wrapper.user.User import fromUUID [as 别名]
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

  (prevScore, currScore) = getStoredScore(User.fromUUID(user_uuid))
  (level, sublevel) = getLevel(currScore)
  
  renderedTemplate = template("clients/gamified/result_template.html",
                              level_picture_filename = getFileName(level, sublevel),
                              prevScore = prevScore,
                              currScore = currScore)
  return renderedTemplate
开发者ID:adambrown13,项目名称:e-mission-server,代码行数:15,代码来源:gamified.py

示例10: savePredictionsStep

# 需要导入模块: from emission.core.wrapper.user import User [as 别名]
# 或者: from emission.core.wrapper.user.User import fromUUID [as 别名]
  def savePredictionsStep(self):
    from emission.core.wrapper.user import User
    from emission.core.wrapper.client import Client

    uniqueModes = sorted(set(self.cleanedResultVector))

    for i in range(self.predictedProb.shape[0]):
      currSectionId = self.sectionIds[i]
      currProb = self.convertPredictedProbToMap(self.modeList, uniqueModes, self.predictedProb[i])

      logging.debug("Updating probability for section with id = %s" % currSectionId)
      self.Sections.update({'_id': currSectionId}, {"$set": {"predicted_mode": currProb}})

      currUser = User.fromUUID(self.sectionUserIds[i])
      clientSpecificUpdate = Client(currUser.getFirstStudy()).clientSpecificSetters(currUser.uuid, currSectionId, currProb)
      if clientSpecificUpdate != None:
        self.Sections.update({'_id': currSectionId}, clientSpecificUpdate)
开发者ID:sunil07t,项目名称:e-mission-server,代码行数:19,代码来源:mode.py

示例11: getSectionFilter

# 需要导入模块: from emission.core.wrapper.user import User [as 别名]
# 或者: from emission.core.wrapper.user.User import fromUUID [as 别名]
def getSectionFilter(uuid):
  from emission.core.wrapper.user import User
  from datetime import datetime, timedelta

  logging.info("testclient.getSectionFilter called for user %s" % uuid)
  # If this is the first two weeks, show everything
  user = User.fromUUID(uuid)
  # Note that this is the last time that the profile was updated. So if the
  # user goes to the "Auth" screen and signs in again, it will be updated, and
  # we will reset the clock. If this is not acceptable, we need to ensure that
  # we have a create ts that is never updated
  updateTS = user.getUpdateTS()
  if (datetime.now() - updateTS) < timedelta(days = 14):
    # In the first two weeks, don't do any filtering
    return []
  else:
    return [{'test_auto_confirmed.prob': {'$lt': 0.9}}]
开发者ID:adambrown13,项目名称:e-mission-server,代码行数:19,代码来源:testclient.py

示例12: updateScoreForDay

# 需要导入模块: from emission.core.wrapper.user import User [as 别名]
# 或者: from emission.core.wrapper.user.User import fromUUID [as 别名]
def updateScoreForDay(user_uuid, today):
    yesterday = today - timedelta(days = 1)
    dayBeforeYesterday = today - timedelta(days = 2)

    dayBeforeYesterdayStart = datetime.combine(dayBeforeYesterday, dttime.min)
    yesterdayStart = datetime.combine(yesterday, dttime.min)
    todayStart = datetime.combine(today, dttime.min)

    user = User.fromUUID(user_uuid)
    (discardedScore, prevScore) = getStoredScore(user)
    # Using score from dayBeforeYesterday instead of yesterday because there is
    # currently a significant lag in the time for e-mission to prompt for
    # entries, so people might not confirm yesterday's trips until sometime
    # today, which means that it won't be counted in their score
    newScore = prevScore + getScore(user_uuid, dayBeforeYesterdayStart, yesterdayStart)
    if newScore < 0:
        newScore = 0
    stats.storeResultEntry(user_uuid, stats.STAT_GAME_SCORE, time.time(), newScore)
    setScores(user, prevScore, newScore)
开发者ID:adambrown13,项目名称:e-mission-server,代码行数:21,代码来源:gamified.py

示例13: getResult

# 需要导入模块: from emission.core.wrapper.user import User [as 别名]
# 或者: from emission.core.wrapper.user.User import fromUUID [as 别名]
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
  import base64
  from dao.user import User
  from dao.client import Client

  user = User.fromUUID(user_uuid)

  renderedTemplate = template("clients/choice/result_template.html",
                          variables = json.dumps({'curr_view': getCurrView(user_uuid),
                                       'uuid': str(user_uuid),
                                       'client_key': Client("choice").getClientKey()}),
                          gameResult = base64.b64encode(gamified.getResult(user_uuid)),
                          leaderboardResult = base64.b64encode(leaderboard.getResult(user_uuid)),
                          dataResult = base64.b64encode(data.getResult(user_uuid)), 
                          commonTripsResult = base64.b64encode(commontrips.getResult(user_uuid)),
                          recommendationResult = base64.b64encode(recommendation.getResult(user_uuid)))

  return renderedTemplate
开发者ID:adambrown13,项目名称:e-mission-server,代码行数:23,代码来源:choice.py

示例14: testRunBackgroundTasksForDay

# 需要导入模块: from emission.core.wrapper.user import User [as 别名]
# 或者: from emission.core.wrapper.user.User import fromUUID [as 别名]
    def testRunBackgroundTasksForDay(self):
        self.testUsers = ["[email protected]", "[email protected]", "[email protected]",
                          "[email protected]", "[email protected]"]
        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.SectionsColl = get_section_db()
        emission.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())
开发者ID:juemura,项目名称:e-mission-server,代码行数:23,代码来源:TestData.py

示例15: setCurrView

# 需要导入模块: from emission.core.wrapper.user import User [as 别名]
# 或者: from emission.core.wrapper.user.User import fromUUID [as 别名]
def setCurrView(uuid, newView):
  user = User.fromUUID(uuid)
  user.setClientSpecificProfileFields({'curr_view': newView})
  stats.storeResultEntry(uuid, stats.STAT_VIEW_CHOICE, time.time(), newView)
开发者ID:adambrown13,项目名称:e-mission-server,代码行数:6,代码来源:choice.py


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