diff --git a/mkt_reader_writer.py b/mkt_reader_writer.py index 7307fcfe6..7c046faf5 100644 --- a/mkt_reader_writer.py +++ b/mkt_reader_writer.py @@ -1,34 +1,55 @@ -#!/usr/bin/env python3 -from configobj import ConfigObj, Section - -def load_questions_file(f_name): - obj = ConfigObj(f_name, interpolation=True) - f_name = f_name.split("/") - f_name = f_name[len(f_name)-1] - return obj, load_questions(obj, f_name) - -def load_questions(obj, parent): - qList = {} - for c in obj: - item = obj[c] - if "question" in item: - qList[parent + "/" + c] = item - elif isinstance(item, Section): - qList.update(load_questions(item, parent + "/" + c)) - return qList - -def get_question(questions, key): - return questions[key] - -def update_question(question, key, value): - question[key] = value - -def save_changes(f_name, obj): - obj.write(open(f_name, "wb")) - -if __name__ == "__main__": - obj, questions = load_questions_file("csci320-2191/questionPool/chapter1.txt") - question = get_question(questions, 'chapter1.txt/File System') - update_question( question, 'points', 100) - save_changes('test.txt', obj) - +#!/usr/bin/env python3 +from configobj import ConfigObj, Section +import os + +root_path = "../questions/" +questionPool_path = "/questionPool/" + + +def get_courses(): + courses = [name for name in os.listdir(root_path) + if os.path.isdir(os.path.join(root_path, name))] + courses.sort() + return courses + +def get_questions_files(course): + files = os.listdir(root_path+course+questionPool_path) + files.sort() + return str(files).strip('[]') + + +def load_questions_file(course, question_file): + f_name = root_path + course + questionPool_path + question_file + obj = ConfigObj(f_name, interpolation=True) + f_name = f_name.split("/") + f_name = f_name[len(f_name)-1] + return obj, load_questions(obj, f_name) + +def load_questions(obj, parent): + qList = {} + for c in obj: + item = obj[c] + if "question" in item: + qList[parent + "/" + c] = item + elif isinstance(item, Section): + qList.update(load_questions(item, parent + "/" + c)) + return qList + +def get_question(questions, file, title): + key = file+"/"+title + return questions[key] + +def update_question(question, key, value): + question[key] = value + +def save_changes(f_name, obj): + obj.write(open(f_name, "wb")) + +if __name__ == "__main__": + if not os._exists("../questions/"): + root_path = "./questions/" + obj, questions = load_questions_file("csci320-2191", "chapter1.txt") + question = get_question(questions, 'chapter1.txt', 'File System') + update_question( question, 'points', 100) + save_changes('test.txt', obj) + diff --git a/test.txt b/test.txt new file mode 100644 index 000000000..cafdc0523 --- /dev/null +++ b/test.txt @@ -0,0 +1,71 @@ +[File System] + type = LongAnswer + points = 100 + question = What are 3 advantages of using a database system over a file system? + solution = "loose coupling between application and data. Facilities provided for query and retrieval. More efficient, consistency, and easier maintenance" + +[Conceptual Data Model] + maxQuestions = 1 + [[1]] + type = LongAnswer + points = 3 + question = What is the purpose of the conceptual data model. Who does it benefit and what artifacts are created? + solution = The conceptual data model is used to share information between the business and development teams. The represent the business needs are an ER diagram is usually produced. + [[2]] + type = shortAnswer + points = 3 + question = "Ideally, what are the 3 data model types (layers)" + solutions = Internal, Logical, External + +[KPIs] + type = LongAnswer + points = 3 + question = What are the three key performance indicators of a database? + solution = "Response time, throughput rate, space utilization" + +[Elements of a DB system] + type = multipleChoice + points = 2 + question = Which is not an element of a database system + correctAnswer = Four Layer Model + wrongAnswers = Catalog, Users, Data Model + +[Data Independence] + type = multipleChoice + points = 2 + question = What is the term used to describe when the physical model need not change when the logical model does? + correctAnswer = Data Independence + wrongAnswers = Model Independence, Physical Isolation, Logical Isolation + +[XML] + type = TF + question = XML is considered semi-structured data + solution = true + + +[DDL] + type = shortAnswer + question = What DB language is used to create the structure of the database + solution = DDL + +[Catalog] + type = shortAnswer + question = What piece of your database (DBMS) holds the metadata for your system? + solution = Catalog + +[ACID] + type = shortAnswer + points = 4 + question = What are the properties of an ACID database (just name them) + solutions = Atomic, Consistent, Isolation, Durable + +[Data Model vs Instance] + maxQuestions = 1 + [[Model]] + type = TF + question = A snapshot of your data at a given time is a data model + solution = False + [[Instance]] + type = TF + question = A snapshot of your data at a given time is a data instance + solution = True diff --git a/web/index.py b/web/index.py index ce62f3ac3..d8233ba99 100644 --- a/web/index.py +++ b/web/index.py @@ -4,41 +4,30 @@ import json -def get_immediate_subdirectories(a_dir): - return [name for name in os.listdir(a_dir) - if os.path.isdir(os.path.join(a_dir, name))] - - -courses = get_immediate_subdirectories('../questions/') -courses.sort() - app = Flask(__name__) @app.route('/') @app.route('/home') def home(): - return render_template('home.html', courses=courses) + return render_template('home.html', courses=mkt_reader_writer.get_courses()) @app.route('/editor') def editor(): - - return render_template('editor.html', courses=courses) + return render_template('editor.html', courses=mkt_reader_writer.get_courses()) @app.route('/changeCourse', methods=['POST']) def changeCourse(): course = request.form['selectedCourse'] - files = os.listdir("../questions/"+course+'/questionPool') - files.sort() - return str(files).strip('[]') + return mkt_reader_writer.get_questions_files(course) @app.route('/getQuestions', methods=['POST']) def getQuestions(): course = request.form['course'].strip() fileName = request.form['fileName'].strip() - obj, questions = mkt_reader_writer.load_questions_file("../questions/"+course+'/questionPool/'+fileName) + obj, questions = mkt_reader_writer.load_questions_file(course, fileName) return json.dumps(obj) @app.route('/addQuestion', methods=['POST'])