Skip to content

Commit

Permalink
Merge branch 'gh-pages' of https://github.com/LivelyKernel/lively4-core
Browse files Browse the repository at this point in the history
… into gh-pages
  • Loading branch information
onsetsu committed Jul 24, 2024
2 parents ec19010 + 2b10e60 commit 24feed1
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ export default class BabylonianProgrammingEditor extends Morph {
var editorComp = this.editorComp()

console.log("Babylonian: load editor" + editorComp)
editorComp.addEventListener("editor-loaded", () => {

// editorComp.addEventListener("editor-loaded", () => {
editorComp.editorLoaded().then(() => {

console.log("Babylonian: editor loaded ", this.livelyEditor())
// Patch editor to load/save comments
Expand All @@ -143,6 +145,7 @@ export default class BabylonianProgrammingEditor extends Morph {
"Tab": (cm) => { cm.replaceSelection(" ") },
})

debugger
// Inject styling into CodeMirror
const livelyEditorStyle =
<link rel="stylesheet" href={`${COMPONENT_URL}/lively-code-editor-inject-styles.css`}></link>
Expand Down
28 changes: 18 additions & 10 deletions src/components/tools/astro-plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,13 @@ export default class AstroPlot extends Morph {
return str.slice(0, 100).replace('\n', '<br>');
}

async displayData(features, clusters) {
if (!clusters) clusters = Array(features.length).fill(0);
async updateLabels(labels) {
// # TODO
let container = this.get('#embedding_plot')
Plotly.restyle(container, 'marker.color', labels)
}

async displayData(features) {

const dataframe = {
_push(el) {
Expand All @@ -81,21 +86,23 @@ export default class AstroPlot extends Morph {
plot_title,
plot_content,
file,
id
id,
cluster
}, i) => dataframe._push({
x: umap_embedding[0],
y: umap_embedding[1],
z: umap_embedding[2],
color: clusters[i],
color: cluster,
customdata: {
cluster: 'Cluster ' + clusters[i],
cluster: 'Cluster ' + cluster,
content: plot_content,
title: plot_title,
file,
contentAbbr: `${this.displayContent(plot_content)}...`
},
// text: ' ' + plot_title, // ' '+ neccessary!!
ids: id || i
ids: id || i,
cluster
}));

const data = [
Expand All @@ -109,7 +116,7 @@ export default class AstroPlot extends Morph {
width: 0.5
},
opacity: 0.8,
color: clusters,
color: dataframe.cluster,
colorscale: 'Viridis',
},
selected: {
Expand Down Expand Up @@ -164,6 +171,7 @@ export default class AstroPlot extends Morph {


container.on('plotly_click', (data) => {
debugger
let item = data.points[0];

// Update the plot with new selected points
Expand All @@ -188,10 +196,10 @@ export default class AstroPlot extends Morph {
//const getRealData = async () => await fetch("http://127.0.0.1:5000/dataset/d3-force-main/umap")

// const response = await getRealData();
const features = await getRealData(); //await response.json()
const clusters = await getClusters();
// const features = await getRealData(); //await response.json()
//const clusters = await getClusters();

await this.displayData(features, clusters);
// await this.displayData(features);
}

/*
Expand Down
14 changes: 11 additions & 3 deletions src/components/tools/astro-view-example-transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ def reduce(self, df):
# multiply whole columns by respective scalar, then add them together

return \
df['method_embedding'] * 0.8 + \
df['class_name_embedding'] * 0.1 + \
df['identifier_mean'] + 0.1
df['method_embedding'] * 0.5 + \
df['class_name_embedding'] * 0.4 + \
df['identifier_mean'] + 0.1

def cluster(self):
from sklearn.cluster import AgglomerativeClustering
return AgglomerativeClustering(
n_clusters=None,
distance_threshold=130,
linkage='ward'
)
12 changes: 11 additions & 1 deletion src/components/tools/astro-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
max-height: 300px
}

#pool-embedding {
white-space: pre-wrap;
}

.token {
margin: 2px; padding: 2px; display:inline-block
}
Expand Down Expand Up @@ -142,6 +146,9 @@
</div>

<div>
<button class="toggle" id="computeEmbeddings" title="Compute Embeddings. Check logs in backend">
Compute Embeddings!<i class="fa fa-refresh fa-fw"></i>
</button>
<button class="toggle" id="runParse" title="Parse files into ASTs">
Parse<i class="fa fa-refresh fa-fw"></i>
</button>
Expand All @@ -154,8 +161,11 @@
<button class="toggle" id="runReduce" title="Apply Weights">
Reduce<i class="fa fa-refresh fa-fw"></i>
</button>
<button class="toggle" id="runCluster" title="Cluster">
Cluster<i class="fa fa-refresh fa-fw"></i>
</button>
<button class="toggle" id="runUmap" title="Map to 3D">
UMAP<i class="fa fa-refresh fa-fw"></i>
Display (UMAP)<i class="fa fa-refresh fa-fw"></i>
</button>
<div id="status"/>
</div>
Expand Down
38 changes: 36 additions & 2 deletions src/components/tools/astro-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ export default class AstroView extends Morph {
get astInspector() { return this.get("#ast"); }

get updateButton() { return this.get("#update"); }
get computeEmbeddings() { return this.get("#computeEmbeddings")}
get runQueryButton() { return this.get('#runQuery'); }
get runMapButton() { return this.get('#runMap'); }
get runReduceButton() { return this.get('#runReduce'); }
get runClusterButton() { return this.get('#runCluster')}

get autoUpdate() { return this._autoUpdate; }
set autoUpdate(bool) {
Expand Down Expand Up @@ -317,10 +319,25 @@ export default class AstroView extends Morph {
}
}

async onComputeEmbeddings() {
this.status ="generating embeddings: long running task. check backend logs";
try {
let language = "typescript"; // HARDCODED CHANGE HERE
let response = await fetch(`${this.api}/dataset/${this.projectName}/make_context_embeddings?language=${language}`, {
method: 'POST',
})
response = await response.json();
if (response.error) throw new Error(response.error);
this.status = `generating embeddings: ${JSON.stringify(response.stats)}`;
} catch (e) {
this.status = "generating embeddings: " + e;
}
}

async onRunParse() {
this.status = "parser: running..."
try {
let language = "typescript";
let language = "typescript"; // HARDCODED CHANGE HERE
let response = await fetch(`${this.api}/dataset/${this.projectName}/parse?language=${language}`, {
method: 'POST',
})
Expand Down Expand Up @@ -397,7 +414,25 @@ export default class AstroView extends Morph {
}
}

async onRunCluster() {
this.status = "clustering: running..."
let data;
try {
let response = await fetch(`${this.api}/dataset/${this.projectName}/run_cluster`, {
method: 'POST',
})
response = await response.json();
if (response.error) throw new Error(response.error);
let clusters = response.clusters;
this.status = "clustering: success. " + clusters + ' clusters found.';
} catch (e) {
this.status = "clustering: " + e;
return;
}
}

async onItemClicked(e) {
debugger
const item = e.detail;
let id = item.id;

Expand All @@ -414,7 +449,6 @@ export default class AstroView extends Morph {
const source = item.plot_content;

this.sourceCM.setValue(source);
debugger
} catch (e) {
this.status = "get item: " + e;
}
Expand Down
Loading

0 comments on commit 24feed1

Please sign in to comment.