Skip to content

Commit

Permalink
Merge pull request #98 from Govind-S-B/dev
Browse files Browse the repository at this point in the history
Long overdue
  • Loading branch information
Govind-S-B authored Sep 17, 2023
2 parents 2622184 + a136ea5 commit 050a01d
Show file tree
Hide file tree
Showing 49 changed files with 2,458 additions and 468 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@ allocator/test/bin/*.db
allocator/test/bin/*.exe
allocator/test/reports/*.db
allocator/test/logs/*.txt
ehsa_frontend/build/windows/runner/Debug/ehsa_frontend.exe
ehsa_frontend/build/windows/runner/Debug/flutter_windows.dll
ehsa_frontend/build/windows/runner/Debug/url_launcher_windows_plugin.dll
ehsa_frontend/linux/flutter/generated_plugin_registrant.cc
ehsa_frontend/linux/flutter/generated_plugin_registrant.h
ehsa_frontend/linux/flutter/generated_plugins.cmake
ehsa_frontend/macos/Flutter/GeneratedPluginRegistrant.swift
ehsa_frontend/windows/flutter/generated_plugin_registrant.cc
ehsa_frontend/windows/flutter/generated_plugin_registrant.h
ehsa_frontend/windows/flutter/generated_plugins.cmake
4 changes: 2 additions & 2 deletions EHSA_V3/bin/config.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[exam info]
name="Marian Engineering College"
title="Internal Examination"
name=Marian Engineering College
title=Internal Examination
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ExamHall-SeatAllocator
A GUI application built in Flutter, Rust, and Python that automates the assignment of student seats in examinations and generates appropriate PDFs
A GUI application built in Flutter, Rust, and Python that automates the assignment of student seats in examinations and generates appropriate PDFs.

# Requirements
Windows 10 and above
Expand All @@ -8,7 +8,7 @@ MSVC++ Redist. ( packaged with installer )
# How to use
- go to [releases](https://github.com/Govind-S-B/ExamHall-SeatAllocator/releases)
- get the latest installer and run it
- to learn more about usage refer the (wiki)[todo: write wikipage and add link]
- to learn more about usage refer the [wiki](https://github.com/Govind-S-B/ExamHall-SeatAllocator/wiki)

# Algorithm
the seat assignment algorithm has 3 modes: `subject`, `class`, and `any`
Expand Down
6 changes: 3 additions & 3 deletions allocator/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ pub fn get() -> Arguments {
"-r" | "--randomize" => {
delta = Some(
args.next()
.expect("no argument after -r flag")
.expect("[ no argument after -r flag ]")
.parse()
.expect("invalid argument for delta"),
.expect("[ invalid argument for delta ]"),
)
}
_ => paths.push(arg),
Expand All @@ -26,7 +26,7 @@ pub fn get() -> Arguments {
let [_, input_db_path, output_db_path] = paths.as_slice()
else {
eprintln!("args given are {paths:?}");
panic!("INVALID ARGUMENTS: arguments should be \" ./allocator <input_db_path> <output_db_path> [-r | --randomize]");
panic!("[ INVALID ARGUMENTS: arguments should be \" ./allocator <input_db_path> <output_db_path> [-r | --randomize] ]");
};

Arguments {
Expand Down
20 changes: 11 additions & 9 deletions allocator/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use sqlite as sq;
use std::collections::hash_map::HashMap;

pub fn read_halls_table(conn: &Connection) -> Vec<Hall> {
let query = "SELECT * FROM halls ORDER BY capacity DESC";
let query = "SELECT name, capacity FROM halls ORDER BY capacity DESC";
let mut halls: Vec<Hall> = vec![];
conn.iterate(query, |pair| {
//pair is an array slice of the columns and the values in the colums
Expand All @@ -14,12 +14,12 @@ pub fn read_halls_table(conn: &Connection) -> Vec<Hall> {

let &(_, Some(hall_name)) = iter.next().unwrap()
else {
panic!("DATABASE NOT VALID")
panic!("[ HALL DATABASE NOT VALID ]")
};

let &(_, Some(capacity)) = iter.next().unwrap()
else {
panic!("DATABASE NOT VALID")
panic!("[ HALL DATABASE NOT VALID ]")
};

halls.push(Hall::new(hall_name, capacity.parse().unwrap()));
Expand All @@ -30,7 +30,7 @@ pub fn read_halls_table(conn: &Connection) -> Vec<Hall> {
halls
}
pub fn read_students_table(conn: &Connection) -> HashMap<String, Vec<Student>> {
let query = "SELECT * FROM students";
let query = "SELECT id, subject FROM students";
let mut students: HashMap<String, Vec<Student>> = HashMap::new();
conn.iterate(query, |pair| {
//pair is an array slice of the columns and the values in the colums
Expand All @@ -39,11 +39,11 @@ pub fn read_students_table(conn: &Connection) -> HashMap<String, Vec<Student>> {
let mut iter = pair.iter();
let &(_, Some(id)) = iter.next().unwrap()
else {
panic!("DATABASE NOT VALID")
panic!("[ STUDENT DATABASE NOT VALID ]")
};
let &(_, Some(subject)) = iter.next().unwrap()
else {
panic!("DATABASE NOT VALID")
panic!("[ STUDENT DATABASE NOT VALID ]")
};

let student = Student::new(id.to_owned(), subject.to_owned());
Expand All @@ -65,7 +65,8 @@ pub fn read_students_table(conn: &Connection) -> HashMap<String, Vec<Student>> {
}
pub fn write_report_table(conn: &Connection, halls: &Vec<Hall>) {
let query = "DROP TABLE IF EXISTS report";
conn.execute(query).expect("error dropping report table");
conn.execute(query)
.expect("[ error dropping report table ]");
let command = "
CREATE TABLE report
(id CHAR(15) PRIMARY KEY NOT NULL,
Expand All @@ -75,7 +76,8 @@ pub fn write_report_table(conn: &Connection, halls: &Vec<Hall>) {
seat_no INT NOT NULL,
subject CHAR(50) NOT NULL)";

conn.execute(command).expect("error creating report table");
conn.execute(command)
.expect("[ error creating report table ]");

let mut command =
"INSERT INTO report (id,class,roll_no,subject,hall,seat_no) VALUES".to_owned();
Expand All @@ -102,5 +104,5 @@ pub fn write_report_table(conn: &Connection, halls: &Vec<Hall>) {
command.pop();
command += ";";
conn.execute(command)
.expect("error inserting row into report table");
.expect("[ error inserting row into report table ]");
}
26 changes: 13 additions & 13 deletions allocator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ enum AllocationMode {
fn main() {
let args = args::get();

let conn = sqlite::open(args.input_db_path).expect("Error connecting to input.db");
let conn = sqlite::open(args.input_db_path).expect("[ Error connecting to input.db ]");
let mut students = db::read_students_table(&conn);
let mut halls = db::read_halls_table(&conn);
if let Some(delta) = args.randomize {
if delta == 0 {
panic!("delta is 0")
panic!("[ delta(CLI Argument) is 0 ]")
}
let mut rng = rand::thread_rng();
halls = {
Expand Down Expand Up @@ -78,9 +78,8 @@ fn main() {
let mut extra_seats = {
let total_seats: usize = halls.iter().map(|h| h.seats_left()).sum();
let total_students: usize = students.values().map(|s| s.len()).sum();

if total_students > total_seats {
panic!("ERROR: more students than seats")
panic!("[ more students than seats ]")
}
total_seats - total_students
};
Expand All @@ -95,7 +94,7 @@ fn main() {
let next_student = get_next_student(&mut students, &next_key);

hall.push(next_student)
.expect("tried to push student into full hall");
.expect("[ tried to push student into full hall ]");
placed_keys.insert(next_key.clone());
previously_placed_key = Some(next_key);
continue;
Expand All @@ -104,7 +103,7 @@ fn main() {
// run out of subjects and now must leave empty seats between students
if extra_seats > 0 {
hall.push_empty()
.expect("tried to push empty on full hall (error should never happer)");
.expect("[ tried to push empty on full hall (error should never happer) ]");
previously_placed_key = None;
extra_seats -= 1;
continue;
Expand Down Expand Up @@ -158,7 +157,7 @@ fn main() {
}
}

let conn = sqlite::open(args.output_db_path).expect("Error connecting to report.db");
let conn = sqlite::open(args.output_db_path).expect("[ Error connecting to report.db ]");
db::write_report_table(&conn, &halls);
log_sparse_halls(&halls);
}
Expand All @@ -167,11 +166,11 @@ fn main() {
fn get_next_student(students: &mut HashMap<String, Vec<Student>>, key: &str) -> Student {
let students_in_key = students
.get_mut(key)
.expect("trying to take a student from subject that doesn't exist");
.expect("[ trying to take a student from subject that doesn't exist ]");

let next_student = students_in_key
.pop()
.expect("trying to take student from empty subject list");
.expect("[ trying to take student from empty subject list ]");

if students_in_key.is_empty() {
students.remove(key);
Expand Down Expand Up @@ -218,24 +217,25 @@ pub fn log_sparse_halls(halls: &[Hall]) {
.create(true)
.append(true)
.open("logs\\logs.txt")
.expect("err opening log file");
.expect("[ err opening log file ]");
let mut sparse_hall_count = 0;
for hall in halls {
let num_students = hall.students().len();
if num_students > 0 && num_students < 20 {
sparse_hall_count += 1;
let content = format!("{}: {}, ", hall.name(), num_students);
file.write_all(content.as_bytes())
.expect("file write error");
.expect("[ file write error ]");
}
}
if sparse_hall_count == 0 {
let content = format!("No sparse halls :D");
file.write_all(content.as_bytes())
.expect("file write error")
.expect("[ file write error ]")
}

file.write_all("\n".as_bytes()).expect("file write error")
file.write_all("\n".as_bytes())
.expect("[ file write error ]")
}

#[cfg(not(debug_assertions))]
Expand Down
12 changes: 10 additions & 2 deletions allocator/src/student.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ pub struct Student {
impl Student {
pub fn new(id: String, subject: String) -> Self {
let id_clone = id.clone();
let (class, roll_no) = id_clone.split_once('-').expect("invalid id format");
let roll_no: i32 = roll_no.parse().expect("invalid roll number");
let (class, roll_no) = id_clone
.split_once('-')
.unwrap_or_else(|| panic!("[ invalid id format (id is {})]", id));
let roll_no: i32 = roll_no.parse().unwrap_or_else(|e| {
panic!(
"[ invalid roll number (id is {}) (error is {1:?}; {1})]",
id, e
)
});
// expect("[ invalid roll number ]");
let class = class.to_owned();
Self {
id,
Expand Down
2 changes: 1 addition & 1 deletion build_flutter_win.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
rmdir /s /q EHSA_V3\bin\data && del /q EHSA_V3\bin\ehsa_frontend.exe del /q EHSA_V3\bin\flutter_windows.dll del /q EHSA_V3\bin\url_launcher_windows_plugin.dll
cd ehsa_frontend && flutter build windows && cd ../ && move ehsa_frontend\build\windows\runner\Release\data EHSA_V3\bin && move ehsa_frontend\build\windows\runner\Release\ehsa_frontend.exe EHSA_V3\bin && move ehsa_frontend\build\windows\runner\Release\flutter_windows.dll EHSA_V3\bin && move ehsa_frontend\build\windows\runner\Release\url_launcher_windows_plugin.dll EHSA_V3\bin
cd ehsa_frontend && flutter build windows && cd ../ && move ehsa_frontend\build\windows\runner\Release\data EHSA_V3\bin && move ehsa_frontend\build\windows\runner\Release\ehsa_frontend.exe EHSA_V3\bin && move ehsa_frontend\build\windows\runner\Release\flutter_windows.dll EHSA_V3\bin && move ehsa_frontend\build\windows\runner\Release\url_launcher_windows_plugin.dll EHSA_V3\bin && move ehsa_frontend\build\windows\runner\Release\window_manager_plugin.dll EHSA_V3\bin && move ehsa_frontend\build\windows\runner\Release\screen_retriever_plugin.dll EHSA_V3\bin
4 changes: 3 additions & 1 deletion ehsa_frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
.history
.svn/
migrate_working_dir/

*.exe
*.txt
*.db
# IntelliJ related
*.iml
*.ipr
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed ehsa_frontend/input.db
Binary file not shown.
1 change: 1 addition & 0 deletions ehsa_frontend/ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
1 change: 1 addition & 0 deletions ehsa_frontend/ios/Flutter/Release.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
44 changes: 44 additions & 0 deletions ehsa_frontend/ios/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '11.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
inherit! :search_paths
end
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
25 changes: 25 additions & 0 deletions ehsa_frontend/lib/bloc/main_screen/main_screen_cubit.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:bloc/bloc.dart';
import 'package:ehsa_frontend/enums/page_type.dart';
import 'package:flutter/material.dart';

part 'main_screen_state.dart';

class MainScreenCubit extends Cubit<MainScreenInitial> {
MainScreenCubit()
: super(MainScreenInitial(
isOverlayOpen: true,
isDrawerOpen: false,
pagesection: Pages.HALLS));

void showOverlay(bool show) {
emit(state.copyWith(isOverlayOpen: show));
}

void openDrawer(bool open) {
emit(state.copyWith(isDrawerOpen: open));
}

void setPageSection(Pages pagesection) {
emit(state.copyWith(pagesection: pagesection));
}
}
25 changes: 25 additions & 0 deletions ehsa_frontend/lib/bloc/main_screen/main_screen_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
part of 'main_screen_cubit.dart';

@immutable
class MainScreenInitial {
bool isOverlayOpen;
bool isDrawerOpen;
Pages pagesection;

MainScreenInitial(
{required this.isOverlayOpen,
required this.isDrawerOpen,
required this.pagesection});

MainScreenInitial copyWith({
bool? isOverlayOpen,
bool? isDrawerOpen,
Pages? pagesection,
}) {
return MainScreenInitial(
isOverlayOpen: isOverlayOpen ?? this.isOverlayOpen,
isDrawerOpen: isDrawerOpen ?? this.isDrawerOpen,
pagesection: pagesection ?? this.pagesection,
);
}
}
Loading

0 comments on commit 050a01d

Please sign in to comment.