def testPutTwoSetsOfUserDataForPhone(self):
        uc = ucauc.UserCache.getUserCache(self.testUserUUID)

        footprintData = {"mine": 30, "avg": 40, "optimal": 50, "alldrive": 60}
        uc.putDocument("data/footprint", footprintData)

        gameData = {
            "my_score": 30,
            "other_scores": {
                'josh': 40,
                'jillie': 20,
                'naomi': 50
            }
        }
        uc.putDocument("data/game", gameData)

        retrievedData = mauc.sync_server_to_phone(self.testUserUUID)
        logging.debug("retrievedData = %s" % retrievedData)
        self.assertTrue(
            retrievedData
            is not None)  # if it doesn't exist, the method returns None

        self.assertEqual(len(retrievedData), 2)
        self.assertTrue(retrievedData[0].keys(), ["data", "metadata"])
        self.assertTrue(retrievedData[1].keys(), ["data", "metadata"])

        for data in retrievedData:
            if data["metadata"]["key"] == "data/game":
                self.assertEqual(data["data"]["my_score"], 30)
def save_server_to_phone(user_id_str, file_name):
    logging.info("Saving current server data for user %s to file %s" %
                 (user_id_str, file_name))

    # TODO: Convert to call to get_timeseries once we get that working
    # Or should we even do that?
    retVal = enau.sync_server_to_phone(uuid.UUID(user_id_str))
    json.dump(retVal, open(file_name, "w"), default=bju.default, allow_nan=False, indent=4)
示例#3
0
  def testPutUserDataForPhone(self):
    uc = ucauc.UserCache.getUserCache(self.testUserUUID)
    footprintData = {"mine": 30, "avg": 40, "optimal": 50, "alldrive": 60}
    uc.putDocument("data/footprint", footprintData)

    retrievedData = mauc.sync_server_to_phone(self.testUserUUID)
    logging.debug("retrievedData = %s" % retrievedData)
    self.assertTrue(retrievedData is not None) # if it doesn't exist, the method returns None
    self.assertEquals(len(retrievedData),1)
    self.assertEquals(sorted(list(retrievedData[0].keys())), ["data", "metadata"])
    self.assertEquals(retrievedData[0]["data"]["mine"], 30)
示例#4
0
  def testClearObsoleteDocument(self):
    self.testPutTwoSetsOfUserDataForPhone()

    uc = ucauc.UserCache.getUserCache(self.testUserUUID)
    uc.clearObsoleteDocument("data/footprint")
    uc.clearObsoleteDocument("data/game")

    retrievedData = mauc.sync_server_to_phone(self.testUserUUID)
    logging.debug("retrievedData = %s" % retrievedData)
    
    self.assertTrue(retrievedData is not None) # if it doesn't exist, the method returns None
    self.assertEqual(len(retrievedData), 0)
示例#5
0
def save_server_to_phone(user_id_str, file_name):
    logging.info("Saving current server data for user %s to file %s" %
                 (user_id_str, file_name))

    # TODO: Convert to call to get_timeseries once we get that working
    # Or should we even do that?
    retVal = enau.sync_server_to_phone(uuid.UUID(user_id_str))
    json.dump(retVal,
              open(file_name, "w"),
              default=bju.default,
              allow_nan=False,
              indent=4)
示例#6
0
def get_maps_for_usercache(user_id):
    data_to_phone = seq(enau.sync_server_to_phone(user_id))
    logging.debug("Before pipeline, trips to phone list has length %d" % len(data_to_phone.to_list()))
    logging.debug("keys are %s" % data_to_phone.map(lambda e: ad.AttrDict(e).metadata.key))
    trips_to_phone = data_to_phone.map(lambda e: ad.AttrDict(e))\
                                    .filter(lambda e: e.metadata.key.startswith("diary/trips")) \
                                    .map(lambda e: e.data)
    logging.debug("After pipeline, trips to phone list has length %d" % len(trips_to_phone.to_list()))
    # logging.debug("trips_to_phone = %s" % trips_to_phone)
    maps_for_day = []
    for day in trips_to_phone:
        maps_for_day.append(get_maps_for_geojson_list(day))
    return maps_for_day
