def run(self, form): provenance = None#form.cleaned_data["provenance"] #TODO: is dit correct? job_size = form.cleaned_data["job_size"] self.monitor.update(10, "Executing query..") article_ids = list(SelectionSearch(form).get_article_ids()) cj = CodingJob() cj.project = self.project cj.name = form.cleaned_data["name"] cj.unitschema = form.cleaned_data["unitschema"] cj.articleschema = form.cleaned_data["articleschema"] cj.coder = form.cleaned_data["coder"] cj.insertuser = self.user self.monitor.update(50, "Creating codingjobs..") if job_size == 0: job_size = len(article_ids) n_batches = len(article_ids) // job_size n_batches += 1 if len(article_ids) % job_size else 0 for i, cid in enumerate(_create_codingjob_batches(cj, article_ids, job_size)): progress = int((i / float(n_batches)) * (100 // 2)) msg = "Creating codingjob {} of {}..".format(i+1, n_batches) print(50 + progress) self.monitor.update(50 + progress, msg) if provenance: cj = CodingJob.objects.get(id=cid) cj.provenance = provenance cj.save() return "Codingjob(s) created."
def import_codingjobs(self): old_ids, jobs = [], [] for job in self._get_dicts("codingjobs.jsonl"): j = CodingJob(project_id=self.status.project.id, name=job['name'], archived=job['archived'], insertuser_id=self.status.project.owner.id, coder_id=self.status.users[job['coder']], articleset_id=self.status.setids[job['articleset']]) if job['articleschema']: j.articleschema_id = self.status.codingschemas[job['articleschema']] if job['unitschema']: j.unitschema_id = self.status.codingschemas[job['unitschema']] jobs.append(j) old_ids.append(job['pk']) jobs = bulk_insert_returning_ids(jobs) return {old_id: job.id for (old_id, job) in zip(old_ids, jobs)}
def test_create_codingjob_batches(self): a = amcattest.create_test_set(10) cj = CodingJob() cj.project = a.project cj.name = "foo" cj.unitschema = amcattest.create_test_schema(project=a.project) cj.articleschema = amcattest.create_test_schema(isarticleschema=True, project=a.project) cj.coder = amcattest.create_test_user() cj.insertuser = amcattest.create_test_user() arts = a.articles.all().values_list("id", flat=True) cjs = create_codingjob_batches(cj, arts, 2) self.assertEqual(5, len(cjs)) cjs = create_codingjob_batches(cj, arts, 3) self.assertEqual(4, len(cjs))
def run(self, form): provenance = None #form.cleaned_data["provenance"] #TODO: is dit correct? job_size = form.cleaned_data["job_size"] self.monitor.update(10, "Executing query..") article_ids = list(SelectionSearch(form).get_article_ids()) cj = CodingJob() cj.project = self.project cj.name = form.cleaned_data["name"] cj.unitschema = form.cleaned_data["unitschema"] cj.articleschema = form.cleaned_data["articleschema"] cj.coder = form.cleaned_data["coder"] cj.insertuser = self.user self.monitor.update(50, "Creating codingjobs..") if job_size == 0: job_size = len(article_ids) n_batches = len(article_ids) // job_size n_batches += 1 if len(article_ids) % job_size else 0 for i, cid in enumerate( _create_codingjob_batches(cj, article_ids, job_size)): progress = int((i / float(n_batches)) * (100 // 2)) msg = "Creating codingjob {} of {}..".format(i + 1, n_batches) print(50 + progress) self.monitor.update(50 + progress, msg) if provenance: cj = CodingJob.objects.get(id=cid) cj.provenance = provenance cj.save() return "Codingjob(s) created."