connect js to main.py

This commit is contained in:
SowinskiBraeden committed 2022-11-06 20:14:15 -08:00
1 parent 7b909b770b
commit 37b961745d
10 files changed
+56 -39

No files matched your search

+6
View File
@@ -0,0 +1,6 @@
# pycache
app/__pycache__/
app/util/__pycache__/
# output
output/
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1 -2
View File
@@ -22,8 +22,7 @@ def getCourses(
courses[row["CrsNo"]] = { courses[row["CrsNo"]] = {
"CrsNo": row["CrsNo"], "CrsNo": row["CrsNo"],
"Requests": 0, "Requests": 0,
"Description": row["Description"], "Description": row["Description"]
"students": []
} }
if log: if log:
+30 -5
View File
@@ -1,5 +1,6 @@
#!/usr/bin/env python3.11 #!/usr/bin/env python3.11
import eel import eel
import os
from app.generator import generateScheduleV3 from app.generator import generateScheduleV3
from app.util.globals import Error from app.util.globals import Error
from app.util.getCourses import getCourses from app.util.getCourses import getCourses
@@ -9,15 +10,28 @@ eel.init('template')
@eel.expose @eel.expose
def start( def start(
input_file_dir: str, raw_file_data: str,
min_req: int, min_req: int,
class_cap: int, class_cap: int,
block_class_limit: int, block_class_limit: int,
total_blocks: int, total_blocks: int,
) -> Error: ) -> Error:
# Ensure output paths exists
if not os.path.exists('output'): os.makedirs('output')
if not os.path.exists('output/temp'): os.makedirs('output/temp')
if not os.path.exists('output/final'): os.makedirs('output/final')
if not os.path.exists('output/final/student_schedules'): os.makedirs('output/final/student_schedules')
if not os.path.exists('output/raw'): os.makedirs('output/raw')
raw_data_dir = './output/temp/course_selection_data.csv'
# save raw file data to local file
with open(raw_data_dir, 'w') as raw_file:
raw_file_data = raw_file_data.replace('\n', '')
raw_file.write(raw_file_data)
# Ensure params are of correct type # Ensure params are of correct type
input_file_dir = str(input_file_dir)
min_req = int(min_req) min_req = int(min_req)
class_cap = int(class_cap) class_cap = int(class_cap)
block_class_limit = int(block_class_limit) block_class_limit = int(block_class_limit)
@@ -26,11 +40,20 @@ def start(
err = None err = None
# call pre-algorithm functions read raw data into a processable format # call pre-algorithm functions read raw data into a processable format
students = getStudents(input_file_dir, log=True, totalBlocks=total_blocks) students = getStudents(
courses = getCourses(input_file_dir, log=True) raw_data_dir,
log=True,
totalBlocks=total_blocks,
log_dir='./output/raw/students.json'
)
courses = getCourses(
raw_data_dir,
log=True,
log_dir='./output/raw/courses.json'
)
# call algorithm to sort data # call algorithm to sort data
master_timetable, err = generateScheduleV3( _, err = generateScheduleV3(
students, students,
courses, courses,
minReq=min_req, minReq=min_req,
@@ -41,6 +64,8 @@ def start(
conflictsDir='./output/raw/conflicts.json' conflictsDir='./output/raw/conflicts.json'
) )
print(err)
# TODO: log master_timetable # TODO: log master_timetable
# TODO: call post-algorithm functions to present sorted data # TODO: call post-algorithm functions to present sorted data
+2 -2
View File
@@ -17,7 +17,7 @@
<div class="shape"></div> <div class="shape"></div>
<div class="shape"></div> <div class="shape"></div>
</div> </div>
<div class="main"> <div id="main" class="main">
<h3>Schedule Generator</h3> <h3>Schedule Generator</h3>
<label for="input_file">Input File (.csv)</label> <label for="input_file">Input File (.csv)</label>
<input <input
@@ -85,7 +85,7 @@
<button id="startBtn" onclick="start()">Generate</button> <button id="startBtn" onclick="start()">Generate</button>
</div> </div>
<div class="processing"> <div id="processing" class="processing">
<div id="myProgress"> <div id="myProgress">
<div id="myBar"></div> <div id="myBar"></div>
</div> </div>
+17 -30
View File
@@ -1,38 +1,25 @@
function start() { function start() {
let file = document.getElementById("input_file"); let file = document.getElementById("input_file").files[0];
let blockClassLimit = document.getElementById("classrooms").value;
let minReq = document.getElementById("min_req").value; let minReq = document.getElementById("min_req").value;
let classCap = document.getElementById("class_cap").value; let classCap = document.getElementById("class_cap").value;
let blockClassLimit = document.getElementById("classrooms").value;
let totalBlocks = document.getElementById("total_blocks").value; let totalBlocks = document.getElementById("total_blocks").value;
// start animation
document.getElementById('main').style.display = 'none';
document.getElementById('processing').style.display = 'block';
console.log(file); let reader = new FileReader()
} reader.addEventListener("load", () => {
let raw = reader.result;
eel.start(raw, minReq, classCap, blockClassLimit, totalBlocks)(start_callback);
}, false);
function summation() { if (file) {
var data_1 = document.getElementById("int1").value; reader.readAsText(file);
var data_2 = document.getElementById("int2").value;
eel.add(data_1, data_2)(call_Back);
}
function call_Back(output){
document.getElementById("res").value = output;
}
var i = 0;
function move() {
if (i == 0) {
i = 1;
var elem = document.getElementById("myBar");
var width = 1;
var id = setInterval(frame, 10);
function frame() {
if (width >= 100) {
clearInterval(id);
i = 0;
} else {
width++;
elem.style.width = width + "%";
}
}
} }
}
function start_callback(error) {
console.log(error, 'done')
} }