Beispiel #1
0
def create_code(uuid, callback_url=None):
    if CodeBatch.objects.filter(uuid=uuid).exists():

        code_batch_obj = CodeBatch.objects.get(uuid=uuid)

        klass = code_batch_obj.klass.name

        if klass == '6x6':
            for i in range(cmagic0.INDEXMAX):
                version = 0

                serial = cmagic0.new_serial(code_batch_obj.batch, i, version)
                text, code, text_str, code_str, blocks = cmagic0.get_colorcode5(code_batch_obj.zone, serial, version)

                hash_code = cmagic0.scramble_textstr(text_str, version)
                hash_code0 = cmagic0.scramble_textstr(text_str, version=0)

                color_blocks = ''.join(map(lambda i: cmagic0.COLORS[i], blocks))

                Code(text=text_str, code=code_str, blocks=color_blocks, hash_code=hash_code,
                     hash_code0=hash_code0, index=i, batch=code_batch_obj).save()

            code_batch_obj.polulated = True
            code_batch_obj.save()

            transaction.commit()

        elif klass == '7x7':
            for i in range(cmagic7.INDEXMAX):
                version = 3

                text, code, text_str, code_str, blocks, color_blocks = cmagic7.get_colorcode6(
                    zone=code_batch_obj.zone,
                    batch=code_batch_obj.batch,
                    index=i
                )
                hash_code = cmagic7.scramble_textstr(text_str, version)
                hash_code0 = cmagic7.scramble_textstr(text_str, version=0)

                Code(text=text_str, code=code_str, blocks=color_blocks, hash_code=hash_code,
                     hash_code0=hash_code0, index=i, batch=code_batch_obj).save()

            code_batch_obj.polulated = True
            code_batch_obj.save()

            transaction.commit()

    if not callback_url is None:
        pass
Beispiel #2
0
    def get_code_6x6():
        n_max_index = cmagic0.INDEXMAX

        n_count = count if count < n_max_index else n_max_index

        index_list = random.sample(range(n_max_index), n_count)

        code_dict_list = []

        if zone <= cmagic0.ZONEMAX and batch <= cmagic0.BATCHMAX:
            for index in index_list:

                t1, t2, text, t4, cstrip = cmagic0.get_colorcode5_ex(zone, cmagic0.new_serial(batch, index))
                sn = cmagic0.scramble_textstr(text)

                code_dict = {
                    'zone': zone,
                    'batch': batch,
                    'index': index,
                    'klass': klass,
                    'blocks': cstrip,
                    'hash': sn
                }

                code_dict_list.append(code_dict)

        return code_dict_list
Beispiel #3
0
def get_random_code_list(zone_batch_info, count=6):
    # zone_batch_info is a list of the dictionary
    # with the following keys:
    #  hash, zone, batch, type

    all_ = []                    # all list to include all code entitiy
    for info in zone_batch_info:
        szone = info.get('zone', '-1')
        sbatch = info.get('batch', '-1')
        sklass = info.get('klass', '6x6')  # by default

        zone = int(szone)
        batch = int(sbatch)

        if zone < 0 or batch < 0:
            continue

        # temporarily diasble 7x7
        if not sklass in ['6x6', '7x7']:
            continue

        if sklass == '6x6' and (batch > MAX_BATCH_1 or zone > MAX_ZONE_1):
            continue

        if sklass == '7x7' and (batch > MAX_BATCH_2 or zone > MAX_ZONE_2):
            continue

        for i in range(cmagic0.INDEXMAX):
            all_.append((zone, batch, i, sklass))

    # Now we have all collections, let's pick random count
    if all_:
        preview_elements = random.sample(all_, count)
    else:
        preview_elements = []

    output = []
    for e in preview_elements:
        zone, batch, i, sklass = e

        #cstrip = None
        #sn = None

        if sklass == '6x6':
            t1, t2, text, t4, cstrip = cmagic0.get_colorcode5_ex(zone, cmagic0.new_serial(batch, i))
            sn = cmagic0.scramble_textstr(text)
        elif sklass == '7x7':
            t1, t2, text, t4, t5, cstrip = cmagic7.get_colorcode6(zone, batch, i)
            sn = cmagic7.scramble_textstr(text, version=3)
        else:
            continue

        code_dict = {
            'zone': zone,
            'batch': batch,
            'index': i,
            'klass': sklass,
            'blocks': cstrip,
            'uuid': sn
        }
        output.append(code_dict)

    return output