Exemple #1
0
    def get_as_dict(self):
        """
        Return model settings as a dictionary.
        """
        settings = {'model': self.model,
                    'exp_segments': self.exp_segments,
                    'exp_max_segments': self.exp_max_segments,
                    'pow_proximal_limit': self.pow_proximal_limit,
                    'pow_distal_limit': self.pow_distal_limit,
                    'wei_number_of_runs': self.wei_number_of_runs,
                    'wei_iterations_per_run': self.wei_iterations_per_run,
                    'wei_lambda_lower_bound': self.wei_lambda_lower_bound,
                    'wei_lambda_upper_bound': self.wei_lambda_upper_bound,
                    'wei_k_lower_bound': self.wei_k_lower_bound,
                    'wei_k_upper_bound': self.wei_k_upper_bound}
        settings_used_by_models = {'exponential': ['exp_segments',
                                                   'exp_max_segments'],
                                   'power_law': ['pow_proximal_limit',
                                                 'pow_distal_limit'],
                                   'weibull': ['wei_lambda_upper_bound',
                                               'wei_lambda_upper_bound',
                                               'wei_k_upper_bound',
                                               'wei_k_upper_bound']}

        # Drop unused settings
        settings_used = settings_used_by_models[self.model]
        all_settings = settings.keys()
        settings_to_drop = [s for s in all_settings if s not in settings_used]
        for setting in settings_to_drop:
            settings.pop(setting)

        return settings
Exemple #2
0
    def get_as_dict(self):
        """
        Return model settings as a dictionary.
        """
        settings = {
            'model': self.model,
            'exp_segments': self.exp_segments,
            'exp_max_segments': self.exp_max_segments,
            'pow_proximal_limit': self.pow_proximal_limit,
            'pow_distal_limit': self.pow_distal_limit,
            'wei_number_of_runs': self.wei_number_of_runs,
            'wei_iterations_per_run': self.wei_iterations_per_run,
            'wei_lambda_lower_bound': self.wei_lambda_lower_bound,
            'wei_lambda_upper_bound': self.wei_lambda_upper_bound,
            'wei_k_lower_bound': self.wei_k_lower_bound,
            'wei_k_upper_bound': self.wei_k_upper_bound
        }
        settings_used_by_models = {
            'exponential': ['exp_segments', 'exp_max_segments'],
            'power_law': ['pow_proximal_limit', 'pow_distal_limit'],
            'weibull': [
                'wei_lambda_upper_bound', 'wei_lambda_upper_bound',
                'wei_k_upper_bound', 'wei_k_upper_bound'
            ]
        }

        # Drop unused settings
        settings_used = settings_used_by_models[self.model]
        all_settings = settings.keys()
        settings_to_drop = [s for s in all_settings if s not in settings_used]
        for setting in settings_to_drop:
            settings.pop(setting)

        return settings
Exemple #3
0
def compare():
    import settings
    settings = settings.settings("packages.json")
    print(settings)
    for key in commands.keys():
        if key not in settings.keys():
            print(key)
Exemple #4
0
def info(argdict: dict, args: list):
    parsedict = {}
    msg = argdict[commands.Locals.message]
    if args == None:
        embed = Embed(title="Information about all commands.", color=0x5a5ec9)
        for module in settings.keys():
            sub = settings.get(module).get("category")
            parsedict.update({sub: [module]}) if parsedict.get(
                sub) == None else parsedict.get(sub).append(module)
        for cat in parsedict.keys():
            embed.add_field(name=cat.upper(),
                            value=MyStrJoin(parsedict.get(cat)),
                            inline=False)
        embed.set_footer(icon_url=msg.author.avatar_url,
                         text=msg.author.name + '#' + msg.author.discriminator)
        return embed
    else:
        module = args[0]
        sub = settings.get(module)
        if sub != None:
            embed = Embed(title="Information about command %s" %
                          module.capitalize(),
                          color=0x5a5ec9)
            for k in sub.keys():
                embed.add_field(name=k.upper(),
                                value="``%s``" % sub.get(k),
                                inline=False)
            embed.set_footer(icon_url=msg.author.avatar_url,
                             text=msg.author.name + '#' +
                             msg.author.discriminator)
            return embed
        else:
            return "No information about command founded."
Exemple #5
0
class AuthSingletonStack:
    __keys__ = settings.keys()

    @staticmethod
    def pop():
        return AuthSingletonStack.__keys__.pop()

    @staticmethod
    def is_empty():
        return len(AuthSingletonStack.__keys__) == 0

    @staticmethod
    def __reset__():
        AuthSingletonStack.__keys__ = settings.keys()
Exemple #6
0
async def set_settings(settings: Dict[str, Tuple[object, datetime]]) -> bool:
    __log_db_function_enter('set_settings', settings=settings)

    utc_now = util.get_utcnow()
    if settings:
        query_lines = []
        args = []
        success = True
        current_settings = await get_settings(settings.keys())
        for setting_name, (value, modified_at) in settings.items():
            query = ''
            column_name = None
            if isinstance(value, bool):
                column_name = 'settingboolean'
                value = util.db_convert_boolean(value)
            elif isinstance(value, int):
                column_name = 'settingint'
            elif isinstance(value, float):
                column_name = 'settingfloat'
            elif isinstance(value, datetime):
                column_name = 'settingtimestamptz'
                value = util.db_convert_timestamp(value)
            else:
                column_name = 'settingtext'
                value = util.db_convert_text(value)
            current_value, db_modify_date = current_settings[setting_name]
            modify_date = db_modify_date or utc_now

            setting_name = util.db_convert_text(setting_name)
            if current_value is None and db_modify_date is None:
                query = f'INSERT INTO settings ({column_name}, modifydate, settingname) VALUES ({value}, \'{modified_at}\', {setting_name});'
            elif current_value != value:
                query = f'UPDATE settings SET {column_name} = {value}, modifydate = \'{modified_at}\' WHERE settingname = {setting_name};'

            if query:
                query_lines.append(query)
                args.extend([value, modified_at, setting_name])
        success = not query_lines or await try_execute('\n'.join(query_lines))
        if success:
            __settings_cache.update(settings)
        return success
    else:
        return True
 def configure(self, settings):
     """Configure engine with settings."""
     for k in settings.keys():
         if hasattr(self, k) and callable(getattr(self,k)):
             getattr(self,k)(settings[k])
Exemple #8
0
def _db_reset_server_setting(guild_id: int, settings: dict) -> bool:
    where = util.db_get_where_string('guildid', guild_id, is_text_type=True)
    set_string = ', '.join([f'{key} = NULL' for key in settings.keys()])
    query = f'UPDATE serversettings SET {set_string} WHERE {where}'
    success = core.db_try_execute(query)
    return success
Exemple #9
0
 def __reset__():
     AuthSingletonStack.__keys__ = settings.keys()
Exemple #10
0
 def configure(self, settings):
     """Configure engine with settings."""
     for k in settings.keys():
         if hasattr(self, k) and callable(getattr(self, k)):
             getattr(self, k)(settings[k])