Exemplo n.º 1
0
    def test_bugfix_1509714111470(self):
        test_id = 1509714111470
        row = 21838
        id, content, truth = self.excel.get_scg_record(row)
        self.assertEquals(test_id, id)

        scg = Scg(id, content, truth)
        scg.save_image('temp/' + str(id) + '.png')
Exemplo n.º 2
0
    def test_bugfix_1509259382091(self):
        test_id = 1509259382091
        row = 12312
        id, content, truth = self.excel.get_scg_record(row)
        self.assertEquals(test_id, id)

        scg = Scg(id, content, truth)
        scg.save_image('temp/' + str(id) + '.png')
Exemplo n.º 3
0
    def setUp(self):
        # Load in the workbook
        excel = Excel('data/scg/test.xlsx')
        scg_id, scg_content, truth, req_at, resp_at = excel.get_scg_record(1)
        self.scg1 = Scg(scg_id, scg_content, truth, req_at, resp_at)  # x + y

        scg_id, scg_content, truth, req_at, resp_at = excel.get_scg_record(2)
        self.scg2 = Scg(scg_id, scg_content, truth, req_at, resp_at)  # x + y
Exemplo n.º 4
0
    def load_all_scgs(self):
        '''
        From a list of .xlsx files, generate a dictionary of Scgs with key is the id of Scg
        :return: scgs, dictionary of Scgs
        '''
        scgs = {}  # dictionary of Scgs
        aspect_ratios = {}
        with codecs.open('data/invalid_scgs.txt', 'w', 'utf-8') as f_out:
            for root, dirnames, filenames in os.walk(self.xlsx_file_path, followlinks=True):
                for filename in fnmatch.filter(filenames, '*.xlsx'):
                    tmp_path = os.path.join(root, filename)
                    # print tmp_path
                    excel = Excel(tmp_path)
                    max_row = excel.get_row_number()
                    for idx in range(1, max_row):
                        print idx
                        id, scg, truth, req_at, resp_at = excel.get_scg_record(idx)
                        if len(truth.strip()) == 0:
                            print id
                            line = str(id) + ' ' + 'no latex\n'
                            f_out.write(line)
                            continue
                        scgs[id] = Scg(id, scg, truth, req_at, resp_at)
                        aspect_ratios[id] = scgs[id].w_h_ratio
        #dump aspect_ratios to a file
        ars = aspect_ratios.values()
        print 'aspect ratio min, mean, max: ', min(ars), max(ars), sum(ars) / float(len(ars))

        with open(self.list_out_dir + 'aspectratio.dict', 'wb') as fout:
            pickle.dump(aspect_ratios, fout)
        return scgs
Exemplo n.º 5
0
    def load_all_scgs(self):
        '''
        From a .xlsx file, generate a dictionary of Scgs with key is the id of Scg
        :return: scgs, dictionary of Scgs
        '''
        scgs = {}  # dictionary of Scgs
        aspect_ratios = {}
        with codecs.open('data/invalid_scgs.txt', 'w', 'utf-8') as f_out:
            max_row = self.get_row_number()
            for idx in range(1, max_row):
                print idx
                id, scg, truth, req_at, resp_at  = self.get_scg_record(idx)
                if len(truth.strip()) == 0:
                    print id
                    line = str(id) + ' ' + 'no latex\n'
                    f_out.write(line)
                    continue
                scgs[id] = Scg(id, scg, truth, req_at, resp_at)
                aspect_ratios[id] = scgs[id].w_h_ratio
        #dump aspect_ratios to a file
        ars = aspect_ratios.values()
        print 'aspect ratio min, mean, max: ', min(ars), max(ars), sum(ars) / float(len(ars))

        with open( 'aspectratio.dict', 'wb') as fout:
            pickle.dump(aspect_ratios, fout)

        self.scgs = scgs
        return scgs
Exemplo n.º 6
0
 def test_get_scg_requestat(self):
     scg_id, scg_content, truth, req_at, resp_at = self.excel.get_scg_record(
         2)
     scg = Scg(scg_id, scg_content, truth, req_at, resp_at)
     print 'request_at: ', scg.request_at
     self.assertEquals(str(req_at),
                       '2017-10-24 15:46:32')  #convert req_at to str
Exemplo n.º 7
0
 def saveRow2db(self, row):
     scg_id, scg_content, truth, req_at, resp_at = self.excel.get_scg_record(
         row)
     if len(truth.strip()) == 0:
         print '' + str(id) + ' ' + 'no latex\n'
         return
     scg = Scg(scg_id, scg_content, truth, req_at, resp_at)
     self.saveScg2db(scg)
Exemplo n.º 8
0
class TestScg(TestCase):
    def setUp(self):
        # Load in the workbook
        excel = Excel('data/scg/test.xlsx')
        scg_id, scg_content, truth, req_at, resp_at = excel.get_scg_record(1)
        self.scg1 = Scg(scg_id, scg_content, truth, req_at, resp_at)  # x + y

        scg_id, scg_content, truth, req_at, resp_at = excel.get_scg_record(2)
        self.scg2 = Scg(scg_id, scg_content, truth, req_at, resp_at)  # x + y

    def test_save_image1(self):
        self.scg1.save_image('temp/' + str(self.scg1.id) + '.png')

    def test_get_latex1(self):
        latex = self.scg1.get_latex()
        print latex

    def test_save_image2(self):
        self.scg2.save_image('temp/' + str(self.scg2.id) + '.png')

    def test_get_latex2(self):
        latex = self.scg2.get_latex()
        print latex
        aspect = self.scg2.w_h_ratio
        print 'aspect ratio: ', aspect
        print 'request_at: ', self.scg2.request_at