Browse Source

[MNT] Update example, modify pipeline, add database function

tags/v0.3.2
chenzx 3 years ago
parent
commit
c46ab025fd
2 changed files with 13 additions and 1 deletions
  1. +3
    -1
      examples/example_market_db/example_db.py
  2. +10
    -0
      learnware/market/database_ops.py

+ 3
- 1
examples/example_market_db/example_db.py View File

@@ -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


+ 10
- 0
learnware/market/database_ops.py View File

@@ -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):


Loading…
Cancel
Save