Skip to content

Commit

Permalink
Merge pull request #24 from cics-syslab/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
calvinchai authored Feb 7, 2024
2 parents 23cd5da + 09c41b7 commit 077907a
Show file tree
Hide file tree
Showing 16 changed files with 187 additions and 227 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ scratch/
# Ignore dynamic pages
webui/pages/1_*.py
webui/pages/2_*.py
webui/pages/scratch.py

docs/
.git/
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
**.pyc


venv/
output/
logs/
settings/
Expand All @@ -16,4 +15,5 @@ scratch/
# Ignore dynamic pages
webui/pages/1_*.py
webui/pages/2_*.py
webui/pages/scratch.py

4 changes: 4 additions & 0 deletions .streamlit/config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[logger]

level = "debug"

[runner]
fastReruns = false
Expand All @@ -6,3 +9,4 @@ magicEnabled = false

[server]
enableCORS = false
folderWatchBlacklist = ['logs','.git']
14 changes: 7 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
FROM ubuntu:22.04
LABEL authors="calvinchai"

COPY ./ /app

WORKDIR /app

VOLUME /app/settings

COPY ./requirements.txt /app/requirements.txt
RUN apt update
RUN apt install python3-all python3-pip -y
COPY static/GRADESCOPE_TEMPLATE/source/setup.sh /setup.sh
RUN /bin/bash -c "apt-get install -y build-essential libgtest-dev cmake && cd /usr/src/gtest && cmake CMakeLists.txt && make"
RUN pip install -r requirements.txt
RUN chmod +x /app/run.sh

COPY ./ /app
VOLUME /app/settings

RUN python3 main.py --setup

RUN chmod +x /app/run.sh
ENTRYPOINT ["/app/run.sh"]
Empty file removed dev.py
Empty file.
4 changes: 2 additions & 2 deletions magi/_private/base_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
class BaseSettings:
project_name: str = ""
project_description: str = field(default_factory=str, metadata={"text_area": True})
strict_file_checking: bool = field(default=True, metadata={"help": "When enabled, student not submitting all required files will not be graded."})
allow_all_file: bool = field(default=False, metadata={"help": "Allow all files to be uploaded, when disabled, only files in the submission_files list will be allowed."})
strict_file_checking: bool = field(default=False, metadata={"help": "When enabled, student not submitting all required files will not be graded."})
allow_all_file: bool = field(default=True, metadata={"help": "Allow all files to be uploaded, when disabled, only files in the submission_files list will be allowed."})
submission_files: List[str] = field(default_factory=list)
output_dir: str = field(default_factory=lambda: "output", metadata={"excluded_from_ui": True})
enabled_module: str = field(default_factory=str, metadata={"excluded_from_ui": True})
Expand Down
3 changes: 2 additions & 1 deletion magi/components/grader.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def grade_submission():
from magi.managers import SettingManager
from magi.managers.info_manager import Directories
from magi.managers import AddonManager, TestManager

TestManager.reset()

submission_files = SettingManager.BaseSettings.submission_files
submission_dir = Directories.SUBMISSION_DIR
os.makedirs(Directories.WORK_DIR, exist_ok=True)
Expand Down
11 changes: 10 additions & 1 deletion magi/managers/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@
test_cases_by_name = {}
anonymous_counter: int = 0


def reset():
global score, execution_time, output, extra_data, test_cases, test_cases_by_name, anonymous_counter
score = 0
execution_time = 0
output = ""
extra_data = {}
test_cases = []
test_cases_by_name = {}
anonymous_counter = 0

def output_global_message(msg: str):
global output
output += "\n" + msg
Expand Down
48 changes: 21 additions & 27 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
import argparse
import logging
import time
from logging import handlers


# GUI will only be started for development purposes
def start_gui():
from gui.app import start_app
start_app()

from pathlib import Path

def setup():
pass
required_dirs = ['logs', 'workdir', 'settings', 'modules', 'plugins']
app_path = Path(__file__).resolve().parent
for d in required_dirs:
if not app_path.joinpath(d).exists():
app_path.joinpath(d).mkdir()


