@@ -51,8 +51,14 @@ function getApiKey() {
5151 ) ;
5252}
5353
54+ function getApiUrl ( ) {
55+ return PropertiesService . getScriptProperties ( ) . getProperty (
56+ "SIMSCORE_API_URL"
57+ ) ;
58+ }
59+
5460function 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
109123function 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