Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

last pr #6

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"cmdk-sv": "^0.0.13",
"csv-parser": "^3.0.0",
"csvtojson": "^2.0.10",
"json-2-csv": "^5.0.1",
"lucide-svelte": "^0.331.0",
"radix-icons-svelte": "^1.2.1",
"tailwind-merge": "^2.2.1",
Expand Down
58 changes: 35 additions & 23 deletions src/routes/demo/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@
// import { Label } from "$lib/components/ui/label";
import { Button } from '$lib/components/ui/button';
import csvtojson from 'csvtojson';
import { json2csv } from 'json-2-csv';

// to do
let features: string[];
let userData: any[] = [];
let anonymizedStringArray: any[] = [];
let anonymizedData: any[] = [];
let jsonArray: object[] = [];
let dataObject;

let originalCSV: string | Blob;
let anonymizedCSV;
let anonymizedCSV: string | Blob;

function readFile(file: Blob) {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -70,12 +68,22 @@
);
data.push(obj);
}

return data;
}

async function convertObjectToCSV(dataObject: object[]) {
return await json2csv(dataObject);
function convertJsonToCsv(dataObject: object[]) {
// Get the headers (object keys)
const headers = features;

// Map each object in the array to a CSV row
const rows = jsonArray.map((obj) => {
return headers.map((header: string) => obj[header as keyof typeof obj]).join(',');
});

// Combine the headers and rows into a single CSV string
const csv = [headers.join(',')].concat(rows).join('\n');

return csv;
}

const handleAnonymizeData = (e: any) => {
Expand Down Expand Up @@ -115,24 +123,28 @@
});
};

// const handleFeatureSelect = (e) => {
// e.preventDefault();
// const formData =
$: featureName = '';

const handleFeatureSelect = (e: any) => {
e.preventDefault();
const formData = new FormData();
formData.append('', featureName);
formData.append('', originalCSV);
formData.append('', anonymizedCSV);

// const url = 'https://trend-predictor-mwnxl4smaa-el.a.run.app';
const url = 'https://trend-predictor-mwnxl4smaa-el.a.run.app';

// fetch(url, {
// method: 'POST',
// body: formData
// })
// .then((response) => {
// if (!response.ok) {
// throw new Error('Network response was not ok');
// }
fetch(url, {
method: 'POST',
body: formData
}).then((response) => {
if (!response.ok) {
throw new Error('Network response was not ok');
}

// return response.json();
// })
// }
return response.json();
});
};
</script>

<main class="flex flex-col items-center">
Expand All @@ -144,7 +156,7 @@
</div>
{#if userData.length !== 0}
<form class="flex w-full items-center space-x-2">
<Input type="text" placeholder="feature" class="w-full" />
<Input type="text" placeholder="feature" class="w-full" bind:value={featureName} />
<Button type="submit" class="w-48">Subscribe</Button>
</form>
<h1 class="mb-4 mt-6 w-full text-center font-bold">Raw Data</h1>
Expand Down Expand Up @@ -176,7 +188,7 @@
<!-- to do -->
<h1 class="mb-4 mt-6 w-full text-center font-bold">Anonymized Data</h1>
<div class="max-h-96 w-full overflow-y-scroll border-2 border-slate-200 object-cover p-4">
<Table.Root>
<Table.Root class="overflow-x-visible">
<Table.Caption>A list of your recent invoices.</Table.Caption>
<Table.Header>
<Table.Row>
Expand Down