def manual_grader_all(submission_folder_path, filename): # path : path of one submission folder. eg. "submissions/" # filename : name of the submission. eg. "question2.txt" report = {} dirs = get_dir(submission_folder_path) dirs = os.listdir(submission_folder_path) dirs = sorted(dirs) try: for c,i in enumerate(dirs): clear_screen() print("---------", i, "----------") print(c+1,'/',len(dirs)) path = os.path.join(submission_folder_path, i) id = get_id_from_path(i) r = manual_grader_one(path, filename) report[id] = r; except Exception as e: print(e) print(report) finally: output_report(report_name, report, sensitivity_words) print("report created!")
def get_ids_with_incorrect_format(note_paths: List[Path], id_pattern: str) -> List[Tuple[str, Path]]: """Check if IDs have the correct format""" zettel_ids = [get_id_from_path(path) for path in note_paths] return [(zettel_id, note_paths[loc]) for loc, zettel_id in enumerate(zettel_ids) if not re.match(id_pattern, zettel_id)]
def extract_submissions(sub_path): report = {} dirs = get_dir(sub_path) for i in dirs: path = os.path.join(sub_path, i) id = get_id_from_path(i) r = extract(path) report[id] = r output_report(report_name, report, sensitivity_words)
def run(): # os.chdir(submission_path) # get subdirectories dir = get_dir(submission_path) counter = 0 # run TB for every folder inside submission folder for i in dir: # start time t1 = time.time() # copy files for TB r = subprocess.run("cp " + tb + " " + os.path.join(submission_path, i), shell=True) # student canvas id student_id = get_id_from_path(i) d = defaultdict(str) print("-------------------" + "-------------------") os.chdir(os.path.join(submission_path, i)) print("current dir :", os.getcwd()) # running the process r = subprocess.Popen("./run.sh", stdout=PIPE, stderr=PIPE, shell=True) # live output out = "" for line in iter(r.stdout.readline, ''): if r.poll() is not None: break print(line.decode("utf-8"), end="") out += line.decode("utf-8") if parse(line.decode("utf-8")) is not None: key, value = parse(line.decode("utf-8")) if key in d: d["warning"] += "duplicate key *" + key + "*:" d[key] = value.strip() # finalized result if student_id in gradebook: print("Warning: duplicate ID") d["warning"] += "duplicate ID;" gradebook[student_id] = d # clean up os.chdir(submission_path) counter += 1 print(str(counter) + "/" + str(len(dir)) + " finished") # time for one iteration print(time.strftime("%H:%M:%S", time.localtime()), '\t\t,', time.time() - t1, "\n---------------------------------------------")
def has_zettel_id(path: Path, id_pattern) -> Union[str, bool]: """Checks if a note already has a zettel ID. :return zettel ID if present; False otherwise """ pattern = re.compile(id_pattern) match = pattern.match(get_id_from_path(path)) if match is not None: return match.group() return False
def get_duplicate_ids(note_paths: List[Path], id_pattern: str) -> List[Tuple[str, List[Path]]]: """Checks for duplicate IDs This method assumes the IDs are in the correct format. :return List of 2-tuples of the form (id, List[Path]) for each ID that occurs more than once """ ids = [get_id_from_path(path) for path in note_paths] duplicates = [] for zettel_id, locs in sorted(list_duplicates(ids)): duplicates.append((zettel_id, [note_paths[loc] for loc in locs])) return duplicates
def get_broken_links(note_paths: List[Path], id_pattern: str) -> List[Tuple[str, Path]]: """Checks for broken links (links that do not point to an existing ID) Checks for the wikilink styles [[ZETTEL_ID]] and [[ZETTEL_ID Optional text]] """ ids = [get_id_from_path(path) for path in note_paths] # group(1) is everything between the [[brackets]] # group(2) is the zettel ID only pattern = re.compile(r"\[{2}(" + id_pattern + r"[^]\n]*)]{2}") broken_links = [] for path in note_paths: for match in pattern.finditer(path.read_text()): if match.group(2) not in ids: broken_links.append((match.group(1), path)) return broken_links