示例#1
0
    def _build_treeview(self):
        list_store = gtk.ListStore(
            gobject.TYPE_INT,
            gobject.TYPE_STRING,
            gobject.TYPE_STRING,
            gobject.TYPE_STRING,
            gobject.TYPE_STRING,
            gobject.TYPE_STRING,
        )

        db = BLLDatabase()
        check2s_list = Check2.db_select(db)

        for check2 in check2s_list:
            created = UIUtils.get_db_timestamp_str(check2.created)

            modified = '-'
            #don't display modification date if it is the same as creation date
            if check2.modified != None and check2.modified != check2.created:
                modified = UIUtils.get_db_timestamp_str(check2.modified)

            completed = '-'
            if check2.completed != None:
                completed = UIUtils.get_db_timestamp_str(check2.completed)

            list_store.append([
                check2.db_id,
                check2.csv_filename,
                check2.wav_foldername,
                completed,
                created,
                modified,
            ])

        db.close()
        treeview = gtk.TreeView(list_store)

        #create the hidden id column
        col = gtk.TreeViewColumn('ID', gtk.CellRendererText(), text=0)
        col.set_visible(False)
        treeview.append_column(col)

        #create the rest of the columns
        column_names = [
            'CSV File', 'WAV Folder', 'Completed', 'Created', 'Modified'
        ]
        for i in range(len(column_names)):
            col = gtk.TreeViewColumn(column_names[i],
                                     gtk.CellRendererText(),
                                     text=(i + 1))
            col.set_resizable(True)
            col.set_min_width(
                UIUtils.calc_treeview_col_min_width(column_names[i]))
            treeview.append_column(col)

        return treeview
示例#2
0
    def _build_list_store(self):
        list_store = gtk.ListStore(
            gobject.TYPE_STRING,  #name
            gobject.TYPE_STRING,  #description
            gobject.TYPE_STRING,  #created timestamp
            gobject.TYPE_STRING,  #output names
            gobject.TYPE_PYOBJECT,  #hidden object
        )

        db = BLLDatabase()
        configs = OutputConfig.db_select(db)
        for cur_config in configs:
            output_names = self._get_output_names_str(cur_config.outputs)
            created_str = UIUtils.get_db_timestamp_str(
                cur_config.created) if cur_config.created else '-'

            list_store.append([
                cur_config.name,
                cur_config.desc,
                created_str,
                output_names,
                cur_config,
            ])

        db.close()

        return list_store
示例#3
0
    def _build_list_store(self):
        list_store = gtk.ListStore(
            gobject.TYPE_INT,
            gobject.TYPE_STRING,
            gobject.TYPE_STRING,
            gobject.TYPE_STRING,
            gobject.TYPE_STRING,
            gobject.TYPE_STRING,
            gobject.TYPE_STRING,
            gobject.TYPE_INT,
            gobject.TYPE_STRING,
            gobject.TYPE_STRING,
        )
        db = BLLDatabase()
        checks_list = Check.db_select(db)
        for check in checks_list:
            created = UIUtils.get_db_timestamp_str(str(
                check.created)) if check.created != None else '-'
            last_run = UIUtils.get_db_timestamp_str(str(
                check.last_run)) if check.last_run != None else '-'
            completed = UIUtils.get_db_timestamp_str(str(
                check.completed)) if check.completed != None else '-'

            filters_str = ''
            if not check.filters:
                filters_str = '-'
            else:
                for i in range(len(check.filters)):
                    filters_str += check.filters[i].get_filter_desc_str()
                    if i < len(check.filters) - 1:
                        filters_str += ',\n'

            list_store.append([
                check.db_id,
                check.name,
                created,
                completed,
                last_run,
                check.input_filename,
                check.wav_filename,
                check.default_context_padding,
                str(check.pick_randomly),
                filters_str,
            ])
        db.close()

        return list_store
示例#4
0
 def _add_callback(self, model, new_config):
     model.append([
         new_config.name,
         new_config.desc,
         UIUtils.get_db_timestamp_str(new_config.created)
         if new_config.created else '-',
         self._get_output_names_str(new_config.outputs),
         new_config,
     ])
