def create_samples(self): # Create weather measurements self.create_weather_measurements() # Get the id from the demo farm. demo_farm_id = self.get_farm_id() # Get factories p_factory = PaddockFactory() r_factory = ReadingFactory() algo_id = self.get_algorithm_id(self.PASTURE_CAT, self.CATEGORY_ALGO) # For loop used to create sample paddocks. for p_id in range(0, 4): # Create an upload and update time. create_time = datetime.datetime.now() update_time = datetime.datetime.now() + datetime.timedelta(hours=1) # Create a sample paddock. paddock = p_factory.build_demo_paddock( demo_farm_id, p_id, create_time, create_time if p_id < 2 else update_time) paddock.set_id(p_id) # Call API. paddock_res = self.api._Moogle__api_call('post', self.PADDOCK_ENDPOINT, paddock.to_dict(), None) # :Add the returned object id to the current paddock object. paddock_json = json.loads(paddock_res.text) paddock.set_oid(paddock_json['data']['_id']) # For loop used to create sample readings for the current paddock. for r_id in range(0, 100): # Create an upload and update time. create_time = datetime.datetime.now() update_time = datetime.datetime.now() + datetime.timedelta(hours=1) # Create a sample pasture reading. reading = r_factory.build_demo_reading( p_id, paddock.oid, -1, algo_id, create_time, create_time if r_id % 4 != 0 else update_time) # Call API. self.api._Moogle__api_call('post', self.READING_ENDPOINT, reading.to_dict(), None)
def add_readings(self): # Get demo farm id demo_farm_id = self.get_farm_id() # Get the user id from the logged in user res = self.api._Moogle__api_call('get', 'auth', None, None) user = json.loads(res.text) user_id = user['user']['id'] # Get pasture reading factory r_factory = ReadingFactory() # Get timestamp timestamp = datetime.datetime.now() # Get each paddock that belongs to the demo farm paddock_params = self.PADDOCKS_PARAMS + str(demo_farm_id) response = self.api._Moogle__api_call('get', self.PADDOCK_ENDPOINT, None, paddock_params) paddocks = json.loads(response.text) paddocks = paddocks['paddocks'] # Iterate through each paddock in the farm for paddock in paddocks: paddock_oid = paddock['_id'] paddock_id = paddock['id'] # Create a pasture reading for each farm. for i in range(0, self.NUM_PASTURE_READINGS): # Create a sample pasture reading. reading = r_factory.build_demo_reading( paddock_id, paddock_oid, user_id, timestamp, timestamp) # Call API. self.api._Moogle__api_call('post', self.READING_ENDPOINT, reading.to_dict(), None)