-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2bb0940
commit 719ee65
Showing
8 changed files
with
498 additions
and
75 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,21 @@ | ||
|
||
.CodeMirror { | ||
border: 1px solid #222; | ||
height: auto; | ||
} | ||
|
||
.CodeMirror-scroll { | ||
overflow-y: hidden; | ||
overflow-x: auto; | ||
} | ||
|
||
.error { | ||
color: red; | ||
transition: .5s; | ||
overflow: hidden; | ||
margin: 15px; | ||
} | ||
|
||
#output { | ||
overflow: auto; | ||
} |
File renamed without changes.
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,45 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="utf8"> | ||
<title>NEET 2024 Center-Wise Marks SQL Interface</title> | ||
<!-- Begin Jekyll SEO tag v2.8.0 --> | ||
<meta property="og:title" content="NEET 2024 Center-Wise Marks SQL Interface" /> | ||
<meta property="og:locale" content="en_US" /> | ||
<meta name="description" content="A browser based SQL Interface for NEET 2024 center-wise marks data, which allows you to explore and analyze using SQL queries." /> | ||
<meta property="og:description" content="A browser based SQL Interface for NEET 2024 center-wise marks data, which allows you to explore and analyze using SQL queries." /> | ||
<link rel="canonical" href="https://pardhavmaradani.github.io/neet-2024-center-marks/" /> | ||
<meta property="og:url" content="https://pardhavmaradani.github.io/neet-2024-center-marks/" /> | ||
<meta property="og:site_name" content="NEET 2024 Center-Wise Marks SQL Interface" /> | ||
<meta property="og:type" content="website" /> | ||
<meta name="twitter:card" content="summary" /> | ||
<meta property="twitter:title" content="NEET 2024 Center-Wise Marks SQL Interface" /> | ||
<!-- End Jekyll SEO tag --> | ||
|
||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.1/codemirror.css"> | ||
<link rel="stylesheet" href="css/styles.css"> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.1/codemirror.js"></script> | ||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous"> | ||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script> | ||
</head> | ||
|
||
<body> | ||
<div class="container"> | ||
<h1 class='mt-4 text-center'>NEET 2024 Center-Wise Marks SQL Interface</h1> | ||
<label class="mt-4" for='commands'>Enter some SQL commands (<b>'Ctrl-Enter'</b> to execute):</label> | ||
<div class="form-floating"> | ||
<textarea class="form-control" id="commands"></textarea> | ||
</div> | ||
<div class="mt-2 text-center"> | ||
<button id="execute" type="button" class="btn btn-primary">Execute</button> | ||
</div> | ||
<div id="error" class="mt-4 error"></div> | ||
<div id="output" class="table-responsive">Please wait. Results will be displayed here...</div> | ||
</div> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.1/mode/sql/sql.min.js"></script> | ||
<script type="text/javascript" src="js/interact.js"></script> | ||
</body> | ||
|
||
</html> |
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,111 @@ | ||
// Based on the sql.js GUI example at: | ||
// https://github.com/sql-js/sql.js/blob/master/examples/GUI/gui.js | ||
|
||
var execBtn = document.getElementById("execute"); | ||
var outputElm = document.getElementById('output'); | ||
var errorElm = document.getElementById('error'); | ||
var commandsElm = document.getElementById('commands'); | ||
|
||
// Start the worker in which sql.js will run | ||
var worker = new Worker("js/worker.sql-wasm.js"); | ||
worker.onerror = error; | ||
|
||
// Open a database | ||
worker.postMessage({ action: 'open' }); | ||
|
||
// Connect to the HTML element we 'print' to | ||
function print(text) { | ||
outputElm.innerHTML = text.replace(/\n/g, '<br>'); | ||
} | ||
|
||
function error(e) { | ||
console.log(e); | ||
errorElm.style.height = '2em'; | ||
errorElm.textContent = e.message; | ||
} | ||
|
||
function noerror() { | ||
errorElm.style.height = '0'; | ||
} | ||
|
||
// Run a command in the database | ||
function execute(commands) { | ||
worker.onmessage = function (event) { | ||
var results = event.data.results; | ||
if (!results) { | ||
error({ message: event.data.error }); | ||
return; | ||
} | ||
outputElm.innerHTML = ""; | ||
for (var i = 0; i < results.length; i++) { | ||
outputElm.appendChild(tableCreate(results[i].columns, results[i].values)); | ||
} | ||
} | ||
worker.postMessage({ action: 'exec', sql: commands }); | ||
outputElm.textContent = "Fetching results..."; | ||
} | ||
|
||
// Create an HTML table | ||
var tableCreate = function () { | ||
function valconcat(vals, tagName) { | ||
if (vals.length === 0) return ''; | ||
var open = '<' + tagName + '>', close = '</' + tagName + '>'; | ||
return open + vals.join(close + open) + close; | ||
} | ||
return function (columns, values) { | ||
var tbl = document.createElement('table'); | ||
tbl.setAttribute("class", "table table-info table-striped table-bordered border-primary"); | ||
var html = '<thead>' + valconcat(columns, 'th') + '</thead>'; | ||
var rows = values.map(function (v) { return valconcat(v, 'td'); }); | ||
html += '<tbody>' + valconcat(rows, 'tr') + '</tbody>'; | ||
tbl.innerHTML = html; | ||
return tbl; | ||
} | ||
}(); | ||
|
||
// Execute the commands when the button is clicked | ||
function execEditorContents() { | ||
noerror() | ||
execute(editor.getValue() + ';'); | ||
} | ||
execBtn.addEventListener("click", execEditorContents, true); | ||
|
||
// Add syntax highlihjting to the textarea | ||
var editor = CodeMirror.fromTextArea(commandsElm, { | ||
mode: 'text/x-mysql', | ||
viewportMargin: Infinity, | ||
indentWithTabs: true, | ||
smartIndent: true, | ||
lineNumbers: true, | ||
matchBrackets: true, | ||
autofocus: true, | ||
extraKeys: { | ||
"Ctrl-Enter": execEditorContents, | ||
} | ||
}); | ||
|
||
// Fetch the database | ||
async function fetchDB(){ | ||
const [buf] = await Promise.all([ | ||
fetch("db/neet-2024-center-marks-data.db").then(res => res.arrayBuffer()) | ||
]); | ||
worker.onmessage = function () { | ||
// Show the schema of the loaded database | ||
editor.setValue("SELECT `name`, `sql` FROM `sqlite_master` WHERE type='table';\n" + | ||
"SELECT * FROM centers LIMIT 5;\n" + | ||
"SELECT count() AS 'No of Centers' FROM centers;\n" + | ||
"SELECT * FROM center_longnames LIMIT 5;\n" + | ||
"SELECT * FROM center_marks LIMIT 5;\n" + | ||
"SELECT count() AS 'No of Students' FROM center_marks;\n" | ||
); | ||
execEditorContents(); | ||
}; | ||
try { | ||
worker.postMessage({ action: 'open', buffer: buf }, [buf]); | ||
} | ||
catch (exception) { | ||
worker.postMessage({ action: 'open', buffer: buf }); | ||
} | ||
} | ||
|
||
fetchDB(); |
Binary file not shown.
Oops, something went wrong.