示例#5
0
 def _edit_callback(self, model, edited_config, row_it):
     model.set_value(row_it, 0, edited_config.name)
     model.set_value(row_it, 1, edited_config.desc)
     model.set_value(
         row_it, 2,
         UIUtils.get_db_timestamp_str(edited_config.created)
         if edited_config.created else '-')
     model.set_value(row_it, 3,
                     self._get_output_names_str(edited_config.outputs))
     model.set_value(row_it, 4, edited_config)
示例#6
0
    def export(self):
        success = True  #whether write succeeded or not

        try:
            #write some basic info about the check
            csv_file = open(self.filename, 'wb')
            csv_writer = csv.writer(csv_file)
            csv_writer.writerow(['Check name: "%s"' % (self.check.name)])
            csv_writer.writerow([
                'Last run on %s' %
                (UIUtils.get_db_timestamp_str(str(self.check.last_run)))
            ])
            csv_writer.writerow([
                'Created on %s' %
                (UIUtils.get_db_timestamp_str(str(self.check.created)))
            ])
            csv_writer.writerow(
                ['TRS / CSV file: %s' % (self.check.input_filename)])
            csv_writer.writerow(['WAV file: %s' % (self.check.wav_filename)])
            csv_writer.writerow(['Number of Segs: %s' % (self.check.num_segs)])
            csv_writer.writerow([
                'Default context padding (sec): %s' %
                (self.check.default_context_padding)
            ])
            csv_writer.writerow([
                'Randomly Pick Segments: %s' % (str(self.check.pick_randomly))
            ])

            #write filter descriptions
            if self.check.filters:
                csv_writer.writerow(['Filters:'])
                for cur_filter in self.check.filters:
                    csv_writer.writerow([cur_filter.get_filter_desc_str()])
            else:
                csv_writer.writerow(['Filters: None'])

            #write the actual data from the tests
            csv_writer.writerow([])
            headers = [
                'Test Number', 'LENA Start Time (w/o padding)',
                'LENA End Time (w/o padding)', 'Context Padding',
                'User-Adjusted Start Time', 'User-Adjusted End Time',
                'Uncertain/Other', 'Syllables (with context)',
                'Syllables (w/o context)', 'Actual Codes',
                'Category Selection', 'Category Correct'
            ]
            csv_writer.writerow(headers)  #write out the column headings

            #run through all of the tests, writing their data to the file and keeping track of how many times the user's selection was correct
            correct_count = 0
            db = BLLDatabase()
            for i in range(self.check.num_segs):
                cur_test = self.check.tests[i]
                row = []

                row.append(str(i + 1))
                row.append('%0.3f' % (cur_test.seg.start))
                row.append('%0.3f' % (cur_test.seg.end))
                row.append(str(cur_test.context_padding))
                row.append('%0.3f' % (cur_test.seg.user_adj_start))
                row.append('%0.3f' % (cur_test.seg.user_adj_end))
                row.append(str(bool(cur_test.is_uncertain)))
                row.append(str(cur_test.syllables_w_context))
                row.append(
                    str(cur_test.syllables_wo_context
                        ) if cur_test.syllables_wo_context != None else '')

                actual_codes = self._get_actual_speaker_codes(cur_test, db)
                codes_str = ''
                for cur_codeinfo in actual_codes:
                    codes_str += cur_codeinfo.code + ' '
                if codes_str.endswith(' '):
                    codes_str = codes_str[:-1]
                row.append(codes_str)

                cat_sel = self._get_cat_sel(cur_test)
                row.append(cat_sel.disp_desc)

                cat_correct = self._get_cat_correct(cur_test, actual_codes,
                                                    cat_sel)
                correct_count += int(cat_correct)
                row.append(str(bool(cat_correct)))

                csv_writer.writerow(row)

            db.close()
            csv_writer.writerow([])
            csv_writer.writerow([
                'Ratio correct: %0.2f' %
                (float(correct_count) / float(self.check.num_segs))
            ])
            csv_file.close()
            success = True

        except Exception as err:
            self.logger.error('Error exporting check: %s' % (err))

        return success