def get_maps_for_usercache(user_id):
    data_to_phone = seq(enau.sync_server_to_phone(user_id))
    logging.debug("Before pipeline, trips to phone list has length %d" % len(data_to_phone.to_list()))
    logging.debug("keys are %s" % data_to_phone.map(lambda e: ad.AttrDict(e).metadata.key))
    trips_to_phone = data_to_phone.map(lambda e: ad.AttrDict(e))\
                                    .filter(lambda e: e.metadata.key.startswith("diary/trips")) \
                                    .map(lambda e: e.data)
    logging.debug("After pipeline, trips to phone list has length %d" % len(trips_to_phone.to_list()))
    # logging.debug("trips_to_phone = %s" % trips_to_phone)
    maps_for_day = []
    for day in trips_to_phone:
        maps_for_day.append(get_maps_for_geojson_list(day))
    return maps_for_day
  def testPutTwoSetsOfUserDataForPhone(self):
    uc = ucauc.UserCache.getUserCache(self.testUserUUID)

    footprintData = {"mine": 30, "avg": 40, "optimal": 50, "alldrive": 60}
    uc.putDocument("data/footprint", footprintData)

    gameData = {"my_score": 30, "other_scores": {'josh': 40, 'jillie': 20, 'naomi': 50}}
    uc.putDocument("data/game", gameData)

    retrievedData = mauc.sync_server_to_phone(self.testUserUUID)
    logging.debug("retrievedData = %s" % retrievedData)
    self.assertTrue(retrievedData is not None) # if it doesn't exist, the method returns None

    self.assertEqual(len(retrievedData), 2)
    self.assertTrue(list(retrievedData[0].keys()), ["data", "metadata"])
    self.assertTrue(list(retrievedData[1].keys()), ["data", "metadata"])

    for data in retrievedData:
        if data["metadata"]["key"] == "data/game":
            self.assertEqual(data["data"]["my_score"], 30)
    def testPutTwoSetsOfBackgroundConfigForPhone(self):
        start_ts = time.time()
        uc = ucauc.UserCache.getUserCache(self.testUserUUID)

        pull_probes_list = [
            "accelerometer", "gyrometer", "linear_accelerometer"
        ]
        uc.putDocument("config/pull_probes", pull_probes_list)

        location_config = {
            "accuracy": "POWER_BALANCED_ACCURACY",
            "filter": "DISTANCE_FILTER",
            "geofence_radius": 100,
        }
        uc.putDocument("config/location_config", location_config)

        end_ts = time.time()

        retrievedData = mauc.sync_server_to_phone(self.testUserUUID)
        logging.debug("retrievedData = %s" % retrievedData)
        self.assertTrue(
            retrievedData
            is not None)  # if it doesn't exist, the method returns None

        expectedData = [["accelerometer", "gyrometer", "linear_accelerometer"],
                        {
                            "accuracy": "POWER_BALANCED_ACCURACY",
                            "filter": "DISTANCE_FILTER",
                            "geofence_radius": 100,
                        }]
        expectedKeys = ["config/pull_probes", "config/location_config"]

        for i, rd in enumerate(retrievedData):
            self.assertEqual(rd["data"], expectedData[i])

        for i, rd in enumerate(retrievedData):
            self.assertEqual(rd["metadata"]["key"], expectedKeys[i])

        for i, rd in enumerate(retrievedData):
            self.assertGreaterEqual(rd["metadata"]["write_ts"], start_ts) and \
                self.assertLessEqual(rd["metadata"]["write_ts"], end_ts)
  def testPutTwoSetsOfBackgroundConfigForPhone(self):
    start_ts = time.time()
    uc = ucauc.UserCache.getUserCache(self.testUserUUID)

    pull_probes_list = ["accelerometer", "gyrometer", "linear_accelerometer"]
    uc.putDocument("config/pull_probes", pull_probes_list)

    location_config = {"accuracy": "POWER_BALANCED_ACCURACY",
                       "filter": "DISTANCE_FILTER",
                       "geofence_radius": 100,
                      }
    uc.putDocument("config/location_config", location_config)

    end_ts = time.time()

    retrievedData = mauc.sync_server_to_phone(self.testUserUUID)
    logging.debug("retrievedData = %s" % retrievedData)
    self.assertTrue(retrievedData is not None) # if it doesn't exist, the method returns None

    expectedData = [
        ["accelerometer", "gyrometer", "linear_accelerometer"],
        {
          "accuracy": "POWER_BALANCED_ACCURACY",
          "filter": "DISTANCE_FILTER",
          "geofence_radius": 100,
        }
    ]
    expectedKeys = ["config/pull_probes", "config/location_config"]

    for i, rd in enumerate(retrievedData):
        self.assertEqual(rd["data"], expectedData[i])

    for i, rd in enumerate(retrievedData):
        self.assertEqual(rd["metadata"]["key"], expectedKeys[i])

    for i, rd in enumerate(retrievedData):
        self.assertGreaterEqual(rd["metadata"]["write_ts"], start_ts) and \
            self.assertLessEqual(rd["metadata"]["write_ts"], end_ts)
示例#11
0
def getFromCache():
    logging.debug("Called userCache.get")
    user_uuid = getUUID(request)
    logging.debug("user_uuid %s" % user_uuid)
    to_phone = usercache.sync_server_to_phone(user_uuid)
    return {'server_to_phone': to_phone}
示例#12
0
def getFromCache():
  logging.debug("Called userCache.get")
  user_uuid=getUUID(request)
  logging.debug("user_uuid %s" % user_uuid)
  to_phone = usercache.sync_server_to_phone(user_uuid)
  return {'server_to_phone': to_phone}