diff --git a/lib/ta_comment/check_comment.py b/lib/ta_comment/check_comment.py new file mode 100644 index 0000000..f9189e1 --- /dev/null +++ b/lib/ta_comment/check_comment.py @@ -0,0 +1,88 @@ +import json + +class TAComment: + def __init__(self, filedata) -> None: + + self.filedata = filedata + self.__requried = ["comment","lines"] + self.__start = 0 + self.__end = 0 + self.__startstate = False + self.__string_container = "" + self.__lines_container = [] + self.__lines_num = 0 + self.__status = True + self.__out = "" + + @property + def out(self): + return self.__out + + def run(self): + for line in self.filedata: + self.__lines_num += 1 + self.__condition_state(line) + return self.__lines_container + + def __condition_state(self,line): + if "#>>> :end:" in line and self.__startstate: + self.__have_end(line) + elif self.__startstate: + self.__add_line(line) + elif "#>>> :end:" in line and not self.__startstate: + self.__can_not_find_start(line) + if "#>>> :start:" in line and self.__startstate: + self.__did_not_have_end_point() + if "#>>> :start:" in line: + self.__have_start() + + def __check_comment_syntax(self,data): + return self.__requried != list(data.keys()) + + + def __did_not_have_end_point(self): + self.__out += f"syntax error line:{self.__lines_num-1}\n \n" + self.__status = False + self.__have_start() + + def __have_end(self,line): + self.__end = self.__lines_num + self.__startstate = False + data = self.__org_info(self.__split_line_data(line)) + if self.__check_comment_syntax(data): + self.__not_follow_req(line) + return + data["lines"] = {f"{self.__start}-{self.__end}":self.__string_container} + self.__lines_container.append(data) + + def __not_follow_req(self,line): + self.__out += f"syntax error line:{self.__lines_num}\n" + self.__out += f" \n" + self.__out += f" {line}\n" + self.__status = False + + def __have_start(self): + self.__start = self.__lines_num + self.__string_container = "" + self.__startstate = True + + def __add_line(self,line): + self.__string_container += line + + def __can_not_find_start(self,line): + self.__out += f"syntax error line:{self.__lines_num}\n \n {line}" + self.__status = False + + def __org_info(self,element): + data = {} + for i in element: + pre_data = i.split("=") + data[pre_data[0].strip()] = pre_data[1].strip() + data[f"lines"] = {f"{self.__start}-{self.__end}":self.__lines_container} + return data + + def __split_line_data(self,line): + elementline = line[11:] + element = elementline.split(",") + return element + diff --git a/lib/ta_comment/main.py b/lib/ta_comment/main.py new file mode 100644 index 0000000..15f41a5 --- /dev/null +++ b/lib/ta_comment/main.py @@ -0,0 +1,23 @@ +from check_comment import TAComment +import os +import json +def ta_comment(path): + std_list = os.listdir(path) + comments = {"comments":[]} + container = {} + traceback = "" + for studir in std_list: + container[studir] = [] + for directory, subdirectories, files in os.walk(os.path.join(path,studir)): + for file in files: + with open(os.path.join(directory, file),"r") as readfile: + filedata = readfile.readlines() + TA = TAComment(filedata) + container[studir].append({file:TA.run()}) + traceback += "=========================\n" + traceback += f"{studir} {file}\n" + traceback += "=========================\n" + traceback += TA.out + print(traceback) + return json.dumps(container,indent=3) + diff --git a/lib/ta_comment/readme.md b/lib/ta_comment/readme.md new file mode 100644 index 0000000..5570e70 --- /dev/null +++ b/lib/ta_comment/readme.md @@ -0,0 +1,52 @@ +# TA COMMENT + +Because we have a problem that when the students were deducted and wondered where they were deducted, then the +students asked ta one by one, causing difficulty in answer question. So we came up with this idea. + +This feature started out when we saw on github that when we reviewing the code we could tell which line of +code were bugs to the person that respomsible for that project. So we think this the way to solved that problem. But we can't +do exactly like github. Then we have to change somthing to make it compatible with our projects. + +## Examples of use +### how to write comment +```python +#>>> :start: + +### YOUR CODE ### + +#>>> :end: comment=good job +``` + +### how to read comment +```python +from ta_comment.main import ta_comment +print(ta_comment(workpath) +``` + +### what you will get +you will get comments in form of json follow this order studentId -> filename -> comment, lines +``` +{ + "123456789": [ + { + "1.py": [ + { + "comment": "good job", + "lines": { + "15-23": "def create_ta_dir(path):\n ta_path = os.path.join(path, \"ta\")\n if os.path.exists(ta_path):\n return False\n else:\n DirManagement().create_dir(ta_path,out=False)\n return True\n" + } + }, + { + "comment": "good job", + "lines": { + "55-60": "def init_work_directory(path, workid) -> bool:\n config_path = os.path.join(path, \"ta\", \"config.json\")\n ta_path = os.path.join(path, \"ta\")\n draft_path = os.path.join(path, \"ta\", \"draft.json\")\n" + } + } + ] + } + } +``` +- we need to write down comment to student file +- we have our own syntax (you can't change it) +- all comment in student file will be read and send to server when we use `ta submit` (in case that you didn't use this feature on our project ignore this line) +