def create_points(data): """ Creates a new entry for every Gathering not already in the database. :param data: The contents of the uploaded file. :return: A list containing all of the Gatherings found in the file. :return: A list containing all of the Gatherings found in the file. """ collections = {} for point in data: if point['GpsNumber'] not in collections: collections[point['GpsNumber']] = [] device.get_or_create(deviceId = point['GpsNumber'], parserInfo=parserInfo) collections[point['GpsNumber']].append( gathering.Gathering( time=ecotones_parse_time(point['GPSTime']), geometry = [float(point["Latitude"]), float(point["Longtitude"])], temperature=float(point['Temperature']) )) points = [] for k in collections.keys(): points += collections[k] document.create(str(uuid.uuid4()), collections[k], k) return points
def _update_gatherings_to_lajiStore(collections): points = [] for k in collections.keys(): doc_array = document.find(deviceID=k) points += collections[k] if len(doc_array) == 0: document.create(collections[k], k) else: doc_array[0].gatherings = _union_of_gatherings(doc_array[0].gatherings, collections[k]) _check_redundant_lajiStore_documents(doc_array) doc_array[0].update() return points
def test_get_public_gatherings(self): dev = device.create("Type", "Manu", "DeviceId", "2000-02-02T20:20:20+00:00", "2000-02-02T20:20:20+00:00") document.create( [gathering.Gathering("2012-01-01T00:00:00+00:00", [10.0, 10.0], publicityRestrictions="MZ.publicityRestrictionsPublic"), gathering.Gathering("2013-02-02T00:00:00+00:00", [11.0, 11.0], publicityRestrictions="MZ.publicityRestrictionsPublic"), gathering.Gathering("2013-02-02T00:00:00+00:00", [10.0, 10.0], publicityRestrictions="MZ.publicityRestrictionsPrivate")], dev.id) dev.attach_to(self.ind.id, "2013-01-01T00:00:00+00:00") gatherings = self.ind.get_public_gatherings() self.assertEquals(1, len(gatherings))
def test_merge_and_delete_if_three_documents_found_for_same_device(self): document.delete_all() device.delete_all() _create_points_from_ecotone(self, "/Ecotones_gps_pos_test.csv") dev = device.find()[0] gatherings = [gathering.Gathering("2015-09-15T08:00:00+03:00", [68.93023632, 23.19298104])] dict = { "deviceID": dev.id, "dateCreated": "2015-09-14T15:29:28+03:00", "dateEdited": "2015-09-14T15:29:28+03:00", "gatherings": gatherings } document.create(**dict) document.create(**dict) document.create(**dict) time.sleep(2) self.assertEqual(len(document.find()), 4) _create_points_from_ecotone(self, "/Ecotones_gps_pos_test.csv") time.sleep(2) self.assertEqual(len(document.find()),1)
def setUp(self): self.c = Client() self.A = document.create("TestA", [gathering.Gathering("1234-12-12T12:12:12+00:00", [22.2, 22.2])], "DeviceId") self.B = document.create("TestB", [gathering.Gathering("1234-12-12T12:12:12+00:00", [32.2, 32.2])], "DeviceId")