Skip to content

Commit 67b906a

Browse files
committed
gSheet: ignore empty cells
1 parent 5f84370 commit 67b906a

File tree

2 files changed

+122
-15
lines changed

2 files changed

+122
-15
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<base target="_top">
5+
<style>
6+
.form-group {
7+
margin: 10px 0;
8+
}
9+
select {
10+
width: 100%;
11+
padding: 5px;
12+
}
13+
.required {
14+
color: red;
15+
}
16+
</style>
17+
</head>
18+
<body>
19+
<form onsubmit="handleSubmit(this); return false;">
20+
21+
<div class="form-group">
22+
<label>Ideas Column <span class="required">*</span></label>
23+
<select name="ideaColumn" required>
24+
<option value="">Select column...</option>
25+
<? headers.forEach(function(header) { ?>
26+
<option value="<?= header ?>"><?= header ?></option>
27+
<? }); ?>
28+
</select>
29+
</div>
30+
31+
<div class="form-group">
32+
<label>ID Column (optional)</label>
33+
<select name="idColumn">
34+
<option value="">None</option>
35+
<? headers.forEach(function(header) { ?>
36+
<option value="<?= header ?>"><?= header ?></option>
37+
<? }); ?>
38+
</select>
39+
</div>
40+
41+
<div class="form-group">
42+
<label>Author Column (optional)</label>
43+
<select name="authorColumn">
44+
<option value="">None</option>
45+
<? headers.forEach(function(header) { ?>
46+
<option value="<?= header ?>"><?= header ?></option>
47+
<? }); ?>
48+
</select>
49+
</div>
50+
51+
<button type="submit">Analyze</button>
52+
</form>
53+
<!-- Add this after the form -->
54+
<div id="loadingIndicator" style="display: none; text-align: center; margin-top: 20px;">
55+
<p>Analyzing ideas with SimScore...</p>
56+
<p>This may take a few moments.</p>
57+
</div>
58+
59+
<script>
60+
function handleSubmit(form) {
61+
// Show loading indicator
62+
document.querySelector('form').style.display = 'none';
63+
document.getElementById('loadingIndicator').style.display = 'block';
64+
65+
const data = {
66+
idColumn: form.idColumn.value,
67+
ideaColumn: form.ideaColumn.value,
68+
authorColumn: form.authorColumn.value
69+
};
70+
71+
google.script.run
72+
.withSuccessHandler(closeDialog)
73+
.withFailureHandler(handleError)
74+
.processSelectedColumns(data);
75+
}
76+
77+
function closeDialog() {
78+
google.script.host.close();
79+
}
80+
81+
function handleError(error) {
82+
// Show form again if there's an error
83+
document.querySelector('form').style.display = 'block';
84+
document.getElementById('loadingIndicator').style.display = 'none';
85+
showError(error);
86+
}
87+
88+
function showError(error) {
89+
alert('Error: ' + error);
90+
}
91+
</script>
92+
</body>
93+
</html>

aux_tools/google/code.gs

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,14 @@ function getApiKey() {
5151
);
5252
}
5353

