Пример #1
0
 def get_source_worker(self):
     """
         Returns a worker who has sent this sample.
     """
     return Sample.get_worker(
         source_type=self.source_type,
         source_val=self.source_val,
     )
Пример #2
0
def create_classify_sample(result, source_type, create_classified=True,
        label='', source_val='', *args, **kwargs):
    """
        Creates classified sample from existing sample, therefore we don't need
        web extraction.
    """

    # We are given a tuple (extraction result, sample id)
    extraction_result = result[0]

    # If extraction failed - return
    if not extraction_result:
        return False
    sample_id = result[1]

    # Don't classify already classified samples
    if label:
        return sample_id

    if create_classified:
        try:
            sample = Sample.objects.get(id=sample_id)

            if not label:
                label = ''

            # Proper sample entry
            class_sample = ClassifiedSample.objects.create(
                job=sample.job,
                url=sample.url,
                sample=sample,
                label=label,
                source_type=source_type,
                source_val=source_val,
            )

            worker = Sample.get_worker(source_type=source_type,
                    source_val=source_val)
            if worker:
                # Update cache
                worker.get_urls_collected_count_for_job(sample.job, cache=False)

            # Sample created sucesfully - pushing event.
            send_event(
                "EventNewClassifySample",
                sample_id=class_sample.id,
            )

        except DatabaseError, e:
            # Retry process on db error, such as 'Database is locked'
            create_classify_sample.retry(exc=e,
                countdown=min(60 * 2 ** current.request.retries, 60 * 60 * 24))
Пример #3
0
    def forwards(self, orm):
        "Write your forwards methods here."
        # Note: Remember to use orm['appname.ModelName'] rather than "from appname.models..."
        for sample in orm["main.Sample"].objects.filter(goldsample__isnull=True):
            worker = Sample.get_worker(source_type=sample.source_type, source_val=sample.source_val)
            if not worker:
                continue

            try:
                orm["crowdsourcing.WorkerQualityVote"].objects.new_vote(worker=worker, sample=sample, label=LABEL_YES)
            except:
                # Such vote already exists - skip.
                pass
Пример #4
0
    def forwards(self, orm):
        "Write your forwards methods here."
        # Note: Remember to use orm['appname.ModelName'] rather than "from appname.models..."
        for sample in orm['main.Sample'].objects.filter(goldsample__isnull=True):
            worker = Sample.get_worker(
                source_type=sample.source_type,
                source_val=sample.source_val,
            )
            if not worker:
                continue

            try:
                orm['crowdsourcing.WorkerQualityVote'].objects.new_vote(
                    worker=worker,
                    sample=sample,
                    label=LABEL_YES,
                )
            except:
                # Such vote already exists - skip.
                pass
Пример #5
0
 def get_source_worker(self):
     """
         Returns a worker who has sent this sample.
     """
     return Sample.get_worker(source_type=self.source_type, source_val=self.source_val)