Skip to content

Commit

Permalink
Merge pull request #8 from adedolapoadegboye/export-results
Browse files Browse the repository at this point in the history
Export results
  • Loading branch information
adedolapoadegboye authored Aug 1, 2024
2 parents 6ba61e7 + d0ef168 commit 9a3f6f8
Show file tree
Hide file tree
Showing 7 changed files with 350 additions and 119 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gnssmetrics",
"version": "1.0.4",
"version": "1.0.5",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
Expand Down
2 changes: 1 addition & 1 deletion public/Examples/example-2D.csv
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,4 @@ Latitude,Longitude
51.1802495,-114.1319418
51.1801314,-114.1320491
51.1802924,-114.1320491
51.1802924,-114.1320276
51.1802924,-114.1320276
200 changes: 100 additions & 100 deletions public/Examples/example-3D.csv
Original file line number Diff line number Diff line change
@@ -1,101 +1,101 @@
Latitude,Longitude,Altitude
21.1803138,-114.1320062,1050
21.1803246,-114.1320920,1050
21.1803997,-114.1321993,1050
21.1805069,-114.1321564,1050
21.1801821,-114.1320062,1050
21.1803246,-114.1319847,1050
21.1803138,-114.1320276,1050
21.1803782,-114.1320705,1050
21.1807108,-114.1320705,1050
21.1801636,-114.1321349,1050
21.1804426,-114.1319847,1050
21.1803460,-114.1320491,1050
21.1803997,-114.1319203,1050
21.1803889,-114.1320062,1050
21.1803460,-114.1320062,1050
21.1802924,-114.1319418,1050
21.1804748,-114.1321993,1050
21.1801529,-114.1320276,1050
21.1802709,-114.1321778,1050
21.1803246,-114.1320491,1050
21.1803782,-114.1320062,1050
21.1802602,-114.1320920,1050
21.1803031,-114.1320276,1050
21.1802280,-114.1320491,1050
21.1802816,-114.1320062,1050
21.1802924,-114.1319633,1050
21.1803782,-114.1320920,1050
21.1803567,-114.1321349,1050
21.1805606,-114.1320062,1050
21.1803567,-114.1321564,1050
21.1804426,-114.1320920,1050
21.1801314,-114.1320705,1050
21.1802495,-114.1320062,1050
21.1804104,-114.1320705,1050
21.1803675,-114.1320705,1050
21.1802280,-114.1320491,1050
21.1803138,-114.1320062,1050
21.1802280,-114.1321993,1050
21.1804211,-114.1321778,1050
21.1803675,-114.1322422,1050
21.1801422,-114.1321564,1050
21.1803138,-114.1323280,1050
21.1801744,-114.1325212,1050
21.1803246,-114.1321564,1050
21.1804104,-114.1320062,1050
21.1802816,-114.1319847,1050
21.1803782,-114.1320276,1050
21.1802816,-114.1320705,1050
21.1802924,-114.1319203,1050
21.1802280,-114.1320062,1050
21.1803460,-114.1320491,1050
21.1802495,-114.1320491,1050
21.1803138,-114.1320920,1050
21.1803997,-114.1320705,1050
21.1804318,-114.1321564,1050
21.1803889,-114.1320705,1050
21.1804533,-114.1321135,1050
21.1801958,-114.1320062,1050
21.1802924,-114.1321778,1050
21.1803567,-114.1321135,1050
21.1803246,-114.1320062,1050
21.1802602,-114.1320491,1050
21.1803460,-114.1320062,1050
21.1803889,-114.1320491,1050
21.1802924,-114.1320705,1050
21.1803460,-114.1320062,1050
21.1802387,-114.1320491,1050
21.1803675,-114.1320276,1050
21.1802387,-114.1320705,1050
21.1803675,-114.1320276,1050
21.1803782,-114.1320062,1050
21.1803031,-114.1320062,1050
21.1803675,-114.1320491,1050
21.1802495,-114.1320062,1050
21.1802924,-114.1319203,1050
21.1803138,-114.1319847,1050
21.1803138,-114.1320705,1050
21.1802177,-114.1313839,1050
21.1803246,-114.1320062,1050
21.1802065,-114.1320705,1050
21.1803246,-114.1320276,1050
21.1803031,-114.1321135,1050
21.1803567,-114.1320491,1050
21.1802924,-114.1320062,1050
21.1803353,-114.1319847,1050
21.1803460,-114.1320491,1050
21.1805284,-114.1321564,1050
21.1804104,-114.1320920,1050
21.1803997,-114.1321349,1050
21.1800671,-114.1319633,1050
21.1801744,-114.1319847,1050
21.1803246,-114.1320276,1050
21.1802065,-114.1320705,1050
21.1802924,-114.1321135,1050
21.1802602,-114.1319418,1050
21.1801207,-114.1319418,1050
21.1802495,-114.1319418,1050
21.1801314,-114.1320491,1050
21.1802924,-114.1320491,1050
21.1802924,-114.1320276,1050
51.1803138,-114.1320062,1050
51.1803246,-114.1320920,1050
51.1803997,-114.1351993,1050
51.1805069,-114.1351564,1050
51.1801851,-114.1320062,1050
51.1803246,-114.1319847,1050
51.1803138,-114.1320276,1050
51.1803782,-114.1320705,1050
51.1807108,-114.1320705,1050
51.1801636,-114.1351349,1050
51.1804426,-114.1319847,1050
51.1803460,-114.1320491,1050
51.1803997,-114.1319203,1050
51.1803889,-114.1320062,1050
51.1803460,-114.1320062,1050
51.1802924,-114.1319418,1050
51.1804748,-114.1351993,1050
51.1801529,-114.1320276,1050
51.1802709,-114.1351778,1050
51.1803246,-114.1320491,1050
51.1803782,-114.1320062,1050
51.1802602,-114.1320920,1050
51.1803031,-114.1320276,1050
51.1802280,-114.1320491,1050
51.1802816,-114.1320062,1050
51.1802924,-114.1319633,1050
51.1803782,-114.1320920,1050
51.1803567,-114.1351349,1050
51.1805606,-114.1320062,1050
51.1803567,-114.1351564,1050
51.1804426,-114.1320920,1050
51.1801314,-114.1320705,1050
51.1802495,-114.1320062,1050
51.1804104,-114.1320705,1050
51.1803675,-114.1320705,1050
51.1802280,-114.1320491,1050
51.1803138,-114.1320062,1050
51.1802280,-114.1351993,1050
51.1804511,-114.1351778,1050
51.1803675,-114.1322422,1050
51.1801422,-114.1351564,1050
51.1803138,-114.1323280,1050
51.1801744,-114.1325512,1050
51.1803246,-114.1351564,1050
51.1804104,-114.1320062,1050
51.1802816,-114.1319847,1050
51.1803782,-114.1320276,1050
51.1802816,-114.1320705,1050
51.1802924,-114.1319203,1050
51.1802280,-114.1320062,1050
51.1803460,-114.1320491,1050
51.1802495,-114.1320491,1050
51.1803138,-114.1320920,1050
51.1803997,-114.1320705,1050
51.1804318,-114.1351564,1050
51.1803889,-114.1320705,1050
51.1804533,-114.1351135,1050
51.1801958,-114.1320062,1050
51.1802924,-114.1351778,1050
51.1803567,-114.1351135,1050
51.1803246,-114.1320062,1050
51.1802602,-114.1320491,1050
51.1803460,-114.1320062,1050
51.1803889,-114.1320491,1050
51.1802924,-114.1320705,1050
51.1803460,-114.1320062,1050
51.1802387,-114.1320491,1050
51.1803675,-114.1320276,1050
51.1802387,-114.1320705,1050
51.1803675,-114.1320276,1050
51.1803782,-114.1320062,1050
51.1803031,-114.1320062,1050
51.1803675,-114.1320491,1050
51.1802495,-114.1320062,1050
51.1802924,-114.1319203,1050
51.1803138,-114.1319847,1050
51.1803138,-114.1320705,1050
51.1805177,-114.1313839,1050
51.1803246,-114.1320062,1050
51.1802065,-114.1320705,1050
51.1803246,-114.1320276,1050
51.1803031,-114.1351135,1050
51.1803567,-114.1320491,1050
51.1802924,-114.1320062,1050
51.1803353,-114.1319847,1050
51.1803460,-114.1320491,1050
51.1805284,-114.1351564,1050
51.1804104,-114.1320920,1050
51.1803997,-114.1351349,1050
51.1800671,-114.1319633,1050
51.1801744,-114.1319847,1050
51.1803246,-114.1320276,1050
51.1802065,-114.1320705,1050
51.1802924,-114.1351135,1050
51.1802602,-114.1319418,1050
51.1801207,-114.1319418,1050
51.1802495,-114.1319418,1050
51.1801314,-114.1320491,1050
51.1802924,-114.1320491,1050
51.1802924,-114.1320276,1050
Binary file modified public/Examples/example-3D.xlsx
Binary file not shown.
145 changes: 145 additions & 0 deletions src/Dev/Components/Visualizers/DataExports.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import React from "react";
import * as XLSX from "xlsx";
import { saveAs } from "file-saver";

