Exemplo n.º 1
0
def create_test_codebook(**kargs):
    """Create a test codebook"""
    from amcat.models.coding.codebook import Codebook, get_codebook
    if "project" not in kargs: kargs["project"] = create_test_project()
    if "name" not in kargs: kargs["name"] = "testcodebook_%i" % Codebook.objects.count()
    if "id" not in kargs: kargs["id"] = _get_next_id()
    c = Codebook.objects.create(**kargs)
    return get_codebook(c.id)
Exemplo n.º 2
0
 def run(self, _input=None):
     c = get_codebook(self.options["codebook"].id)
     for lang in LABEL_LANGUAGE + QUERY_LANGUAGE:
         c.cache_labels(lang)
     t = ObjectTable(rows=c.get_codes())
     t.addColumn(lambda c: c.id, "id")
     t.addColumn(lambda c: c.get_label(*LABEL_LANGUAGE), "label")
     t.addColumn(lambda c: c.get_label(*QUERY_LANGUAGE, fallback=False),
                 "query")
     return t
Exemplo n.º 3
0
    def test_jobset_allcodes(self):
        """Test whether getting all codes for a set is efficient"""
        types = [self.inttype, self.codetype]
        vals = [(12, self.code)]
        job = self._create_job(types)
        codings = self._add_codings(job, vals * 25, narticles=1)

        with self.checkMaxQueries(2, "Caching codebook"):
            c = codebook.get_codebook(self.codebook.id)
            list(c.get_hierarchy())

        with self.checkMaxQueries(1, "Getting all codings for a job"):
            codings = list(job.get_codings())

        with self.checkMaxQueries(0, "Getting pre-fetched codings and values"):
            for c in codings:
                _x = [v for (_k, v) in c.get_values()]
Exemplo n.º 4
0
 def __init__(self, field):
     super(_CodebookSerialiser, self).__init__(field, Code, int)
     self.codebook = get_codebook(field.codebook_id)
Exemplo n.º 5
0
 def get_codebook(self):
     return get_codebook(self.codebook_id)