예제 #1
0
 def to_dict(self):
     return { 'start': datetime_str(self.start),
              'end': datetime_str(self.end),
              'source': self.source,
              'mean': self.mean,
              'peak': self.peak,
              'valley': self.valley }
예제 #2
0
    def post(self):

        uname = self.get_argument("uname", "")
        cell = self.get_argument("cell", "")
        upass = self.get_argument("upass", "")
        upass2 = self.get_argument("upass2", "")

        # if upass2 is not upass:
        if upass2 != upass:
            self.write({'code': 'error', 'reason': 'pass2'})
            return

        salt = random_string(16)
        authcode = random_number(6)
        password = hashlib.sha1((upass + salt).encode('ascii')).hexdigest()

        info = {}

        user = User(
            username=uname,
            password=password,
            status=0,
            type=2,
            salt=salt,
            reg_date=datetime_str(),
            courses='',
            info=info)

        self.db.add(user)
        self.db.commit()

        if user.id:
            self.set_secure_cookie("userinfo", json.dumps({
                'type': user.type,
                'name': user.username,
                'id': user.id})
            )
            # TODO: 发短信
            jobq.enqueue("job_send_sms_auth.tpl_send_sms", "#code#=%s" % authcode, cell)
            self.write({'code': 'ok', 'id': user.id})
        else:
            self.write({'code': 'error'})
    def __init__(self, config=None):
        """Constructor for the miscellaneous configuration"""
        config = {} if config is None else config
        super().__init__(config)
        if self.has_value("keys", base=config):
            for kname, kvalue in config['keys'].items():
                self.keys[kname] = kvalue
        self.independent = self.get_value("independent_component", base=config, default=False)

        self.allow_model_deserialization = self.get_value("allow_model_deserialization", base=config, default=False)
        self.allow_output_deserialization = self.get_value("allow_output_deserialization", base=config, default=False)


        self.csv_separator = self.get_value("csv_separator", base=config, default=",")
        self.run_id = self.get_value("run_id", base=config, default="run_" + datetime_str())

        if not self.has_value("keys", base=config):
            self.seed = random.randint(0, 5000)
            warning("No random seed submitted, randomly generated: {}".format(self.seed))
        else:
            self.seed = self.get_value("seed", base=config)
예제 #4
0
    def post(self):
        uname = self.get_argument("uname", "")
        upass = self.get_argument("upass", "")

        user = self.db.query(User).filter(
            User.username == uname).filter(
            User.type == 2).first()

        if not user:
            self.write({'code': 'error', 'reason': "notuser"})
            return

        userinfo = {'name': uname, 't': 2}

        user.last_login = datetime_str()
        self.db.commit()
        userinfo['id'] = user.id

        if user.password == hashlib.sha1((upass + user.salt).encode('ascii')).hexdigest():
            self.set_secure_cookie('user', json.dumps(userinfo), expires_days=None)
            self.write({'code': 'ok'})
        else:
            self.write({'code': 'error', 'reason': 'other'})
    def read_global_configuration(config_dict, ignore_undefined=False):
        """Read global-level configuration (accessible to all components and chains)
        Arguments:
            input_config {dict} -- The configuration
            ignore_undefined {boolean} -- Whether to ignore (true) of throw an error (false) on undefined keys
        """
        global_config = GlobalConfig()
        for global_conf_key, comp_conf in config_dict.items():
            if global_conf_key == GlobalConfig.chains_key:
                continue
            comp = [
                g for g in global_component_classes
                if g.conf_key_name == global_conf_key
            ]
            if len(comp) != 1:
                if not ignore_undefined:
                    error(
                        f"Undefined global configuration component: {global_conf_key}",
                        not comp)
                else:
                    continue
                error(
                    f"Multiple global configuration component matches: {global_conf_key}",
                    len(comp) > 1)
            comp = comp[0]
            component_config = comp(comp_conf)
            global_config.add_config_object(global_conf_key, component_config)

        global_config.finalize()
        if global_config.misc.run_id is None:
            global_config.misc.run_id = utils.datetime_str()
        # make directories
        for ddir in (global_config.folders.run, global_config.folders.raw_data,
                     global_config.folders.serialization):
            os.makedirs(ddir, exist_ok=True)
        return global_config
예제 #6
0
 def __repr__(self):
     return '<Stat ({} - {}; duration {}s)>'.format(datetime_str(self.start), datetime_str(self.end), self.duration)
    def __init__(self, config=None):
        """Constructor for the folders configuration"""
        config = {} if config is None else config
        super().__init__(config)
        self.run = self.get_value("run", base=config, default=join(os.getcwd(), "run_" + datetime_str()))
        warning(f"No run folder submitted, generated {self.run}")
        self.results = join(self.run, "results")
        self.serialization = self.get_value("serialization", base=config, default="serialization")
        self.raw_data = self.get_value("raw_data", base=config, default="raw_data")

        nltk_data_path = self.get_value("nltk", base=config, default=join(self.raw_data, "nltk"))
        # set nltk data folder
        nltk.data.path = [nltk_data_path]