def main():
log_format = '%(asctime)s - %(name)s - %(levelname)s: %(message)s - %(pathname)s[line:%(lineno)d]'
logging.basicConfig(format=log_format, level=logging.DEBUG)
# TODO: log file path should be configured
th = handlers.TimedRotatingFileHandler(filename=f"logs/log-{time.strftime('%m%d%H%M')}.txt", encoding='utf-8')
formatter = logging.Formatter(log_format)
th.setFormatter(formatter)
logging.getLogger().addHandler(th)


parser = argparse.ArgumentParser()
parser.add_argument("-s", "--setup", action="store_true")
Expand All @@ -32,17 +21,22 @@ def main():

if args.setup:
setup()
elif args.test:
pass
elif args.autograder:
return
import logging
from logging import handlers
import time

log_format = '%(asctime)s - %(name)s - %(levelname)s: %(message)s - %(pathname)s[line:%(lineno)d]'
logging.basicConfig(format=log_format, level=logging.DEBUG)
# TODO: log file path should be configured
th = handlers.TimedRotatingFileHandler(filename=f"logs/log-{time.strftime('%m%d%H%M')}.txt", encoding='utf-8')
formatter = logging.Formatter(log_format)
th.setFormatter(formatter)
logging.getLogger().addHandler(th)

if args.autograder:
from magi.components.grader import grade_submission
grade_submission()
elif args.mock:
pass
else:
start_gui()
from magi.managers import SettingManager
SettingManager.save_settings()


if __name__ == '__main__':
Expand Down
40 changes: 8 additions & 32 deletions mock/autograder/results/results.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,44 @@
"stdout_visibility": "hidden",
"extra_data": {},
"tests": [
{
"score": 10,
"max_score": 10,
"visibility": "visible",
"output": "Successfully connected",
"name": "Test case 0",
"status": ""
},
{
"score": 10,
"max_score": 10,
"visibility": "visible",
"output": "Test Case: 612 + 504 ...... SUCCESS",
"name": "Test case 1",
"status": ""
},
{
"score": 10,
"max_score": 10,
"visibility": "visible",
"output": "Reached end of tests",
"name": "Test case 2",
"status": ""
},
{
"score": 30,
"max_score": 30,
"visibility": "visible",
"output": "Successfully connected",
"name": "Test case 3",
"name": "Test case 0",
"status": ""
},
{
"score": 3,
"max_score": 3,
"visibility": "visible",
"output": "Test Case: 205 + 339 ...... SUCCESS",
"name": "Test case 4",
"output": "Test Case: 500 + 846 ...... SUCCESS",
"name": "Test case 1",
"status": ""
},
{
"score": 3,
"max_score": 3,
"visibility": "visible",
"output": "Test Case: 744 - 322 ...... SUCCESS",
"name": "Test case 5",
"output": "Test Case: 106 + 574 ...... SUCCESS",
"name": "Test case 2",
"status": ""
},
{
"score": 3,
"max_score": 3,
"visibility": "visible",
"output": "Test Case: 567 - 842 ...... SUCCESS",
"name": "Test case 6",
"output": "Test Case: 356 * 463 ...... SUCCESS",
"name": "Test case 3",
"status": ""
},
{
"score": 30,
"max_score": 30,
"visibility": "visible",
"output": "Reached end of tests",
"name": "Test case 7",
"name": "Test case 4",
"status": ""
}
],
Expand Down
7 changes: 0 additions & 7 deletions scratch.py

This file was deleted.

Empty file removed setup.py
Empty file.
3 changes: 0 additions & 3 deletions test_autograder.py

This file was deleted.

6 changes: 4 additions & 2 deletions webui/functions/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@



def init_session():
def init_session(preview_page=False):
st.set_page_config(layout="wide")
if "update_addon_lock" not in session_state:
session_state.update_addon_lock = threading.Lock()
Expand All @@ -25,7 +25,9 @@ def init_session():
session_state["InfoManager"] = InfoManager

# print(session_state["AddonManager"]._name_to_modules["ClientServerSocket"].loaded)

if not preview_page:
session_state["output_generated"] = False

update_pages()
session_state["SettingManager"].save_settings()
st.markdown(
Expand Down
Loading

0 comments on commit 077907a

Please sign in to comment.