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

UI update #3

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
11134e6
Attempt to implement a custom function to update the constant from th…
lognece Jul 4, 2024
87afb5f
Fixed the update_constant in custom_backend to dynamically update the…
lognece Jul 4, 2024
3df97a9
- Custom backend function update_constant() now works as it should.
lognece Jul 8, 2024
0e6e97e
Changed the Repo format and made minor changes to the ui appearance
lognece Jul 14, 2024
6a4b41e
Changed the Repo format and made minor changes to the ui appearance (…
lognece Jul 14, 2024
19f22cc
Changed UI:
lognece Jul 16, 2024
f236ac3
Added description of the custom_download method to the README
lognece Jul 16, 2024
f3a3283
added screenshots
lognece Jul 16, 2024
25fbda9
added screenshots to the README
lognece Jul 16, 2024
7d5c36e
added side bar with subsets of modules and calculations of remaning c…
lognece Jul 22, 2024
6098eff
added responsive layout, progress bar
lognece Aug 27, 2024
e1ffffd
- added a new container with modules with checkboxes for the custom s…
lognece Aug 27, 2024
587ce2a
- ui_extra.lp has additional left panel for module preference
lognece Sep 7, 2024
690d753
updated cogsys _info.lp: added explanations
lognece Sep 7, 2024
8de699f
added modal to the module
lognece Oct 1, 2024
74f18f8
Changes sus
susuhahnml Oct 1, 2024
fd049bb
preference + modal improvement content
lognece Oct 8, 2024
076e884
Improved UI with preferences
susuhahnml Oct 8, 2024
f9c2dad
- separated huge ui file into parts: layout, menu bar, modals, module…
lognece Oct 9, 2024
2862fa9
Changes in the Modal
lognece Oct 9, 2024
290d7b9
Update ideas for UI and functions
susuhahnml Oct 9, 2024
d87a2d2
Small adjustments to the layout
lognece Oct 15, 2024
427e535
added exams
lognece Dec 3, 2024
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Created by pytest automatically.
*
29 changes: 10 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,18 @@ Clinguin UI for Study regulations

### Usage

#### cogsys.lp:
#### Code from ASPOCP_23:
```
clinguin client-server --domain-files new/instance/cogsys.lp new/encoding.lp --ui-files new/ui.lp -c n=4
```
#### cscbsc.lp:
```
clinguin client-server --domain-files new/instance/cscbsc.lp new/encoding.lp --ui-files new/ui.lp -c n=4
```
#### cscmsc.lp:
```
clinguin client-server --domain-files new/instance/cscmsc.lp new/encoding.lp --ui-files new/ui.lp -c n=4
```
#### dsmsc.lp:
```
clinguin client-server --domain-files new/instance/dsmsc.lp new/encoding.lp --ui-files new/ui.lp -c n=4
```
#### irsba.lp:
```
clinguin client-server --domain-files new/instance/irsba.lp new/encoding.lp --ui-files new/ui.lp -c n=4
clinguin client-server --domain-files instances/instance_ASPOCP_23.lp encodings/encoding_ASPOCP_23.lp --ui-files encodings/ui.lp --custom-classes custom_backend.py --backend CustomBackend -c n=3
```


## Custom Backend

### custom_download(file_name)

This function is specific to study regulation formatting. It allows users to download a study plan file with a specified name.


### Clinguin version
`Clinguin 1.0.16`
`Clinguin 1.0.32`
7 changes: 7 additions & 0 deletions TODOS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# ToDo List
- [ ] create a `set_constant()` in a `custom_backend` that would allow user to update the constant dynamically from the ui (for example to set the number of semesters)
- [x] all tests passed for the custom_backend
- [x] does set_constant work in the ui?
- [ ] ensure that the input is only integer

# Ideas
104 changes: 104 additions & 0 deletions custom_backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
from collections import defaultdict
import re
from clinguin.server.application.backends import ClingoBackend
from clingo import Control
from typing import Tuple, Any


class CustomBackend(ClingoBackend):
def __init__(self, args: Any):
# Parse and store constants
self.current_constants = {
name: value
for const in (args.const or [])
for name, value in [const.split("=")]
}
super().__init__(args)
# Add a method to generate constant facts for the domain state
self._add_domain_state_constructor("_ds_generate_constant_facts")

# ---------------------------------------------
# Setup
# ---------------------------------------------


def _init_ctl(self):
"""Initialize the Clingo control object with current constants and domain files."""
try:
# Create constant definitions and initialize Control
const_defs = [
f"-c {name}={value}" for name, value in self.current_constants.items()
]
self._ctl = Control(["0"] + const_defs)

# Load domain files and add atoms
for f in self._domain_files:
self._ctl.load(str(f))
for atom in self._atoms:
self._ctl.add("base", [], str(atom) + ".")

# Ground the program
self._ctl.ground([("base", [])])
except Exception as e:
self._logger.error(f"Error initializing clingo.Control: {e}")
raise

# ---------------------------------------------
# Public methods
# ---------------------------------------------

def custom_download(self, file_name="study_plan.lp"):
"""
Custom download function to save the solution in a more user-friendly format,
showing only assignments related to semesters and formatting them.
"""
if self._model is None:
raise RuntimeError("Can't download when there is no model")

# Filter the model to include only semester assignments
semester_assignments = [
f"{str(atom)}."
for atom in self._model
if re.match(r"in\(\w+,s\(\d+\)\)", str(atom))
]

# Format the StudyPlan
semesters = defaultdict(list)
for line in semester_assignments:
match = re.match(r"in\((\w+),s\((\d+)\)\)\.", line.strip())
if match:
module, semester = match.groups()
semesters[int(semester)].append(module)

formatted_output = ""
for semester in sorted(semesters.keys()):
formatted_output += f"Semester {semester}:\n"
for module in semesters[semester]:
formatted_output += f"{module}\n"
formatted_output += "\n"

# Write the formatted output to the file
file_name = file_name.strip('"')
with open(file_name, "w", encoding="UTF-8") as file:
file.write(formatted_output)

self._messages.append(
(
"Download successful",
f"Information saved in file {file_name}.",
"success",
)
)

# ---------------------------------------------
# Properties
# ---------------------------------------------

@property
def _ds_generate_constant_facts(self) -> str:
"""Generate facts for current constants."""
facts = [
f"_clinguin_const({name},{value})."
for name, value in self.current_constants.items()
]
return "#defined _clinguin_const/2." + " ".join(facts) + "\n"
File renamed without changes.
Loading