Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies #7

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ A research on creation of metaheuristic university class timetable scheduling so

### Installation:
1. Clone repository.
3. Ensure all dependencies are installed.
3. Run `pip install -r requirements.txt`
2. Run `python main.py` on project directory.

### Usage:
Expand All @@ -16,7 +16,7 @@ A research on creation of metaheuristic university class timetable scheduling so

### Dependencies:
1. Numpy
2. PyQT5
2. PyQt6
3. psutil

### Educational Documentation
Expand Down
611 changes: 396 additions & 215 deletions components/GeneticAlgorithm.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion components/ImportExportHandler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from PyQt5 import QtWidgets
from PyQt6 import QtWidgets
from components import Database as db
import csv

Expand Down
50 changes: 28 additions & 22 deletions components/ScheduleParser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt6 import QtCore, QtWidgets, QtGui
from components import Settings, TableModel, Utilities
import json

Expand All @@ -12,38 +12,44 @@ class ScheduleParser:
# table = QTableView, data = []
def __init__(self, table, data):
self.table = table
header = [['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']]
with open('timeslots.json') as json_file:
self.timeslots = timeslots = json.load(json_file)['timeslots']
header = [["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]]
with open("timeslots.json") as json_file:
self.timeslots = timeslots = json.load(json_file)["timeslots"]
self.settings = settings = Settings.getSettings()
header.append(timeslots[settings['starting_time']:settings['ending_time'] + 1])
header.append(
timeslots[settings["starting_time"] : settings["ending_time"] + 1]
)
temporaryData = []
for i in range(settings['ending_time'] + 1 - settings['starting_time']):
temporaryData.append(['', '', '', '', '', ''])
for i in range(settings["ending_time"] + 1 - settings["starting_time"]):
temporaryData.append(["", "", "", "", "", ""])
self.model = ScheduleParserModel(header, temporaryData)
table.setModel(self.model)
table.setFocusPolicy(QtCore.Qt.NoFocus)
table.setSelectionMode(QtWidgets.QAbstractItemView.NoSelection)
# table.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.Fixed)
table.verticalHeader().setSectionResizeMode(QtWidgets.QHeaderView.Fixed)
table.setFocusPolicy(QtCore.Qt.FocusPolicy.NoFocus)
table.setSelectionMode(QtWidgets.QAbstractItemView.SelectionMode.NoSelection)
# table.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.ResizeMode.Fixed)
table.verticalHeader().setSectionResizeMode(
QtWidgets.QHeaderView.ResizeMode.Fixed
)
self.parseData(data)

# data = [{'color': None, 'text': '', 'instances': [[day, startingTS, endingTS]]}]
def parseData(self, data):
view = self.table
model = self.model
for entry in data:
entry['color'] = Utilities.colorGenerator()
for instance in entry['instances']:
entry["color"] = Utilities.colorGenerator()
for instance in entry["instances"]:
index = model.index(instance[1], instance[0])
view.setSpan(instance[1], instance[0], instance[2] - instance[1], 1)
item = QtGui.QStandardItem(entry['text'])
item.setBackground(QtGui.QBrush(QtGui.QColor(*entry['color'])))
item.setForeground(QtGui.QBrush(QtGui.QColor(*Utilities.textColor(entry['color']))))
item = QtGui.QStandardItem(entry["text"])
item.setBackground(QtGui.QBrush(QtGui.QColor(*entry["color"])))
item.setForeground(
QtGui.QBrush(QtGui.QColor(*Utilities.textColor(entry["color"])))
)
model.setData(index, item)

def subjectGenerator(self):
print(self.settings['starting_time'])
print(self.settings["starting_time"])


class ScheduleParserModel(TableModel.TableModel):
Expand All @@ -61,12 +67,12 @@ def setData(self, index, value, role=None):
def data(self, index, role):
if not index.isValid() or not self.data[index.row()][index.column()]:
return QtCore.QVariant()
elif role == QtCore.Qt.TextAlignmentRole:
return QtCore.Qt.AlignCenter
elif role == QtCore.Qt.BackgroundRole:
elif role == QtCore.Qt.ItemDataRole.TextAlignmentRole:
return QtCore.Qt.AlignmentFlag.AlignCenter
elif role == QtCore.Qt.ItemDataRole.BackgroundRole:
return self.data[index.row()][index.column()].background()
elif role == QtCore.Qt.ForegroundRole:
elif role == QtCore.Qt.ItemDataRole.ForegroundRole:
return self.data[index.row()][index.column()].foreground()
elif role != QtCore.Qt.DisplayRole:
elif role != QtCore.Qt.ItemDataRole.DisplayRole:
return QtCore.QVariant()
return self.data[index.row()][index.column()].text()
14 changes: 10 additions & 4 deletions components/TableModel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from PyQt5 import QtCore
from PyQt6 import QtCore


# Standard table model requires 2D header and complete dataset
Expand All @@ -11,7 +11,7 @@ def __init__(self, header, data):
def data(self, index, role):
if not index.isValid():
return QtCore.QVariant()
elif role != QtCore.Qt.DisplayRole:
elif role != QtCore.Qt.ItemDataRole.DisplayRole:
return QtCore.QVariant()
return self.data[index.row()][index.column()]

Expand All @@ -22,9 +22,15 @@ def columnCount(self, parent=None, *args, **kwargs):
return len(self.data[0])

def headerData(self, p_int, Qt_Orientation, role=None):
if Qt_Orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
if (
Qt_Orientation == QtCore.Qt.Orientation.Horizontal
and role == QtCore.Qt.ItemDataRole.DisplayRole
):
return QtCore.QVariant(self.header[0][p_int])
elif Qt_Orientation == QtCore.Qt.Vertical and role == QtCore.Qt.DisplayRole:
elif (
Qt_Orientation == QtCore.Qt.Orientation.Vertical
and role == QtCore.Qt.ItemDataRole.DisplayRole
):
return QtCore.QVariant(self.header[1][p_int])
return QtCore.QVariant()

Expand Down
68 changes: 50 additions & 18 deletions components/Timetable.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt6 import QtCore, QtWidgets, QtGui
from components import Settings, TableModel
import json

Expand All @@ -7,20 +7,35 @@
class Timetable:
def __init__(self, table, data=False):
self.table = table
header = [['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']]
with open('timeslots.json') as json_file:
timeslots = json.load(json_file)['timeslots']
header = [["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]]
with open("timeslots.json") as json_file:
timeslots = json.load(json_file)["timeslots"]
settings = Settings.getSettings()
header.append(timeslots[settings['starting_time']:settings['ending_time'] + 1])
header.append(
timeslots[settings["starting_time"] : settings["ending_time"] + 1]
)
self.data = data
if not data:
self.data = []
for i in range(settings['ending_time'] + 1 - settings['starting_time']):
self.data.append(['Available', 'Available', 'Available', 'Available', 'Available', 'Available'])
for i in range(settings["ending_time"] + 1 - settings["starting_time"]):
self.data.append(
[
"Available",
"Available",
"Available",
"Available",
"Available",
"Available",
]
)
self.model = TimetableModel(header, self.data)
table.setModel(self.model)
table.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.Fixed)
table.verticalHeader().setSectionResizeMode(QtWidgets.QHeaderView.Fixed)
table.horizontalHeader().setSectionResizeMode(
QtWidgets.QHeaderView.ResizeMode.Fixed
)
table.verticalHeader().setSectionResizeMode(
QtWidgets.QHeaderView.ResizeMode.Fixed
)
table.clicked.connect(self.toggleCells)
table.horizontalHeader().sectionClicked.connect(self.toggleCells)
table.verticalHeader().sectionClicked.connect(self.toggleCells)
Expand All @@ -30,11 +45,19 @@ def __init__(self, table, data=False):
def toggleCells(self):
indexes = self.table.selectionModel().selectedIndexes()
for i in indexes:
value = 'Available' if self.data[i.row()][i.column()] == 'Unavailable' else 'Unavailable'
if value == 'Available':
self.table.setStyleSheet('selection-background-color: rgb(46, 204, 113); selection-color: black;')
value = (
"Available"
if self.data[i.row()][i.column()] == "Unavailable"
else "Unavailable"
)
if value == "Available":
self.table.setStyleSheet(
"selection-background-color: rgb(46, 204, 113); selection-color: black;"
)
else:
self.table.setStyleSheet('selection-background-color: rgb(231, 76, 60); selection-color: black;')
self.table.setStyleSheet(
"selection-background-color: rgb(231, 76, 60); selection-color: black;"
)
self.model.setData(i, value)

def getData(self):
Expand All @@ -49,19 +72,28 @@ def __init__(self, header, data):
def data(self, index, role):
if not index.isValid():
return QtCore.QVariant()
elif role == QtCore.Qt.BackgroundRole:
if self.data[index.row()][index.column()] == 'Available':
elif role == QtCore.Qt.ItemDataRole.BackgroundRole:
if self.data[index.row()][index.column()] == "Available":
return QtGui.QBrush(QtGui.QColor(46, 204, 113))
else:
return QtGui.QBrush(QtGui.QColor(231, 76, 60))
elif role != QtCore.Qt.DisplayRole:
elif role != QtCore.Qt.ItemDataRole.DisplayRole:
return QtCore.QVariant()
return self.data[index.row()][index.column()]


def generateRawTable():
settings = Settings.getSettings()
data = []
for i in range(settings['ending_time'] + 1 - settings['starting_time']):
data.append(['Available', 'Available', 'Available', 'Available', 'Available', 'Available'])
for i in range(settings["ending_time"] + 1 - settings["starting_time"]):
data.append(
[
"Available",
"Available",
"Available",
"Available",
"Available",
"Available",
]
)
return data
Binary file removed components/__pycache__/Database.cpython-35.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed components/__pycache__/ResourceTracker.cpython-35.pyc
Binary file not shown.
Binary file not shown.
Binary file removed components/__pycache__/ScheduleParser.cpython-35.pyc
Binary file not shown.
Binary file removed components/__pycache__/Settings.cpython-35.pyc
Binary file not shown.
Binary file removed components/__pycache__/TableModel.cpython-35.pyc
Binary file not shown.
Binary file removed components/__pycache__/Timetable.cpython-35.pyc
Binary file not shown.
Binary file removed components/__pycache__/Utilities.cpython-35.pyc
Binary file not shown.
Loading