Initial commit of data store for API2 experiments

This commit is contained in:
Rod A Santiago 2016-08-10 17:24:56 -07:00
parent 2f7c337b02
commit 3ba2b685b6

View file

@ -0,0 +1,49 @@
#
# CORE
# Copyright (c)2016 the Boeing Company.
# See the LICENSE file included in this distribution.
#
# author: Rod Santiago
#
from core.api import core_pb2
from multiprocessing import Lock
class ExperimentStore(object):
__lastid = 0
__experiments = {}
__lock = Lock()
@staticmethod
def addExperiment(exp):
with ExperimentStore.__lock:
id = str(ExperimentStore.__lastid)
ExperimentStore.__lastid += 1
exp.experimentId = id
if not id in ExperimentStore.__experiments:
ExperimentStore.__experiments[id] = exp
return True
else:
return False
@staticmethod
def delExperiment(exp):
if not exp.HasField("experimentId"):
print 'Experiment ID is needed but not supplied'
return False
id = exp.experimentId
with ExperimentStore.__lock:
if id in ExperimentStore.__experiments:
del ExperimentStore.__experiments[id]
return True
else:
return False