const DataExports = (props) => {
const {
file,
refLat,
refLong,
refAlt,
meanAlt,
meanLat,
meanLong,
cep50,
cep90,
cep98,
meanCep50,
meanCep90,
meanCep98,
sep50,
sep90,
sep98,
meanSep50,
meanSep90,
meanSep98,
plotData,
altPlotData,
} = props;

const exportToExcelAndKml = () => {
// Data for the second sheet
const fileData = file.data.map((item, index) => {
const dataEntry = {
Latitude: item.Latitude,
Longitude: item.Longitude,
"2D Fix Error": plotData[index],
};

// Add Altitude and 3D Fix Error if Altitude exists
if (item.Altitude !== undefined) {
dataEntry.Altitude = item.Altitude;
dataEntry["3D Fix Error"] = altPlotData[index];
}

return dataEntry;
});

// Data for the first sheet
const statsData = [
["Statistics", "Value"],
["Reference Latitude", refLat],
["Reference Longitude", refLong],
["Reference Altitude", refAlt],
["Mean Altitude", meanAlt],
["Mean Latitude", meanLat],
["Mean Longitude", meanLong],
["CEP 50%", cep50],
["CEP 90%", cep90],
["CEP 98%", cep98],
["Mean CEP 50%", meanCep50],
["Mean CEP 90%", meanCep90],
["Mean CEP 98%", meanCep98],
["SEP 50%", sep50],
["SEP 90%", sep90],
["SEP 98%", sep98],
["Mean SEP 50%", meanSep50],
["Mean SEP 90%", meanSep90],
["Mean SEP 98%", meanSep98],
];

// Create a new workbook
const workbook = XLSX.utils.book_new();

// Create the first sheet and append it to the workbook
const ws1 = XLSX.utils.aoa_to_sheet(statsData);
XLSX.utils.book_append_sheet(workbook, ws1, "Statistics");

// Create the second sheet and append it to the workbook
const ws2 = XLSX.utils.json_to_sheet(fileData);
XLSX.utils.book_append_sheet(workbook, ws2, "Data");

// Write the workbook to a binary string
const excelBuffer = XLSX.write(workbook, {
bookType: "xlsx",
type: "array",
});

// Create a Blob object from the binary string
const excelBlob = new Blob([excelBuffer], {
type: "application/octet-stream",
});

// Generate a timestamp for the filename
const timestamp = new Date()
.toISOString()
.replace(/[-:T.]/g, "")
.slice(0, 14);

// Trigger the file download for the Excel file
saveAs(excelBlob, `data_results_${timestamp}.xlsx`);

// Generate KML content
const kmlContent = `<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>Position Fixes</name>
<description>Position Fixes from GNSS Data</description>
${fileData
.map(
(item, index) => `
<Placemark>
<name>Fix ${index}</name>
<Point>
<coordinates>${item.Longitude},${item.Latitude},${
item.Altitude ? item.Altitude : 0
}</coordinates>
</Point>
</Placemark>`
)
.join("")}
</Document>
</kml>`;

// Create a Blob object for the KML file
const kmlBlob = new Blob([kmlContent], {
type: "application/vnd.google-earth.kml+xml",
});

// Trigger the file download for the KML file
saveAs(kmlBlob, `data_results_${timestamp}.kml`);
};

return (
<div>
<button
className="h-fit w-fit px-6 py-3 border bg-gray-700 rounded-2xl text-white transition duration-300 ease-in-out hover:bg-blue-500"
onClick={exportToExcelAndKml}
>
Download Results
</button>
</div>
);
};

export default DataExports;
Loading

0 comments on commit 9a3f6f8

Please sign in to comment.