Commit 7fc212d6 authored by Jiahang Chen's avatar Jiahang Chen
Browse files

add is_stanford2010_sync

parent d6ecc136
Pipeline #504993 passed with stages
in 40 seconds
......@@ -351,6 +351,7 @@ def add_function_impl_obj(thing, impl_obj, feature_name, **kwargs):
def create_thing(model, grant_type="password",
secret="", username=None, password=None,
is_broker_rest=False, is_broker=False, is_repo=False, is_stanford2010=False,
is_stanford2010_sync=False,
stanford2010_sync_freq=None, stanford2010_path=None, is_database=False,
database_conf=None, database_file=None):
"""
......@@ -397,6 +398,7 @@ def create_thing(model, grant_type="password",
is_repo=is_repo,
is_stanford2010=is_stanford2010,
stanford2010_sync_freq=stanford2010_sync_freq,
is_stanford2010_sync=is_stanford2010_sync,
stanford2010_path=stanford2010_path,
is_database=is_database,
database_conf=database_conf,
......
......@@ -45,6 +45,7 @@ def __init__(
is_broker_rest=True,
is_stanford2010=False,
stanford2010_path=None,
is_stanford2010_sync=False,
stanford2010_sync_freq=None,
is_database=None,
database_conf=None,
......@@ -90,6 +91,7 @@ def __init__(
self.__is_repo = is_repo
self.__is_stanford2010 = is_stanford2010
self.__stanford2010_path = stanford2010_path
self.__is_stanford2010_sync = is_stanford2010_sync
self.__stanford2010_sync_freq = stanford2010_sync_freq
self.__is_db = is_database
......@@ -275,7 +277,8 @@ def run_forever(self):
threading.Thread(target=self.__repo_syn).start()
if self.__is_stanford2010:
threading.Thread(target=self.__stanford2010_syn,
args=(self.__stanford2010_path, True, self.__stanford2010_sync_freq)).start()
args=(self.__stanford2010_path, self.__is_stanford2010_sync,
self.__stanford2010_sync_freq)).start()
if self.__is_db:
self.__config_database()
......@@ -353,17 +356,19 @@ def get_timestamp(hpr):
time_str = time_node.text
return time_str.replace(time_str[time_str.rfind("."):time_str.find("+")], "")
def get_last_hpr(hpr_files):
def get_last_hpr(hpr_files, is_remove=False):
# get the last generated hpr data
if len(hpr_files) == 0:
return None
hpr = XML(path="{0}/{1}".format(path, hpr_files[0]))
os.remove("{0}/{1}".format(path, hpr_files[0]))
if is_remove:
os.remove("{0}/{1}".format(path, hpr_files[0]))
hpr_files.pop(0)
for filename in hpr_files:
hpr_temp = XML(path="{0}/{1}".format(path, filename))
os.remove("{0}/{1}".format(path, filename))
if is_remove:
os.remove("{0}/{1}".format(path, filename))
hpr_timestamp = get_timestamp(hpr)
hpr_temp_timestamp = get_timestamp(hpr)
hpr_isotime = datetime.fromisoformat(hpr_timestamp)
......@@ -374,7 +379,7 @@ def get_last_hpr(hpr_files):
return hpr
while True:
_stanford2010 = get_last_hpr(get_hpr_files(path))
_stanford2010 = get_last_hpr(get_hpr_files(path), is_remove=is_period)
time.sleep(1)
if _stanford2010 is None:
APP_LOGGER.warn("StanForD2010 Data not found in the specified folder, wait for the data")
......@@ -385,7 +390,7 @@ def get_last_hpr(hpr_files):
break
while is_period:
time.sleep(freq)
hpr_temp = get_last_hpr(hpr_files=get_hpr_files(path))
hpr_temp = get_last_hpr(hpr_files=get_hpr_files(path), is_remove=is_period)
if hpr_temp is None:
continue
isotime_old = datetime.fromisoformat(get_timestamp(self.__stanford2010))
......@@ -532,13 +537,13 @@ def __on_broker_callback(self, ch, method, properties, body):
body = literal_eval(body.decode('utf-8'))
except ValueError as e:
body = json.loads(body)
elif isinstance(body, int):
pass
elif isinstance(body, str):
pass
if ch is not None:
ch.basic_ack(method.delivery_tag)
try:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment