Skip to content

Commit 04da28e

Browse files
author
isabellapedraza
committed
first prototype done
1 parent 1977454 commit 04da28e

File tree

2 files changed

+80
-14
lines changed

2 files changed

+80
-14
lines changed

dist/main.js

+36-7
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ document.addEventListener('DOMContentLoaded', function () { return __awaiter(_th
111111
var binButtonContainer = document.createElement('div');
112112
// Create a label for the bin
113113
var binLabel = document.createElement('label');
114-
binLabel.textContent = "Bin: ".concat(bin.bin_name);
114+
binLabel.textContent = "".concat(field, " Bin: ").concat(bin.bin_name);
115115
binButtonContainer.appendChild(binLabel);
116116
binButtonContainer.appendChild(document.createElement('br')); // Line break for better formatting
117117
// Create button for showing reasoning
@@ -143,24 +143,53 @@ document.addEventListener('DOMContentLoaded', function () { return __awaiter(_th
143143
var valuesText = document.createElement('p');
144144
valuesText.id = "values-".concat(bin.bin_name);
145145
valuesText.style.display = 'none'; // Initially hide the values text
146+
var table = document.createElement('table');
147+
table.id = "table_values-".concat(bin.bin_name);
148+
table.style.display = 'none'; // Initially hide the values text
149+
// Create table header
150+
var headerRow = document.createElement('tr');
151+
uniqueFields.forEach(function (col) {
152+
var headerCell = document.createElement('th');
153+
headerCell.textContent = col;
154+
headerRow.appendChild(headerCell);
155+
});
156+
table.appendChild(headerRow);
146157
valuesButton.addEventListener('click', function () {
147158
// Toggle visibility of the values text
148159
if (valuesText.style.display === 'none') {
149160
valuesButton.textContent = "Hide Values for ".concat(bin.bin_name);
150161
valuesText.style.display = 'block';
162+
table.style.display = 'table';
151163
console.log(getDataValues(fileContent, bin.pred));
152164
var values = getDataValues(fileContent, bin.pred);
153-
valuesText.textContent = "Number of values: ".concat(values.length, " \n");
154-
valuesText.textContent += "Values: ".concat(JSON.stringify(values));
165+
var op = Object.keys(bin.pred).filter(function (item) { return item !== "field" && item !== "reasoning"; })[0];
166+
valuesText.textContent = "Bin boundary: ".concat(field, " ").concat(op, " ").concat(bin.pred[op], ". \n");
167+
valuesText.textContent += "Number of values in ".concat(bin.bin_name, " bin: ").concat(values.length, ". \n");
168+
// Clear previous rows
169+
while (table.rows.length > 1) {
170+
table.deleteRow(1);
171+
}
172+
// Create data rows
173+
values.forEach(function (item) {
174+
var row = document.createElement('tr');
175+
uniqueFields.forEach(function (col) {
176+
var cell = document.createElement('td');
177+
cell.textContent = item[col] || ''; // Handle missing data
178+
row.appendChild(cell);
179+
});
180+
table.appendChild(row);
181+
});
155182
}
156183
else {
157184
valuesButton.textContent = "Show Values for ".concat(bin.bin_name);
158185
valuesText.style.display = 'none';
186+
table.style.display = 'none';
159187
valuesText.textContent = '';
160188
}
161189
});
162190
binButtonContainer.appendChild(valuesButton);
163191
binButtonContainer.appendChild(valuesText);
192+
binButtonContainer.appendChild(table);
164193
binsContainer_1.appendChild(binButtonContainer);
165194
});
166195
// Display response - Modify according to your actual response format
@@ -251,7 +280,7 @@ function fetchOpenAI(apiKey, fieldValues, field) {
251280
'OpenAI-Beta': 'assistants=v1'
252281
},
253282
body: JSON.stringify({
254-
instructions: "Please analyze the uploaded dataset. For a field in the dataset, you will format all of it's binnings \n using the Vega-Lite predicate formatting. For a bin, a field must be provided along with one of \n the predicate properties: equal, lt (less than), lte (less than or equal), gt (greater than), \n gte (greater than or equal), range, or oneOf.\n \n For example, if we have:\n\n {\n \"field\": \"Displacement\",\n \"field_bins\": [\"Compact\", \"Mid-Size\", \"Full-Size\"]\n },\n \n You should output:\n \n { bins: [\n {\n \"bin_name\": \"Compact\",\n \"pred\": {\n \"field\": \"Displacement\",\n \"lte\": 100,\n \"reasoning\": [insert detailed reasoning for bin and its boundaries]\n }\n },\n {\n \"bin_name\": \"Mid-Size\",\n \"pred\": {\n \"field\": \"Displacement\",\n \"range\": [101, 150],\n \"reasoning\": [insert detailed reasoning for bin]\n }\n },\n {\n \"bin_name\": \"Full-Size\",\n \"pred\": {\n \"field\": \"Displacement\",\n \"gt\": 150,\n \"reasoning\": [insert detailed reasoning for bin]\n }\n }\n ]\n }\n\n Another example, if we have:\n\n {\n \"field\": \"car_origin\",\n \"field_bins\": [\"Japan\", \"USA\", \"France\"]\n },\n \n You should output:\n \n { bins: [\n {\n \"bin_name\": \"Japan\",\n \"pred\": {\n \"field\": \"car_origin\",\n \"oneOf\": [\"nissan\", \"lexus\"],\n \"reasoning\": [insert detailed reasoning for bin and its boundaries]\n }\n },\n {\n \"bin_name\": \"USA\",\n \"pred\": {\n \"field\": \"car_origin\",\n \"oneOf\": [\"ford\", \"ram\"],\n \"reasoning\": [insert detailed reasoning for bin]\n }\n },\n {\n \"bin_name\": \"France\",\n \"pred\": {\n \"field\": \"car_origin\",\n \"oneOf\": [\"renault\", \"citroen\"],\n \"reasoning\": [insert detailed reasoning for bin]\n }\n }\n ]\n }",
283+
instructions: "Please analyze the uploaded dataset. For a field in the dataset, you will format all of it's binnings \n using the Vega-Lite predicate formatting. For a bin, a field must be provided along with one of \n the predicate properties: equal, lt (less than), lte (less than or equal), gt (greater than), \n gte (greater than or equal), range, or oneOf to describe what data for that field belong in that bin.\n \n For example, if we have:\n\n {\n \"field\": \"Displacement\",\n \"field_bins\": [\"Compact\", \"Mid-Size\", \"Full-Size\"]\n },\n \n You should output:\n \n { bins: [\n {\n \"bin_name\": \"Compact\",\n \"pred\": {\n \"field\": \"Displacement\",\n \"lte\": 100,\n \"reasoning\": [insert detailed reasoning for bin and its boundaries]\n }\n },\n {\n \"bin_name\": \"Mid-Size\",\n \"pred\": {\n \"field\": \"Displacement\",\n \"range\": [101, 150],\n \"reasoning\": [insert detailed reasoning for bin]\n }\n },\n {\n \"bin_name\": \"Full-Size\",\n \"pred\": {\n \"field\": \"Displacement\",\n \"gt\": 150,\n \"reasoning\": [insert detailed reasoning for bin]\n }\n }\n ]\n }\n\n Another example, if we have:\n\n {\n \"field\": \"car_origin\",\n \"field_bins\": [\"Japan\", \"USA\", \"France\"]\n },\n \n You should output:\n \n { bins: [\n {\n \"bin_name\": \"Japan\",\n \"pred\": {\n \"field\": \"car_origin\",\n \"oneOf\": [\"nissan\", \"lexus\"],\n \"reasoning\": [insert detailed reasoning for bin and its boundaries]\n }\n },\n {\n \"bin_name\": \"USA\",\n \"pred\": {\n \"field\": \"car_origin\",\n \"oneOf\": [\"ford\", \"ram\"],\n \"reasoning\": [insert detailed reasoning for bin]\n }\n },\n {\n \"bin_name\": \"France\",\n \"pred\": {\n \"field\": \"car_origin\",\n \"oneOf\": [\"renault\", \"citroen\"],\n \"reasoning\": [insert detailed reasoning for bin]\n }\n }\n ]\n }",
255284
model: "gpt-4-1106-preview",
256285
tools: [{ "type": "retrieval" }],
257286
// file_ids: [fileId]
@@ -284,7 +313,7 @@ function fetchOpenAI(apiKey, fieldValues, field) {
284313
},
285314
{
286315
"role": "user",
287-
"content": "Create a way of breaking down this data in a non-obvious way that includes the semantic meaning of the data with the following JSON format.\n {\n bins : [\n {\n bin_name: [insert bin name]\n \"pred\" : {insert predicate information}\n }\n ]\n }\n "
316+
"content": "Create a way of breaking down this data in a non-obvious way that includes the semantic meaning of the data with the following JSON format.\n Make sure the predicate can map directly to the earlier values and that the JSON you output is a valid JSON.\n {\n bins : [\n {\n bin_name: [insert bin name]\n \"pred\" : {insert predicate information}\n }\n ]\n }\n "
288317
}
289318
]
290319
}
@@ -384,8 +413,8 @@ function getDataValues(fileContent, pred) {
384413
console.log(pred[op]);
385414
switch (op) {
386415
case 'equal':
387-
console.log(fileContent.filter(function (item) { return item[field] === Number(pred[op]); }));
388-
return fileContent.filter(function (item) { return item[field] === Number(pred[op]); });
416+
console.log(fileContent.filter(function (item) { return [pred[op]].includes(item[field]); }));
417+
return fileContent.filter(function (item) { return [pred[op]].includes(item[field]); });
389418
case 'oneOf':
390419
console.log(fileContent.filter(function (item) { return pred[op].includes(item[field]); }));
391420
return fileContent.filter(function (item) { return pred[op].includes(item[field]); });

0 commit comments

Comments
 (0)