54+
function getApiUrl() {
55+
return PropertiesService.getScriptProperties().getProperty(
56+
"SIMSCORE_API_URL"
57+
);
58+
}
59+
5460
function processSelectedColumns(
55-
selections = { idColumn: "ID", ideaColumn: "description" }
61+
selections = { idColumn: "ID#", ideaColumn: "ideas", authorColumn: "author" }
5662
) {
5763
const sheet = SpreadsheetApp.getActiveSheet();
5864
const headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0];
@@ -70,20 +76,28 @@ function processSelectedColumns(
7076
const lastRow = sheet.getLastRow();
7177
const ideas = [];
7278

79+
console.log(`Analysing Rows 2 - ${lastRow}`)
80+
7381
// Build data array
7482
for (let row = 2; row <= lastRow; row++) {
83+
ideaValue = sheet.getRange(row, ideaColIndex).getValue()
84+
if (!ideaValue) continue;
7585
const idea = {
76-
idea: sheet.getRange(row, ideaColIndex).getValue(),
86+
idea: ideaValue,
7787
};
78-
88+
7989
if (idColIndex) {
8090
idea.id = sheet.getRange(row, idColIndex).getValue().toString();
8191
}
82-
92+
8393
if (authorColIndex) {
8494
idea.author_id = sheet.getRange(row, authorColIndex).getValue();
8595
}
8696

97+
if (row % 50 === 0) {
98+
console.log(`Row ${row}: `, idea)
99+
}
100+
87101
ideas.push(idea);
88102
}
89103

@@ -99,15 +113,15 @@ function processSelectedColumns(
99113

100114
const response = callSimScoreApi(requestData);
101115
if (response) {
102-
console.log(response.ranked_ideas);
103-
console.log(response.pairwise_similarity_matrix);
104-
console.log(response.cluster_names);
116+
console.log("(Slices of) Ranked Ideas: \b", response.ranked_ideas.slice(0, 5), "\n[...]\n", response.ranked_ideas.slice(-10));
117+
console.log("Has similarity matrix? : ", Boolean(response.pairwise_similarity_matrix));
118+
console.log("Has cluster names? : ", Boolean(response.cluster_names));
105119
displayResults(response);
106120
}
107121
}
108122

109123
function callSimScoreApi(requestData) {
110-
const API_URL = "http://127.0.0.1:8000/v1/rank_ideas";
124+
const API_URL = getApiUrl();
111125
const apiKey = getApiKey();
112126

113127
const options = {
@@ -119,8 +133,8 @@ function callSimScoreApi(requestData) {
119133
options["headers"] = { Authorization: `Bearer ${apiKey}` };
120134
}
121135

122-
console.log("Options: ", options);
123-
136+
const forLogging = JSON.stringify(options)
137+
console.log("Options: ", forLogging.slice(0, 200) + "\n[...]\n" + forLogging.slice(forLogging.length/2, forLogging.length/2+200) + "\n[...]\n" + forLogging.slice(-700, -500)); // the last 400chars or so is the API key
124138
try {
125139
const response = UrlFetchApp.fetch(API_URL, options);
126140
return JSON.parse(response.getContentText());
@@ -157,8 +171,7 @@ function displayResults(response) {
157171
// Format ranked ideas
158172
const rankedData = response.ranked_ideas.map((item, index) => {
159173
const clusterName =
160-
response.cluster_names?.find((c) => c.id === item.cluster_id)?.name ||
161-
item.cluster_id;
174+
response.cluster_names?.find((c) => c.id === item.cluster_id)?.name || item.cluster_id;
162175
return [
163176
"# " + (index + 1),
164177
item.id,
@@ -169,6 +182,8 @@ function displayResults(response) {
169182
];
170183
});
171184

185+
console.log("Ranked Data: ", rankedData.slice(0,5), rankedData.slice(-5))
186+
172187
if (rankedData.length > 0) {
173188
rankingsSheet
174189
.getRange(2, 1, rankedData.length, rankedData[0].length)
@@ -203,7 +218,7 @@ function displayResults(response) {
203218

204219
// Combine headers and matrix
205220
const fullMatrix = [headerRow].concat(matrixWithHeaders);
206-
console.log("Matrix:\n\n", fullMatrix);
221+
console.log("Matrix:\n\n", fullMatrix.slice(0, 5), fullMatrix.slice(-5));
207222

208223
// Important: Use the fullMatrix dimensions which include the headers
209224
const numRows = fullMatrix.length;
@@ -253,10 +268,9 @@ function createScatterPlot(response, sheet, rankedData) {
253268
Math.round(4 + 240 * t).toString(16).padStart(2, "0")
254269

255270
colorMap[index] = { color };
256-
console.log(`Idea: ${idea} - Similarity: ${t} - Color: ${color}`);
257271
});
258272

259-
console.log(colorMap);
273+
console.log(colorMap.slice(0, 5), colorMap.slice(-5));
260274

261275
const chartRange = sheet.getRange(1, rankedData[0].length, chartData.length, chartData[0].length);
262276
chartRange.setValues(chartData);

0 commit comments

Comments
 (0)