Example #1
0
    def post(self):
        if experiment_grouping_already_started(
                self.experiment):  # be idempotent
            return

        cycle = Cycle(range(self.experiment.cohort_count))

        workers, peer_workers = [], {}

        for worker in Worker.all().filter('experiment = ', self.experiment):
            worker.cohort_index = cycle.next()

            workers.append(worker)

            if peer_workers.has_key(worker.cohort_index):
                peer_workers[worker.cohort_index].append(worker)
            else:
                peer_workers[worker.cohort_index] = [worker]

        for worker in workers:
            previous_cohort_index = index_decr(worker.cohort_index,
                                               self.experiment.cohort_count)

            previous_cohort = peer_workers[previous_cohort_index]

            worker.peer_worker = previous_cohort.pop(
                random.randrange(len(previous_cohort)))
            worker.put()

            if worker.cohort_index == 0:
                taskqueue.add(queue_name='worker-notification',
                              params={'key': worker.key()})
Example #2
0
  def post(self):
    if experiment_grouping_already_started(self.experiment): # be idempotent
      return

    cycle = Cycle(range(self.experiment.cohort_count))

    workers, peer_workers = [], {}

    for worker in Worker.all().filter('experiment = ', self.experiment):
      worker.cohort_index = cycle.next()

      workers.append(worker)

      if peer_workers.has_key(worker.cohort_index):
        peer_workers[worker.cohort_index].append(worker)
      else:
        peer_workers[worker.cohort_index] = [worker]

    for worker in workers:
      previous_cohort_index = index_decr(worker.cohort_index, self.experiment.cohort_count)

      previous_cohort = peer_workers[previous_cohort_index]

      worker.peer_worker = previous_cohort.pop(random.randrange(len(previous_cohort)))
      worker.put()

      if worker.cohort_index == 0:
        taskqueue.add(queue_name='worker-notification', params={'key': worker.key()})
Example #3
0
  def _fn(self, *args, **kwargs):
    self.token = self.request.get('token')

    self.worker = Worker.all().filter('nonce = ', self.token).get()

    if self.worker:
      return fn(self, *args, **kwargs)
    else:
      self.bad_request()
Example #4
0
    def _fn(self, *args, **kwargs):
        self.token = self.request.get('token')

        self.worker = Worker.all().filter('nonce = ', self.token).get()

        if self.worker:
            return fn(self, *args, **kwargs)
        else:
            self.bad_request()
Example #5
0
  def post(self):
    labeling = Labeling()
    labeling.image_url = self.image_url(self.worker)
    labeling.worker = self.worker
    labeling.labels = self.request.get_all('label')
    labeling.time = int(self.request.get('time'))
    labeling.put()

    evaluator = Worker.all().filter('peer_worker = ', self.worker).get()

    taskqueue.add(queue_name='worker-notification', params={'key': evaluator.key()})

    self.redirect(self.mturk_submit_url())
Example #6
0
    def post(self):
        labeling = Labeling()
        labeling.image_url = self.image_url(self.worker)
        labeling.worker = self.worker
        labeling.labels = self.request.get_all('label')
        labeling.time = int(self.request.get('time'))
        labeling.put()

        evaluator = Worker.all().filter('peer_worker = ', self.worker).get()

        taskqueue.add(queue_name='worker-notification',
                      params={'key': evaluator.key()})

        self.redirect(self.mturk_submit_url())
Example #7
0
  def get(self):
    experiments = Experiment.all().filter('second_stage_started = ', None)

    for experiment in experiments:
      worker_count = 0

      for worker in Worker.all().filter('experiment = ', experiment):
        if worker.has_labeled_an_image():
          worker_count += 1

      if worker_count == experiment.cohort_size * experiment.cohort_count:
        taskqueue.add(queue_name='worker-grouping', params={'key': experiment.key()})

        experiment.second_stage_started = datetime.now()
        experiment.put()
Example #8
0
    def get(self):
        experiments = Experiment.all().filter('second_stage_started = ', None)

        for experiment in experiments:
            worker_count = 0

            for worker in Worker.all().filter('experiment = ', experiment):
                if worker.has_labeled_an_image():
                    worker_count += 1

            if worker_count == experiment.cohort_size * experiment.cohort_count:
                taskqueue.add(queue_name='worker-grouping',
                              params={'key': experiment.key()})

                experiment.second_stage_started = datetime.now()
                experiment.put()