def populate_init_data(): # Initialize data store with default computing ht_res = apply_clustering() rt_res = rating_clustering(INIT_THRESHOLD_VAL) return { "ht": {"data": ht_res[0].to_json(), "pct": ht_res[1].to_json()}, "rt": { "data": rt_res[0].to_json(), "p_val": rt_res[1], "pct_d": rt_res[2].to_json(), }, }
def update_ds(n_clicks, clustering_type, cur_ds, thr): # Apply algorithm and only apply computing once upon button=click,save it for figure loading if n_clicks: if clustering_type == "ht-cluster": # Apply KMeans and update datastore ht_res = apply_clustering() cur_ds.update(ht={"data": ht_res[0].to_json(), "pct": ht_res[1].to_json()}) elif clustering_type == "rating-cluster": rt_res = rating_clustering(thr) cur_ds.update( rt={ "data": rt_res[0].to_json(), "p_val": rt_res[1], "pct_d": rt_res[2].to_json(), } ) else: return cur_ds return cur_ds return cur_ds