Expire hits for an experiment id.
197574
def expire(app, sandbox, exit=True):
    """"""
    success = []
    failures = []
    service = _mturk_service_from_config(sandbox)
    hits = _current_hits(service, app)
    for hit in hits:
        hit_id = hit["id"]
        try:
            service.expire_hit(hit_id)
            success.append(hit_id)
        except MTurkServiceException:
            failures.append(hit_id)
    out = Output()
    if success:
        out.log("Expired {} hits: {}".format(len(success), ", ".join(success)))
    if failures:
        out.log(
            "Could not expire {} hits: {}".format(len(failures), ", ".join(failures))
        )
    if not success and not failures:
        out.log("No hits found for this application.")
        if not sandbox:
            out.log(
                "If this experiment was run in the MTurk sandbox, use: "
                "`dallinger expire --sandbox --app {}`".format(app)
            )
    if exit and not success:
        sys.exit(1)
713471
def expired(self):
    """"""
    expiry_time = self.expiry_time
    if expiry_time is not None:
      return expiry_time < rdfvalue.RDFDatetime.Now()
    else:
      return False
881783
def expires_at(self):
        
        if 'SignatureExpirationTime' in self._signature.subpackets:
            expd = next(iter(self._signature.subpackets['SignatureExpirationTime'])).expires
            return self.created + expd
        return None
26452
def _maybe_init_experiment(self, experiment_name):
    
    user_id = self._maybe_init_user()
    cursor = self._db.cursor()
    cursor.execute(
        """
        SELECT experiment_id FROM Experiments
        WHERE user_id = ? AND experiment_name = ?
        """,
        (user_id, experiment_name))
    row = cursor.fetchone()
    if row:
      return row[0]
    experiment_id = self._create_id()
    # TODO: track computed time from run start times
    computed_time = 0
    cursor.execute(
        """
        INSERT INTO Experiments (
          user_id, experiment_id, experiment_name,
          inserted_time, started_time, is_watching
        ) VALUES (?, ?, ?, ?, ?, ?)
        """,
        (user_id, experiment_id, experiment_name, time.time(), computed_time,
         False))
    return experiment_id
1308028
def expires_at(self):
        """"""
        try:
            expires = min(sig.key_expiration for sig in itertools.chain(iter(uid.selfsig for uid in self.userids), self.self_signatures)
                          if sig.key_expiration is not None)

        except ValueError:
            return None

        else:
            return (self.created + expires)
24386
def delete_expired_requests():
    """"""
    InclusionRequest.query.filter_by(
        InclusionRequest.expiry_date > datetime.utcnow()).delete()
    db.session.commit()
62095
def purge_obsolete_samples(self, config, now):
        
        expire_age = config.samples * config.time_window_ms
        for sample in self._samples:
            if now - sample.last_window_ms >= expire_age:
                sample.reset(now)
772837
def bandit_sticky_choose(exp)
      name = "bandit_#{exp}".intern
      # choose url param with preference
      value = params[name].nil? ? cookies.signed[name] : params[name]
      # sticky choice may outlast a given alternative
      alternative = if Bandit.get_experiment(exp).alternatives.include?(value)
                      value
                    else
                      Bandit.get_experiment(exp).choose(value)
                    end
      # re-set cookie
      cookies.permanent.signed[name] = alternative
    end
426825
def ExpireRules(self):
    """"""
    rules = self.Get(self.Schema.RULES)
    new_rules = self.Schema.RULES()
    now = time.time() * 1e6
    expired_session_ids = set()

    for rule in rules:
      if rule.expires > now:
        new_rules.Append(rule)
      else:
        for action in rule.actions:
          if action.hunt_id:
            expired_session_ids.add(action.hunt_id)

    if expired_session_ids:
      with data_store.DB.GetMutationPool() as pool:
        # Notify the worker to mark this hunt as terminated.
        manager = queue_manager.QueueManager(token=self.token)
        manager.MultiNotifyQueue([
            rdf_flows.GrrNotification(session_id=session_id)
            for session_id in expired_session_ids
        ],
                                 mutation_pool=pool)

    if len(new_rules) < len(rules):
      self.Set(self.Schema.RULES, new_rules)
      self.Flush()
1134233
def download_experiment(self, experiment_id):
        
        req = self.query_records('experiment', self.access_key,
                                 self.secret_key,
                                 query='download/'+experiment_id)
        print req.text
        return
1260551
def _has_expired(self):
        
        expired = False
        if hasattr(self, 'Expiration'):
            now = datetime.datetime.utcnow()
            expiration = datetime.datetime.strptime(self.Expiration, '%Y-%m-%dT%H:%M:%SZ')
            expired = (now >= expiration)
        else:
            raise ValueError("ERROR: Request for expired property, but no Expiration in HIT!")
        return expired
529407
def save_variation_for_experiment(self, experiment_id, variation_id):
    

    self.experiment_bucket_map.update({
      experiment_id: {
        self.VARIATION_ID_KEY: variation_id
      }
    })
647351
def archive(self):
        """"""
        pipe = self.redis.pipeline(transaction=True)
        pipe.srem(ACTIVE_EXPERIMENTS_REDIS_KEY, self.name)
        pipe.sadd(ARCHIVED_EXPERIMENTS_REDIS_KEY, self.name)
        pipe.execute()
1154898
def end_experiment(self):
        """"""
        if self.exp_config.get("mode") != "debug":
            HerokuApp(self.app_id).destroy()
        return True
1313297
def expireat(key, timestamp, host=None, port=None, db=None, password=None):
    '''
    
    '''
    server = _connect(host, port, db, password)
    return server.expireat(key, timestamp)
1025916
def expire(url)
      if url == :all
        if store.respond_to?(:keys)
          urls.each{ |u| expire(u) }
        else
          raise(NoMethodError, "The Geocoder cache store must implement `#keys` for `expire(:all)` to work")
        end
      else
        expire_single_url(url)
      end
    end
446415
def update_experiment(self, id, key, value):
        ''''''
        if id not in self.experiments:
            return False
        self.experiments[id][key] = value
        self.write_file()
        return True