예제 #1
0
 def testCarbonFootprintStore(self):
     user = User.fromUUID(self.uuid)
     # Tuple of JSON objects, similar to the real footprint
     dummyCarbonFootprint = ({
         'myModeShareCount': 10
     }, {
         'avgModeShareCount': 20
     })
     self.assertEquals(default.getCarbonFootprint(user), None)
     default.setCarbonFootprint(user, dummyCarbonFootprint)
     # recall that pymongo converts tuples to lists somewhere down the line
     self.assertEquals(default.getCarbonFootprint(user),
                       list(dummyCarbonFootprint))
예제 #2
0
# and delete the currentScore and previousScore fields

from get_database import get_uuid_db, get_profile_db
from dao.user import User
from clients.default import default
import logging

logging.basicConfig(level=logging.DEBUG)

for user_uuid_dict in get_uuid_db().find({}, {'uuid': 1, '_id': 0}):
    currUUID = user_uuid_dict['uuid']
    logging.info("Fixing results for %s" % currUUID)
    currUser = User.fromUUID(currUUID)
    if currUser.getFirstStudy() is None:
        currFootprint = currUser.getProfile().get("currentScore", None)
        default.setCarbonFootprint(currUser, currFootprint)
        get_profile_db().update(
            {'user_id': currUUID},
            {'$unset': {
                'previousScore': "",
                'currentScore': ""
            }})
        logging.debug("After change, currentScore = %s, currFootprint = %s" %
                      (currUser.getProfile().get("currentScore"),
                       default.getCarbonFootprint(currUser)))

# Informal testing from the command line since this is a one-time script
# Can be pulled out into a unit test if reworked
# Test setup steps from the REPL:
# In [52]: userTest = User.register("*****@*****.**")
# In [53]: userTest1 = User.register("*****@*****.**")
# carbon footprint from the currentScore field to the carbon_footprint field,
# and delete the currentScore and previousScore fields

from get_database import get_uuid_db, get_profile_db
from dao.user import User
from clients.default import default
import logging

logging.basicConfig(level=logging.DEBUG)

for user_uuid_dict in get_uuid_db().find({}, {'uuid': 1, '_id': 0}):
    currUUID = user_uuid_dict['uuid']
    logging.info("Fixing results for %s" % currUUID)
    currUser = User.fromUUID(currUUID)
    if currUser.getFirstStudy() is None:
        currFootprint = currUser.getProfile().get("currentScore", None)
        default.setCarbonFootprint(currUser, currFootprint)
        get_profile_db().update({'user_id': currUUID}, {'$unset': {'previousScore': "",
                                                                    'currentScore': ""}})
        logging.debug("After change, currentScore = %s, currFootprint = %s" % (
            currUser.getProfile().get("currentScore"),
            default.getCarbonFootprint(currUser)))

# Informal testing from the command line since this is a one-time script
# Can be pulled out into a unit test if reworked
# Test setup steps from the REPL:
# In [52]: userTest = User.register("*****@*****.**")
# In [53]: userTest1 = User.register("*****@*****.**")
# In [54]: gamified.setScores(userTest, None, [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}])
# In [55]: gamified.setScores(userTest1, None, [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}])