def getcoordinates(self, test_coordinates=False): """Get machine coordinates from bot.""" location = ENV.redis_load('location') if location is None or test_coordinates: self.coordinates = self.test_coordinates # testing coordintes else: self.coordinates = location # current bot coordinates
def test_get_coordinates(self): """Get location from redis""" self.r.lpush('BOT_STATUS.location', self.coordinates[2]) self.r.lpush('BOT_STATUS.location', self.coordinates[1]) self.r.lpush('BOT_STATUS.location', self.coordinates[0]) self.assertEqual(ENV.redis_load('location', other_redis=self.r), self.coordinates)
def test_env_load(self): """Get user_env from redis""" self.r.set('BOT_STATUS.user_env.testkey', self.testvalue) self.assertEqual( ENV.redis_load('user_env', name='testkey', get_json=False, other_redis=self.r), self.testvalue)
def load_env_var(self): """Read input parameters from JSON in environment variable.""" self.parameters = ENV.load(self.env_var_name) if not isinstance(self.parameters, dict): self.load_defaults_for_env_var() message = "Warning: Environment variable parameters load failed." else: self._add_missing() message = "" return message
def test_bad_json_os_env_load(self): """Try to get bad json env from os""" os.environ['testbadjson'] = '{"label": "whoop' self.assertEqual(ENV.load_env('testbadjson'), None)
def test_none_os_env_load(self): """Try to get a non-existant env from os""" self.assertEqual(ENV.load_env('doesntexist'), None)
def test_os_env_load(self): """Try to get an env from os""" os.environ['oktestenv'] = 'test' self.assertEqual(ENV.load_env('oktestenv', get_json=False), 'test')
def test_none_user_env_load(self): """Try to get a non-existant user_env from redis""" self.assertEqual( ENV.redis_load('user_env', name='doesntexist', other_redis=self.r), None)
def test_bad_json_env_load(self): """Try to get bad json user_env from redis""" self.r.set('BOT_STATUS.user_env.testdata', self.badjson_string) self.assertEqual( ENV.redis_load('user_env', name='testdata', other_redis=self.r), None)
def test_json_env_load(self): """Get json user_env from redis""" self.r.set('BOT_STATUS.user_env.testdata', json.dumps(self.testjson)) self.assertEqual( ENV.redis_load('user_env', name='testdata', other_redis=self.r), self.testjson)
def test_not_coordinates(self): """Coordinates aren't a list""" self.r.set('BOT_STATUS.location', 'notalist') self.assertEqual(ENV.redis_load('location', other_redis=self.r), None)
def test_no_coordinates(self): """Coordinates don't exist""" self.assertEqual(ENV.redis_load('location', other_redis=self.r), None)
def save_to_env_var(self): """Save input parameters to environment variable.""" ENV.save(self.env_var_name, self.parameters)
def load_calibration_data_from_env(self): """Load calibration parameters from environment variable.""" self.calibration_params = ENV.load(self.env_var_name) if self.calibration_params is None: raise ValueError("ENV load failed.")
def save_calibration_data_to_env(self): """Save calibration parameters to environment variable.""" self.json_calibration_data = ENV.save(self.env_var_name, self.calibration_params)
#!/usr/bin/env python """Plant Detection Image Capture. For Plant Detection. """ import sys import os from time import sleep from subprocess import call import cv2 from PD import ENV CAMERA = ENV.load('camera', get_json=False) if CAMERA is None: CAMERA = 'USB' # default camera else: if 'RPI' in CAMERA: CAMERA = 'RPI' # Raspberry Pi Camera else: CAMERA = 'USB' class Capture(object): """Capture image for Plant Detection.""" def __init__(self): """Set initial attributes.""" self.image = None self.ret = None self.camera_port = None self.image_captured = False self.silent = False