-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move formatting/looks code + search init
- Loading branch information
Showing
12 changed files
with
307 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// upload file handler | ||
export function parseFile(event) { | ||
return new Promise((resolve, reject) => { | ||
// set the worker | ||
pdfjsLib.GlobalWorkerOptions.workerSrc = | ||
"https://cdnjs.cloudflare.com/ajax/libs/pdf.js/4.5.136/pdf.worker.min.mjs"; | ||
|
||
// get file | ||
const file = event.target.files[0]; | ||
|
||
// verify that file is pdf | ||
if (file.type !== "application/pdf") { | ||
alert("Please upload a PDF file."); | ||
reject("File is not a PDF."); | ||
return; | ||
} | ||
|
||
// clear output | ||
clearTableOutput(); | ||
clearStatsOutput(); | ||
|
||
// new file reader | ||
const reader = new FileReader(); | ||
|
||
// when file successfully read | ||
reader.onload = function (event) { | ||
// store raw binary data of file | ||
const typedarray = new Uint8Array(event.target.result); | ||
|
||
// get pdf from raw binary data | ||
pdfjsLib.getDocument(typedarray).promise.then(function (pdf) { | ||
// initializes array to hold promises for each page | ||
const pagesPromises = []; | ||
|
||
// extract room + room infos | ||
const rooms = []; | ||
let roomsInfoList = []; | ||
|
||
// don't remove if | ||
// not whitespace and not any of following: | ||
// 'College' | ||
// 'Building' | ||
// 'Room' | ||
// 'Type' | ||
// 'Sq. Ft.' | ||
// 'Updated' | ||
function noRemove(item) { | ||
return ( | ||
!/^\s*$/.test(item.str) && | ||
item.str !== "College" && | ||
item.str !== "Building" && | ||
item.str !== "Room" && | ||
item.str !== "Type" && | ||
item.str !== "Sq. Ft." && | ||
!item.str.includes("Updated") && | ||
item.str !== "Dorm" && | ||
item.str !== "Sq Foot" && | ||
!item.str.includes("you") | ||
); | ||
} | ||
|
||
// iterate through each page | ||
for (let pageNum = 1; pageNum <= pdf.numPages; pageNum++) { | ||
// keep track of promises for each page (when each page gets retrieved) | ||
pagesPromises.push( | ||
pdf.getPage(pageNum).then(function (page) { | ||
// get text content of each page | ||
return page.getTextContent().then(function (textContent) { | ||
// extract relevant room info | ||
const roomsInPage = textContent.items | ||
.filter(noRemove) | ||
.map((item) => item.str) | ||
.filter((item) => item !== ""); | ||
|
||
// organize room info | ||
let room = {}; | ||
for (let i = 0; i < roomsInPage.length; i++) { | ||
if (i % 5 === 0) { | ||
room = {}; | ||
rooms.push(room); | ||
room["college"] = roomsInPage[i]; | ||
} else if (i % 5 === 1) { | ||
room["building"] = roomsInPage[i]; | ||
} else if (i % 5 === 2) { | ||
room["room"] = roomsInPage[i]; | ||
} else if (i % 5 === 3) { | ||
room["type"] = roomsInPage[i]; | ||
} else { | ||
room["sqft"] = roomsInPage[i]; | ||
} | ||
} | ||
roomsInfoList = roomsInfoList.concat(roomsInPage); | ||
}); | ||
}), | ||
); | ||
} | ||
|
||
// when all pages processed | ||
Promise.all(pagesPromises) | ||
.then(function () { | ||
console.log("All pages processed"); | ||
resolve(rooms); | ||
}) | ||
.catch((error) => { | ||
reject(error); | ||
}); | ||
}); | ||
}; | ||
|
||
// read file to trigger load even when read complete | ||
reader.readAsArrayBuffer(file); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
function dialog() { | ||
// brief instructions | ||
const dialog = document.querySelector("dialog"); | ||
const closeButton = document.querySelector("dialog button"); | ||
|
||
// "Close" button closes the dialog | ||
closeButton.addEventListener("click", () => { | ||
dialog.close(); | ||
}); | ||
|
||
// hide output initially output initially | ||
document.getElementById("output").style.display = "none"; | ||
} | ||
|
||
// remove site banner | ||
function fadeBanner() { | ||
let banner = document.getElementById("banner"); | ||
if (banner) { | ||
banner.classList.add("opacity-0"); | ||
setTimeout(function () { | ||
banner.remove(); | ||
}, 500); | ||
} | ||
} | ||
|
||
// clear output | ||
function clearTableOutput() { | ||
const table = document.getElementById("table-div"); | ||
table.innerHTML = `<span class="loading loading-infinity loading-lg text-warning"></span>`; | ||
} | ||
|
||
// clear output | ||
function clearStatsOutput() { | ||
const stats = document.getElementById("stats-div"); | ||
stats.innerHTML = `<span class="loading loading-infinity loading-lg text-warning"></span>`; | ||
} | ||
|
||
// remove space evenly for main justify-evenly | ||
function removeSpacing() { | ||
document.getElementsByTagName("main")[0].classList.remove("justify-evenly"); | ||
} | ||
|
||
// show table etc | ||
function showOutput() { | ||
document.getElementById("output").style.display = "flex"; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,8 @@ | |
"devDependencies": { | ||
"daisyui": "^4.12.2", | ||
"tailwindcss": "^3.4.3" | ||
}, | ||
"dependencies": { | ||
"fuse.js": "^7.0.0" | ||
} | ||
} |
Oops, something went wrong.