Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

New_Structure effort. #36

Merged
merged 24 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4d66e1b
Add ClassSchedule Class
guilherme-ds-matos Oct 28, 2023
e06ef6e
Adding the structure of Student and introducing the OperationResult enum
guilherme-ds-matos Oct 28, 2023
607593e
Name changes and rebased with main
jvdcf Oct 29, 2023
3040d7c
Making sure classes are on the same day to compare thir time
guilherme-ds-matos Oct 29, 2023
31889fa
Renaming the classes themselves
guilherme-ds-matos Oct 29, 2023
3147c5a
Merge conflit resolved
jvdcf Oct 29, 2023
d96027f
main.cpp fixed
jvdcf Oct 29, 2023
5642c1d
First try to implement constructor (with errors)
jvdcf Oct 30, 2023
6fffab9
Student.ad_to_class() alterado
DuarteSAssuncao Oct 30, 2023
3016daa
Fixing remove, fixing binary_search, fixing Runtime()
guilherme-ds-matos Oct 30, 2023
2390d38
Merge remote-tracking branch 'refs/remotes/origin/new_structure' into…
guilherme-ds-matos Oct 30, 2023
9410f8d
Student::verify_add()
jvdcf Oct 30, 2023
8477d86
Duarte suggestion
jvdcf Oct 30, 2023
b5a11f7
Duarte suggestion
jvdcf Oct 30, 2023
139b56e
Merge remote-tracking branch 'origin/new_structure' into new_structure
jvdcf Oct 30, 2023
257dd1f
Switch and remove classes from student
jvdcf Oct 30, 2023
83f25a8
Multiple Changes
guilherme-ds-matos Oct 30, 2023
5bd264d
Fixing some bugs
guilherme-ds-matos Oct 30, 2023
26742b3
Repl can now execute print (single student), remove, and can quit
guilherme-ds-matos Oct 30, 2023
a170387
Update Doxyfile
jvdcf Oct 31, 2023
9eb8cee
Enhancing the user experience
guilherme-ds-matos Oct 31, 2023
cac155d
Documentation for the first 4 classes
jvdcf Nov 1, 2023
4936c46
Merge remote-tracking branch 'origin/new_structure' into new_structure
jvdcf Nov 1, 2023
5e47788
Help modified.
DuarteSAssuncao Nov 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ endif(DOXYGEN_FOUND)

# Project build
add_executable(AED2324_PRJ1_G23 main.cpp
src/appClasses.cpp src/appClasses.hpp
src/appClassesPerUC.cpp src/appClassesPerUC.hpp
src/appStudentsClasses.cpp src/appStudentsClasses.hpp
src/classes.cpp src/classes.hpp
src/classesPerUC.cpp src/classesPerUC.hpp
src/studentsClasses.cpp src/studentsClasses.hpp
src/Utils.cpp src/Utils.hpp)
src/CSVClasses.cpp src/CSVClasses.hpp
src/CSVClassesPerUC.cpp src/CSVClassesPerUC.hpp
src/CSVStudentsClasses.cpp src/CSVStudentsClasses.hpp
src/Lesson.cpp src/Lesson.hpp
src/ClassesPerUC.cpp src/ClassesPerUC.hpp
src/StudentsClasses.cpp src/StudentsClasses.hpp
src/Utils.cpp src/Utils.hpp
src/Runtime.cpp src/Runtime.hpp
src/ClassSchedule.cpp src/ClassSchedule.hpp
src/Student.cpp src/Student.hpp
src/Process.cpp src/Process.hpp)
2 changes: 1 addition & 1 deletion docs/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ WARN_LOGFILE =
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
# Note: If this tag is empty the current directory is searched.

INPUT = ../src ../main.cpp ../docs/docs.md
INPUT = @PROJECT_SOURCE_DIR@/src @PROJECT_SOURCE_DIR@/main.cpp @PROJECT_SOURCE_DIR@/docs/docs.md

# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
Expand Down
37 changes: 20 additions & 17 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,30 @@
* @file main.cpp
* @brief Point of entry of the program.
*/

#include "src/appClasses.hpp"
#include "src/appClassesPerUC.hpp"
#include "src/appStudentsClasses.hpp"
#include "src/classes.hpp"
#include "src/classesPerUC.hpp"
#include "src/studentsClasses.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include "src/CSVClasses.hpp"
#include "src/CSVClassesPerUC.hpp"
#include "src/CSVStudentsClasses.hpp"
#include "src/ClassesPerUC.hpp"
#include "src/StudentsClasses.hpp"
#include "src/Lesson.hpp"
#include "src/ClassSchedule.hpp"
#include "src/Student.hpp"
#include "src/Runtime.hpp"
#include "src/Utils.hpp"

