Each time a chip is detected, the resource files (images, sounds, videos...) are written to the disk in a temporary folder, even if the experiment is the same. (FilePoolStore does not receive a 'folder' argument.)
The proposed solution is to modify the _get_osexp function of the OpenMonkeyMind class, and to proceed in the same way as for the 'osexp' file, by passing the 'pool_folder' argument to Experiment.
def _get_osexp(self, json):
t0 = time.time()
for f in json['files']:
if not f['type'] == 'experiment':
continue
path = f['path']
updated_at = f['updated_at']
size = f['size']
break
else:
raise InvalidJSON(safe_decode(json))
tmpname=os.path.join(
tempfile.gettempdir(),
hashlib.md5(safe_encode(path + updated_at)).hexdigest()
)
cache_path = tmpname + '.osexp'
# If a cached file that matches in name and size exists, we re-use it.
# The file name also includes the updated_at fields, and thus
# re-uploading a new experiment with the same size will still refresh
# the cache.
if os.path.exists(cache_path) and os.path.getsize(cache_path) == size:
oslogger.info('using cached {}'.format(cache_path))
else:
response = requests.get(self._osexp_url + path)
if not response.ok:
raise FailedToDownloadExperiment()
with open(cache_path, 'wb') as fd:
fd.write(response.content)
oslogger.info('caching {} to {}'.format(path, cache_path))
self._experiment = experiment(pool_folder = tmpname,string=cache_path)
oslogger.info(
'building experiment ({:.3f} s)'.format(time.time() - t0)
)
return self._experiment
Each time a chip is detected, the resource files (images, sounds, videos...) are written to the disk in a temporary folder, even if the experiment is the same. (FilePoolStore does not receive a 'folder' argument.)
The proposed solution is to modify the _get_osexp function of the OpenMonkeyMind class, and to proceed in the same way as for the 'osexp' file, by passing the 'pool_folder' argument to Experiment.