-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from Senior-Capstone-2024/gandalf
Gandalf
- Loading branch information
Showing
8 changed files
with
269 additions
and
80 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,87 @@ | ||
""" | ||
Call with "python3 report_generator/main.py path/to/json" | ||
""" | ||
|
||
''' | ||
call with "python3 report_generator/main.py path/to/json" | ||
''' | ||
from dotenv import load_dotenv | ||
from pylatex import Document, Section, NewPage | ||
from pylatex.utils import NoEscape | ||
from pylatex import Document, Section, LineBreak, NewPage, PageStyle, Package | ||
from pylatex.base_classes import Environment | ||
from pylatex.utils import bold, NoEscape | ||
import os | ||
from os import path | ||
import sys | ||
import json | ||
|
||
from util.parse_json import json_to_dict | ||
|
||
error_links = { | ||
'Improper Capitalized Primitive Type': 'https://www.oracle.com/java/technologies/javase/codeconventions-namingconventions.html', | ||
'Improper Method Name': 'https://www.oracle.com/java/technologies/javase/codeconventions-namingconventions.html', | ||
'Too many statements on this line, revise': 'https://www.oracle.com/java/technologies/javase/codeconventions-declarations.html', | ||
'Improper Class Or Interface': 'https://www.oracle.com/java/technologies/javase/codeconventions-namingconventions.html' | ||
} | ||
|
||
class syntax_code(Environment): | ||
_latex_name = 'minted' | ||
#packages = [Package('minted')] | ||
start_arguments = 'java' | ||
escape = False | ||
content_separator = '\n' | ||
def __init__(self, *, options=None, arguments=None, start_arguments=start_arguments, **kwargs): | ||
super().__init__(options=options, arguments=arguments, start_arguments=start_arguments, **kwargs) | ||
|
||
class syntax_code(Environment): | ||
_latex_name = 'minted' | ||
#packages = [Package('minted')] | ||
start_arguments = 'java' | ||
escape = False | ||
content_separator = '\n' | ||
def __init__(self, *, options=None, arguments=None, start_arguments=start_arguments, **kwargs): | ||
super().__init__(options=options, arguments=arguments, start_arguments=start_arguments, **kwargs) | ||
|
||
def format_doc(): | ||
geometry_options = { | ||
'margin': '0.5in' | ||
} | ||
|
||
doc = Document(geometry_options=geometry_options) | ||
doc.change_document_style('empty') | ||
return doc | ||
|
||
geometry_options = { | ||
'margin': '0.5in' | ||
} | ||
|
||
doc = Document(geometry_options=geometry_options) | ||
doc.change_document_style('empty') | ||
doc.packages.append(Package(name='minted')) | ||
doc.packages.append(Package(name='setspace')) | ||
doc.preamble.append(NoEscape(r'\SetSinglespace{1.1}')) | ||
doc.preamble.append(NoEscape(r'\singlespacing')) | ||
return doc | ||
|
||
def assemble_pdf(json_file_path: str, assignment_path: str, out_dir: str='./out/out'): | ||
assignment = open(assignment_path).read().splitlines() | ||
|
||
def assemble_pdf(json_file_path: str): | ||
with open(json_file_path, 'r') as f: | ||
data = json.load(f) | ||
# Load JSON data from file | ||
with open(json_file_path, 'r') as f: | ||
data = json.load(f) | ||
|
||
data: dict | ||
# load path to pdflatex | ||
dotenv_path = path.join(path.dirname(__file__), '.env') | ||
load_dotenv(dotenv_path) | ||
PDFLATEX_PATH = os.environ.get('PDFLATEX_PATH') | ||
|
||
# load path to pdflatex | ||
dotenv_path = path.join(path.dirname(__file__), '.env') | ||
load_dotenv(dotenv_path) | ||
PDFLATEX_PATH = os.environ.get('PDFLATEX_PATH') | ||
|
||
doc = format_doc() | ||
|
||
keys = list(data.keys()) | ||
with doc.create(Section(NoEscape(r'\centerline{' "Student A" + '}'), numbering=False)): | ||
doc.append(NoEscape(r'\centerline{/src/file.java} \n')) | ||
doc.append('\n') | ||
doc.append('\n\n') | ||
|
||
for key in keys: | ||
doc.append(NoEscape(f"Line: {key}")) | ||
doc.append('\n') | ||
if data[key] is not None: | ||
values = data[key] | ||
values = [str(value).strip("'") for value in values] | ||
error_type = "Error Type: " + ", ".join(values) | ||
doc.append(NoEscape(error_type)) | ||
doc.append('\n') | ||
else: | ||
doc.append(NoEscape("Error Type:")) | ||
doc.append('\n') | ||
|
||
doc.append(NoEscape("Description:")) | ||
doc.append('\n') | ||
doc.append(NoEscape("Additional Notes:")) | ||
doc.append('\n') | ||
doc.append('\n') | ||
|
||
doc.append(NewPage()) | ||
doc.append(Section(NoEscape(r'\underline{Additional Resources:}'), numbering=False)) | ||
doc.append('\n') | ||
doc.append('\n') | ||
|
||
added_errors = set() | ||
|
||
for key in keys: | ||
if data[key] is not None: | ||
values = data[key] | ||
unique_values = list(set([str(value).strip("'") for value in values])) # Removes duplicates | ||
for error_name in unique_values: | ||
error_message = error_name | ||
if error_message not in added_errors: | ||
if error_name in error_links: | ||
link = error_links[error_name] | ||
doc.append(NoEscape(error_message + r': \underline{\href{' + link + r'}{link}}\n')) | ||
doc.append('\n') | ||
else: | ||
doc.append('- ' + error_message + '\n') | ||
added_errors.add(error_message) | ||
else: | ||
doc.append("\n") | ||
keys = list(data.keys()) | ||
print(keys) | ||
with doc.create(Section(NoEscape(r'\centerline{Code Report}'), numbering=False)): | ||
for count, line in enumerate(assignment): | ||
if data.get(str(count + 1)) is not None: | ||
text = data.get(str(count + 1)) | ||
doc.append(str(text)) | ||
else: | ||
with doc.create(syntax_code()): | ||
# text = ''.join([line]) | ||
text = (line) | ||
doc.append(text) | ||
|
||
doc.generate_pdf(out_dir, clean_tex=False, compiler=PDFLATEX_PATH, compiler_args=['-shell-escape']) | ||
# doc = format_doc() | ||
# doc.append(NewPage()) | ||
# doc.generate_pdf('out/out', clean_tex=False, compiler='pdflatex', silent=False) | ||
|
||
doc.generate_pdf('report_out/report_out', clean_tex=False, compiler=PDFLATEX_PATH) | ||
|
||
if __name__ == '__main__': | ||
assemble_pdf(sys.argv[1]) | ||
assemble_pdf(sys.argv[1], sys.argv[2]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import * as vscode from 'vscode'; | ||
|
||
export function cursorPosition() { | ||
const editor = vscode.window.activeTextEditor; | ||
if (editor === undefined) { | ||
return; | ||
} | ||
const doc = editor.document; | ||
const position = editor.selection.active; | ||
return doc.lineAt(position); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.