示例#1
0
def make_a_simulant(sim_info, out_dir):
    sim_id = codenamize(str(uuid.uuid4()), 2, 0)
    simulant = SimulantDescriptionGenerator(0, sim_id, sim_info)
    info = simulant.desriptor()

    with open(os.path.join(out_dir, '{}.json'.format(sim_id)), 'w') as outfile:
        json.dump(info, outfile, indent=2)

    return sim_id
示例#2
0
    def _calc_words_count(maxlength, words_count=2):
        if 5 > maxlength or words_count > (maxlength / 2):
            return codenamize(random.randint(0, 999999999), 0, maxlength, '',
                              True)

        remainder = maxlength % words_count
        word_len = maxlength / words_count
        if remainder == 0:
            # (bloque de palabras, cantidad de palabras, tamaño maximo, join, capitalize)
            return codenamize(random.randint(0, 999999999), words_count - 1,
                              word_len, '', True)
        elif remainder == (words_count - 1):
            # (bloque de palabras, cantidad de palabras, tamaño maximo, join, capitalize)
            return codenamize(random.randint(0, 999999999), words_count - 1,
                              math.trunc(word_len), '_', True)
        else:
            return GroupArtifactInfoBusiness._calc_words_count(
                maxlength=maxlength, words_count=words_count + 1)
 def _create_path():
     adjectives = 0 if end else 1
     parts = ('/data',
              codenamize.codenamize(random.randint(0, sys.maxsize),
                                    adjectives,
                                    join='/'))
     if end:
         parts += (end.replace('-', '_'), )
     return os.path.join(*parts)
示例#4
0
 def _generate_name(cls, prefix=None, slug=True, ids=True, codename=None):
     name = prefix or cls.__name__
     if slug:
         name = slugify(name)
     if ids:
         name += '#{}'.format(next(cls._ids[name]))
     if codename is not None:
         # generates codename like: pushy-idea
         name += ' ({})'.format(codenamize(codename, max_item_chars=5))
     return name
示例#5
0
    def humanize_name(self, name: str, collision_removal: bool = True) -> str:
        new_name = codenamize(name, 3, 0)

        i = 0
        while collision_removal and self.is_already_drawn(new_name):
            print(
                f"Collision found on filename {name} generating {new_name}. Adding 1 to filename."
            )
            # Modify/Create a new name
            tmp_name = name + str(i)

            # Redraw the new name
            new_name = codenamize(tmp_name, 3, 0)
            print(
                f"Collision handled by renaming {name} to {tmp_name} generating {new_name}."
            )

        self.already_generated.add(new_name)
        return new_name
示例#6
0
 def _generate_info_key(hidden_info):
     if hidden_info.random_key_code_word:
         # Si se quiere un codigo que sea legible obtenemos una aleatoriamente
         word_max_length = hidden_info.random_word_maxlength
         # Si esta definido tamaño maximo de palabra la calculamos en base a el
         if hidden_info.random_word_maxlength:
             info_key = GroupArtifactInfoBusiness._calc_words_count(
                 maxlength=word_max_length)
             # Si la clave no llega al maximo especificado rellenamos con tantas eses que sean necesarias
             while len(info_key) < word_max_length:
                 info_key = "{}s".format(info_key)
         else:
             info_key = codenamize(random.randint(0, 999999999))
     else:
         # En el caso de que no se haya especificado preferencia generamos un uuid
         info_key = uuid.uuid4()
     return info_key
示例#7
0
    def __str__(self):
        if self.__pretty_name:
            return self.__pretty_name

        name: List[str] = []
        for word in getattr(self, 'name', '').split('.'):
            name.append(word.capitalize())

        for key, value in getattr(self, 'mods', {}).items():
            # TODO: Fix hack for network mod
            if key == 'port':
                continue

            name.append(' '.join([key.capitalize()] + [str(el).capitalize()
                                                       for el in value]))

        block_name: str = codenamize(id(self), 0)
        name.append('#' + block_name)

        self.__pretty_name = ' '.join(name)

        return self.__pretty_name
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys

from codenamize import codenamize

print(codenamize(sys.argv[1]))
示例#9
0
    nminibatches=1,
    noptepochs=8,
    cliprange=args.cliprange,
    cliprange_vf=None,
    tensorboard_log='./tensorboard/',
)
wandbconfig = model_args.copy()
wandbconfig["salt"] = args.salt
wandbconfig["action_scaling"] = args.action_scaling
wandbconfig["L"] = os.environ["LATTICE_L"]

hashstr = ""
for key, value in wandbconfig.items():
    hashstr = hashstr + str(value)
if args.codename is None:
    args.tag = codenamize(hashstr)
else:
    args.tag = args.codename

episode_length = args.episode_length

if not (args.test):
    if args.wandb_project != "disable":
        import wandb
        wandb.init(id=args.tag,
                   resume='allow',
                   config=wandbconfig,
                   project="cool_final",
                   sync_tensorboard=True)

    try:
示例#10
0
def get_codename(normalized):
    return codenamize(
        hashlib.sha1(normalized.ravel().view(np.uint8)).hexdigest())
示例#11
0
from collections import defaultdict
from codenamize import codenamize
import random

counts = defaultdict(lambda: 0)

for i in range(0, 2760 * 100):
    val = random.randint(0, 999999999999)
    res = codenamize(val, 1, 3, '', True)
    #print "%s %s" % (val, res)
    counts[res] = counts[res] + 1

for k, v in counts.items():
    print("%s %s" % (k, v))
print("Length: %d (expected 2760)" % (len(counts)))

 def _create_name():
     return codenamize.codenamize(obj=random.randint(0, sys.maxsize),
                                  adjectives=0,
                                  max_item_chars=8,
                                  join='-')
示例#13
0
文件: stats.py 项目: hcraT/codenamize
from collections import defaultdict
from codenamize import codenamize
import random

counts = defaultdict(lambda: 0)

for i in range(0, 2760 * 1000):
    val = random.randint(0, 999999999999)
    res = codenamize(val, 1, 3, '', True)
    #print "%s %s" % (val, res)
    counts[res] = counts[res] + 1

for k, v in counts.items():
    print "%s %s" % (k, v)
print "Length: %d (expected 2760)" % (len(counts))

示例#14
0
 def get_name(content, file_suffix: str) -> str:
     return codenamize(hashlib.sha256(content).hexdigest(), 3, 0) + file_suffix
示例#15
0
                        type=str,
                        help='base directory of clothing models',
                        default='data/clothes')
    args = parser.parse_args()

    if not os.path.exists(args.out_dir):
        os.makedirs(args.out_dir)

    if not os.path.exists(args.sim_dir):
        os.makedirs(args.sim_dir)

    textures = find_filepaths(args.textures, 'png')
    poses = get_list(args.pose_list)

    sim_info = {
        'out_path': args.sim_dir,
        'hair_path': args.hairs,
        'clothes_path': args.clothes,
        'textures': textures,
        'poses': poses
    }

    for i in range(args.number):
        sim_id = codenamize(str(uuid.uuid4()), 2, 0)
        simulant = SimulantDescriptionGenerator(i, sim_id, sim_info)
        info = simulant.desriptor()

        with open(os.path.join(args.out_dir, '{}.json'.format(sim_id)),
                  'w') as outfile:
            json.dump(info, outfile, indent=2)