int main(int argc, char** argv) {
AppClassPerUC cpu = AppClassPerUC("schedule/classes_per_uc.csv");
cpu.display();
CSVClassPerUC cpu("schedule/classes_per_uc.csv");
//cpu.display();

CSVStudentsClasses sc("schedule/students_classes.csv");
//sc.display();

AppStudentsClasses sc("schedule/students_classes.csv");
sc.display();
CSVClasses ac("schedule/classes.csv");
//ac.display();

AppClass ac("schedule/classes.csv");
ac.display();
Runtime rt(sc, cpu, ac);

rt.run();

return 0;
}
85 changes: 59 additions & 26 deletions src/appClasses.cpp → src/CSVClasses.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#include "appClasses.hpp"
/**
* @file CSVClasses.cpp
*/
#include "CSVClasses.hpp"
#include "Utils.hpp"
#include "classes.hpp"
#include "Lesson.hpp"
#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>

/**
* @file appClasses.cpp
*/

/**
* This constructor receives a string containing all the lines of a csv file and creates the AppClass from it.
* @brief This constructor receives a string containing all the lines of a csv file and creates the AppClass from it.
* @param csv
*/
AppClass::AppClass(const std::string& csv) {
CSVClasses::CSVClasses(const std::string& csv) {
// CSV file into memory
std::ifstream file = std::ifstream(csv);
std::string contents;
Expand All @@ -25,7 +25,7 @@ AppClass::AppClass(const std::string& csv) {
// Parse string
std::stringstream s(contents);
std::string line;
this->entries = std::vector<Class>();
this->entries = std::vector<Lesson>();
getline(s, line, '\n');
std::vector<std::string> bufs;
parse_csv_line(line, bufs);
Expand All @@ -37,19 +37,19 @@ AppClass::AppClass(const std::string& csv) {
this->type_cath_name = bufs[5];
line.clear();
while (std::getline(s, line, '\n')) {
this->entries.push_back(Class(line));
this->entries.push_back(Lesson(line));
}
}

/**
* Erases the contents of classes.csv and saves there the updated values.
* @brief Erases the contents of classes.csv and saves there the updated values.
*/
AppClass::~AppClass() {
CSVClasses::~CSVClasses() {
std::ofstream ofs;
ofs.open("../schedule/classes.csv", std::ofstream::out | std::ofstream::trunc);
ofs << class_cath_name << ',' << uc_cath_name << ',' << weekday_cath_name << ',' << start_hour_cath_name
<< ',' << duration_cath_name << ',' << type_cath_name << '\n';
for (Class entry: entries) {
for (Lesson entry: entries) {
std::string value;
entry.class_to_str(value);
ofs << value << ',';
Expand All @@ -65,7 +65,10 @@ AppClass::~AppClass() {
ofs.close();
}

void AppClass::display() {
/**
* @brief Displays the contents of the class.
*/
void CSVClasses::display() {
std::cout << this->uc_cath_name << ',' << this->class_cath_name << ','
<< this->weekday_cath_name << ',' << this->start_hour_cath_name
<< ',' << this->duration_cath_name << ',' << this->type_cath_name
Expand All @@ -75,52 +78,69 @@ void AppClass::display() {
}
}

void AppClass::sort_by(std::string category) {
/**
* @brief Sorts the entries by the category passed as parameter.
* @details Available categories: id, ClassCode, UcCode, Weekday, StartHour, Duration, Type.
* Theoretical Complexity: O(n log n), n being the number of lines in the csv file.
* @param category
*/
void CSVClasses::sort_by(std::string category) {
if (category == uc_cath_name) {
std::stable_sort(this->entries.begin(), this->entries.end(),
[](const Class &first, const Class &second) {
[](const Lesson &first, const Lesson &second) {
std::string first_uc, second_uc;
first.uc_to_str(first_uc);
second.uc_to_str(second_uc);
return first_uc < second_uc;
});
} else if (category == class_cath_name) {
std::stable_sort(this->entries.begin(), this->entries.end(),
[](const Class &first, const Class &second) {
[](const Lesson &first, const Lesson &second) {
return first.get_class_code() < second.get_class_code();
});
} else if (category == weekday_cath_name) {
std::stable_sort(this->entries.begin(), this->entries.end(),
[](const Class &first, const Class &second) {
[](const Lesson &first, const Lesson &second) {
return first.get_day() < second.get_day();
});
} else if (category == start_hour_cath_name) {
std::stable_sort(this->entries.begin(), this->entries.end(),
[](const Class &first, const Class &second) {
[](const Lesson &first, const Lesson &second) {
return first.get_start_hour() < second.get_start_hour();
});
} else if (category == duration_cath_name) {
std::stable_sort(this->entries.begin(), this->entries.end(),
[](const Class &first, const Class &second) {
[](const Lesson &first, const Lesson &second) {
return first.get_duration() < second.get_duration();
});
} else if (category == type_cath_name) {
std::stable_sort(this->entries.begin(), this->entries.end(),
[](const Class &first, const Class &second) {
return first.get_type() < second.get_type();
[](const Lesson &first, const Lesson &second) {
return first.get_type() < second.get_type();
});
} else if (category == "id") {
std::stable_sort(this->entries.begin(), this->entries.end(),
[](const Lesson &first, const Lesson &second) {
return first.get_id() < second.get_id();
});
} else {
std::cerr << "Error: invalid category" << '\n';
std::exit(1);
}
}

std::vector<Class>::iterator AppClass::search_by_uc(
/**
* @deprecated
* @brief Search the lines for the first class with the given uc_code.
* @param uc_code
* @return Iterator to the first class with the given uc_code. If not found, returns a past-the-end pointer.
*/
std::vector<Lesson>::iterator CSVClasses::search_by_uc(
uint16_t
uc_code) { // Sorts the entries by UC and returns the iterator of the
// first found. If not found, returns a past-the-end pointer
sort_by(uc_cath_name);
std::vector<Class>::iterator ret = entries.end();
std::vector<Lesson>::iterator ret = entries.end();
size_t mid = entries.size() / 2;
while (true) { // Binary search
if (mid == entries.size()) {
Expand All @@ -145,14 +165,21 @@ std::vector<Class>::iterator AppClass::search_by_uc(
return ret;
}

std::vector<Class>::iterator AppClass::search_by_class(uint16_t class_code) {
/**
* @deprecated
* @brief Search the lines for the first class with the given class_code.
* @param uc_code
* @param class_code
* @return Iterator to the first class with the given class_code. If not found, returns a past-the-end pointer.
*/
std::vector<Lesson>::iterator CSVClasses::search_by_class(uint16_t uc_code, uint16_t class_code) {
sort_by(class_cath_name);
std::vector<Class>::iterator ret = entries.end();
std::vector<Lesson>::iterator ret = entries.end();
size_t mid = entries.size() / 2;
while (true) { // Binary search
if (mid == entries.size()) {
return ret;
} else if (entries[mid].get_class_code() == class_code) {
} else if (entries[mid].get_uc_code() == uc_code && entries[mid].get_class_code() == class_code) {
ret = entries.begin() + mid;
break;
} else if (entries[mid].get_class_code() > class_code) {
Expand All @@ -171,3 +198,9 @@ std::vector<Class>::iterator AppClass::search_by_class(uint16_t class_code) {
}
return ret;
}

/**
* @brief Getter for the vector of Lessons
* @return Pointer to lessons.
*/
std::vector<Lesson> *CSVClasses::get_lessons() {return &this->entries;}
35 changes: 35 additions & 0 deletions src/CSVClasses.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @file CSVClasses.hpp
*/
#ifndef APPCLASSES_H
#define APPCLASSES_H
#include "Lesson.hpp"
#include <string>
#include <vector>

/**
* @brief Class representation of the file classes.csv
*/
class CSVClasses {
private:
std::string class_cath_name;
std::string uc_cath_name;
std::string weekday_cath_name;
std::string start_hour_cath_name;
std::string duration_cath_name;
std::string type_cath_name;
/// Vector with every line of the file
std::vector<Lesson> entries;

public:
CSVClasses(const std::string& csv);
~CSVClasses();
std::vector<Lesson>* get_lessons();
void display();
void sort_by(std::string category);
std::vector<Lesson>::iterator search_by_uc(uint16_t uc_code);
std::vector<Lesson>::iterator search_by_class(uint16_t uc_code, uint16_t class_code);
};


#endif // APPCLASSES_H
Loading