From c46ab025fd880b61cffd10cb589d1fcccdca46af Mon Sep 17 00:00:00 2001 From: chenzx Date: Fri, 7 Apr 2023 11:02:23 +0800 Subject: [PATCH] [MNT] Update example, modify pipeline, add database function --- examples/example_market_db/example_db.py | 4 +++- learnware/market/database_ops.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/examples/example_market_db/example_db.py b/examples/example_market_db/example_db.py index a03feb7..cc9e544 100644 --- a/examples/example_market_db/example_db.py +++ b/examples/example_market_db/example_db.py @@ -16,7 +16,8 @@ def prepare_learnware(learnware_num=10): os.makedirs(dir_path, exist_ok=True) print("Preparing Learnware: %d" % (i)) - data_X = np.random.randn(5000, 20) + data_X = np.random.randn(5000, 20) * i + # print(data_X[:10]) data_y = np.random.randn(5000) data_y = np.where(data_y > 0, 1, 0) @@ -32,6 +33,7 @@ def prepare_learnware(learnware_num=10): def test_market(): + database_ops.clear_learnware_table() easy_market = EasyMarket() print("Total Item:", len(easy_market)) test_learnware_num = 10 diff --git a/learnware/market/database_ops.py b/learnware/market/database_ops.py index 56c5298..03009af 100644 --- a/learnware/market/database_ops.py +++ b/learnware/market/database_ops.py @@ -36,6 +36,16 @@ def init_empty_db(func): return wrapper +# Clear Learnware Database +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +# !!!!! !!!!! +# !!!!! Do NOT use unless highly necessary !!!!! +# !!!!! !!!!! +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +@init_empty_db +def clear_learnware_table(cur): + LOGGER.warning("!!! Drop Learnware Table !!!") + cur.execute("DROP TABLE LEARNWARE") @init_empty_db def add_learnware_to_db(id: str, name: str, model_path: str, stat_spec_path: str, semantic_spec: dict, cur):