def get_2018_result(pdf): results = {} for page in iter_pages(pdf): if has_page_results(page): results.update( {r.roll_num: r for r in iter_results(page) if r.batch == 2018}) return results
from ggsipu_result import iter_pages, iter_results, has_page_results FILE = "document1.pdf" cgpa = [] for page in iter_pages(FILE): if has_page_results(page): for res in iter_results(page): # Filtered for specific batch if res.batch == 2018: cgpa.append(res.cgpa) avg_cgpa = sum(i for i in cgpa) / len(cgpa) print(avg_cgpa)
def test_iter_results(self): with open(self.result_data_file, 'r') as inputfile, open(self.result_file, 'r') as dumpf: results = list(ggsipu_result.iter_results(inputfile.read())) json_dump = ggsipu_result.toJSON(results) self.assertEqual(json_dump, dumpf.read())
def test_iter_results(self): with open(self.result_data_file, "r") as inputfile, open(self.result_file, "r") as dump_f: results = list(ggsipu_result.iter_results(inputfile.read())) json_dump = ggsipu_result.toJSON(results) assert json_dump == dump_f.read()
import ggsipu_result FILE = "document1.pdf" with open('subj_dump.json', 'a') as fs, open('res_dump.json', 'a') as fr: for page in ggsipu_result.iter_pages(FILE): if ggsipu_result.has_page_results(page): results = list(ggsipu_result.iter_results(page)) fr.write(ggsipu_result.toJSON(results)) elif ggsipu_result.has_page_subejcts(page): subjects = list(ggsipu_result.iter_subjects(page)) fs.write(ggsipu_result.toJSON(subjects))
import ggsipu_result import os CURRENT_DIR = os.path.abspath(os.path.dirname(__file__)) PROJECT_ROOT = os.path.dirname(CURRENT_DIR) RESOURCE_ROOT = os.path.join(PROJECT_ROOT, "Resources") SUBJ_TXT = os.path.join(RESOURCE_ROOT, "CSE_Result", "1.txt") RES_TXT = os.path.join(RESOURCE_ROOT, "CSE_Result", "58.txt") with open(os.path.join(RESOURCE_ROOT, "subjects.json"), "w") as subj_f, open( SUBJ_TXT, "r" ) as inputfile: inputdata = inputfile.read() if ggsipu_result.has_page_subjects(inputdata): subjects = list(ggsipu_result.iter_subjects(inputdata)) subj_f.write(ggsipu_result.toJSON(subjects)) with open(os.path.join(RESOURCE_ROOT, "results.json"), "w") as res_f, open( RES_TXT, "r" ) as inputfile: inputdata = inputfile.read() if ggsipu_result.has_page_results(inputdata): results = list(ggsipu_result.iter_results(inputdata)) res_f.write(ggsipu_result.toJSON(results))