From c93b12a95bed7cfbd13fd641b1979d61ace19362 Mon Sep 17 00:00:00 2001 From: Ian Johnson Date: Thu, 2 May 2024 14:23:15 -0400 Subject: [PATCH] export scope-XXX-input.parquet. fix hulls bug --- latentscope/scripts/scope.py | 7 +++++- latentscope/server/bulk.py | 11 ++++++++++ web/src/components/HullPlot.jsx | 38 ++++++++++++++++----------------- 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/latentscope/scripts/scope.py b/latentscope/scripts/scope.py index 62c7c89..ffdfa57 100644 --- a/latentscope/scripts/scope.py +++ b/latentscope/scripts/scope.py @@ -128,5 +128,10 @@ def get_next_scopes_number(dataset): if not os.path.exists(transactions_file_path): with open(transactions_file_path, 'w') as f: json.dump([], f) + + input_df = pd.read_parquet(os.path.join(DATA_DIR, dataset_id, "input.parquet")) + combined_df = input_df[input_df.index.isin(scope_parquet['ls_index'])] + combined_df.to_parquet(os.path.join(directory, id + "-input.parquet")) + + print("wrote scope", id) - print("wrote scope", id) \ No newline at end of file diff --git a/latentscope/server/bulk.py b/latentscope/server/bulk.py index eb8e081..aadcc7d 100644 --- a/latentscope/server/bulk.py +++ b/latentscope/server/bulk.py @@ -56,6 +56,7 @@ def change_cluster(): # write the parquet df.to_parquet(scope_file) + update_combined(df, dataset_id, scope_id) # recalculate the hulls for c in clusters: @@ -104,6 +105,9 @@ def change_cluster_name(): # update the label column in the parquet df[df['cluster'] == cluster]['label'] = new_label df.to_parquet(scope_file) + + update_combined(df, dataset_id, scope_id) + #write the scope meta to file with open(scope_meta_file, "w") as f: json.dump(scope_meta, f, indent=2) @@ -131,6 +135,8 @@ def delete_rows(): df.to_parquet(scope_file) + update_combined(df, dataset_id, scope_id) + # recalculate hulls scope_meta_file = os.path.join(DATA_DIR, dataset_id, "scopes", scope_id + ".json") with open(scope_meta_file) as f: @@ -156,3 +162,8 @@ def delete_rows(): }) return jsonify({"success": True}) +def update_combined(df, dataset_id, scope_id): + input_df = pd.read_parquet(os.path.join(DATA_DIR, dataset_id, "input.parquet")) + combined_df = input_df[input_df.index.isin(df['ls_index'])] + combined_df.to_parquet(os.path.join(DATA_DIR, dataset_id, "scopes", scope_id + "-input.parquet")) + diff --git a/web/src/components/HullPlot.jsx b/web/src/components/HullPlot.jsx index 03a6613..9c2e0a5 100644 --- a/web/src/components/HullPlot.jsx +++ b/web/src/components/HullPlot.jsx @@ -1,10 +1,10 @@ -import React, { useEffect, useRef } from 'react'; -import { scaleLinear } from 'd3-scale'; +import { useEffect, useRef } from 'react'; +// import { scaleLinear } from 'd3-scale'; import { line, curveLinearClosed, curveCatmullRomClosed } from 'd3-shape'; import { select } from 'd3-selection'; -import { transition } from 'd3-transition'; +// import { transition } from 'd3-transition'; import { easeExpOut, easeExpIn, easeCubicInOut} from 'd3-ease'; -import { interpolate } from 'flubber'; +// import { interpolate } from 'flubber'; import "./HullPlot.css" @@ -95,21 +95,21 @@ const HullPlot = ({ .delay(delay) .ease(easeCubicInOut) .style("opacity", 0.75) - // .attr("d", draw) - .attrTween("d", function(d,i) { - // console.log("d,i", d, i) - // console.log(d.hull, prevHulls.current.find(h => h.index == d.index).hull) - const prev = prevHulls.current ? prevHulls.current[i] : null - // console.log(d, prev) - if(!prev) return () => draw(d) - const inter = interpolate( - draw(prev), - draw(d) - ); - return function(t) { - return inter(t) - } - }) + .attr("d", draw) + // .attrTween("d", function(d,i) { + // // console.log("d,i", d, i) + // // console.log(d.hull, prevHulls.current.find(h => h.index == d.index).hull) + // const prev = prevHulls.current ? prevHulls.current[i] : null + // // console.log(d, prev) + // if(!prev) return () => draw(d) + // const inter = interpolate( + // draw(prev), + // draw(d) + // ); + // return function(t) { + // return inter(t) + // } + // }) setTimeout(() => {