第十八届全国大学智能车竞赛电子证书打印

01 板制作


打开模板

利用 Acrobat 软件直接打开设计的 AI 文档, 然后另存为 PDF 文件。 再次另存为 PNG 文件。 但是, 实际上将该文件打开的时候始终与源文件存在着视图色差, 具体原因不详。

▲ 图1.1 模板图片

▲ 图1.1 模板图片

最后, 还是直接通过屏幕截屏,最终获得一张 BMP 证书模板

不同组别打印程序

大疆智慧仓储

#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# FINALPRINT.PY                -- by Dr. ZhuoQing 2021-08-26
#
# Note:
#============================================================

from head import *
import cert
import shutil
import openpyxl

#------------------------------------------------------------

group = '大疆智慧仓储'
division = '全国总决赛'
cert.printcount = 110

#scorefile = r'H:\SmartCar\2023\CertPrint\DOP\大疆仓储\大疆天途智能仓储赛项总成绩.xlsx'
scorefile = r'H:\SmartCar\2023\CertPrint\DOP\大疆仓储\大疆天途智能仓储赛项总成绩(1).xlsx'

wb = openpyxl.load_workbook(scorefile, data_only=True)
ws = wb.get_sheet_by_name("职教组")

corders = "零一二三四五六七八九十"

#------------------------------------------------------------
outdir = r'd:\temp\CERTIFCATION'

picdirdef = outdir
if not os.path.isdir(picdirdef):
    os.mkdir(picdirdef)
else:
    shutil.rmtree(picdirdef)
    os.mkdir(picdirdef)

#------------------------------------------------------------
univ = ''
team = ''
award = ''
tstr = ''
sstr = ''
orderN = 0

mentors = []
students = []

flag = 1

#------------------------------------------------------------
for id,a in enumerate(ws):

    astr = [str(aa.value) for aa in a]

    if astr[0].isdigit():
        if len(univ) > 0:

            university = univ
            if orderN <= 3:
                order = '第%s名'%corders[orderN]
            else: order = ''


            printff(id,university, team, mentors, students, award, order)

            if flag > 0:
                cert.printcert(university,
                      team,
                      group,
                      award,
                      order,
                      students,
                      mentors,
                      division,
                      picdir = picdirdef)

        orderN = int(astr[0])
        mentors = []
        students = []
        award = astr[5]

        univ = astr[1].replace('\n','').replace('\r','')
        team = astr[2].replace(' ', '_')

    student = astr[3]
    name = astr[4]

    if student.find('指导') >= 0:
        mentors.append(name)
    elif student.find('学生') >= 0:
        students.append(name)


#------------------------------------------------------------

university = univ
if orderN <= 3:
    order = '第%s名'%corders[orderN]
else: order = ''

printff(id,university, team, mentors, students, award, order)

if flag > 0:
    cert.printcert(university,
          team,
          group,
          award,
          order,
          students,
          mentors,
          division,
          picdir = picdirdef)

#------------------------------------------------------------



#------------------------------------------------------------
printf('\a')


#------------------------------------------------------------
#        END OF FILE : FINALPRINT.PY
#============================================================
#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# CERT.PY                      -- by Dr. ZhuoQing 2021-08-25
#
# Note:
#============================================================

from head import *

#------------------------------------------------------------
studentc = [27, 4, 3, 11, 19]        # template, text, award, order, sn

snhead = '○ NCSC2023-09'
text_width = 40

#------------------------------------------------------------
testid = 16

#------------------------------------------------------------
groupdict = {
    
    '负压电磁':'01', '专科电磁':'02', '摄像头':'03',
             '电能接力':'04', '独轮车':'05', '智能视觉':'06',
             '完全模型':'07', '极速越野':'08', '单车越野':'09',
             '声音信标':10, '百度智慧交通':11,
             '讯飞智慧农业':12, '大疆智慧仓储':13,
             '航天智慧物流':14,  'MicroPython工程挑战赛':15,
             '高中':16, '初中':17, '小学':18,
             '特邀表演':19}

awarddict = {
    
    '一等奖':1, '二等奖':2, '三等奖':3, '优胜奖':4, '专项奖':5, '挑战赛':6}

def printjpg(cid, filename):
    tspsaveimagerange(cid, filename,0, 50)
    printff(cid, filename)


#------------------------------------------------------------
def getsnstr(group, award, num):
    printff(group, award, num)
    return '%s-%s-%d%03d'%(snhead, groupdict[group], awarddict[award], num)

#------------------------------------------------------------
def boldheitifont(s):
    rets = ''
    for c in s:
        rets = rets + '\h\*%s\.'%c
    return rets

def boldfont(s):
    rets = ''
    for c in s:
        rets = rets + '\*%s\.'%c
    return rets

def settextwidth(s, width):
    rets = ''
    count = 0

    for id,c in enumerate(s):
        if c in '\\ . * h'.split():
            rets = rets + c
            if c == '.':
                if count >= width - 1:
                    count -= (width - 1)
                    rets += '\r\n'

            continue

        if ord(c) < 127: count += 1
        else: count += 2


        appendcount = 0
        if s[id:id+4] == '2022':
            if count+3 >= width:
                rets += '\r\n'
                count = 0

        rets = rets + c
        if count+appendcount >= width:
            count -= width
            rets += '\r\n'

    return rets


#------------------------------------------------------------
def setstudenttext(tid, university, student, group, division):
    global text_width

    university = boldheitifont(university)
    student = boldheitifont(student)
    group = boldfont(group)

    setstr = '%s %s 同学在2023年第十八届全国大学生智能车竞赛中荣获%s%s组比赛'%(university, student, division,group)
    setstr = settextwidth(setstr, text_width)

    tspsettext(tid, setstr)

def setmentortext(tid, university, mentor, team, group, division):
    global text_width

    university = boldheitifont(university)
    mentor = boldheitifont(mentor)

    nameflag = 0
    if len(team) > 0:
        if team[-1] == '队':
            nameflag = 1

    team = boldfont(team)

    if nameflag == 0:
        team = team + ' 队'
    else: team = team + ''


    group = boldfont(group)

    setstr = '%s %s 教师指导%s在2023年第十八届全国大学生智能车竞赛中荣获%s%s组比赛'%(university, mentor, team, division, group)
    setstr = settextwidth(setstr, text_width)
    tspsettext(tid, setstr)


def setteamtext(tid, university, team, group, division):
    global text_width

    university = boldheitifont(university)

    nameflag = 0
    if len(team) > 0:
        if team[-1] == '队':
            nameflag = 1

    team = boldfont(team)

    if nameflag == 0:
        team = team + ' 队'
    else: team = team + ''

    group = boldfont(group)

    setstr = '%s %s在2023年第十八届全国大学生智能车竞赛中荣获%s%s组比赛'%(university, team, division, group)
    setstr = settextwidth(setstr, text_width)
    tspsettext(tid, setstr)


def setawardstr(awardstr):
    tspsettext(studentc[2], awardstr)

def setorderstr(orderstr):
    if len(orderstr) > 2:
        orderstr = '(%s)'%orderstr
    else: orderstr = ' '

    printf(orderstr)

    tspsettext(studentc[3], orderstr)

#------------------------------------------------------------
printcount = 0
def printcert(university, team, group, award, order, students,
              mentors, division = '全国总决赛', picdir=r'd:\temp'):

    global printcount

    printcount += 1
    snstr = getsnstr(group, award, printcount)
    tspsettext(studentc[4], snstr)


    #--------------------------------------------------------

    if len(order) < 2: order = ''

    team = team.replace('"', '')

    setawardstr(award)
    setorderstr(order)

    setteamtext(studentc[1], university, team, group, division)
    tsprv()
    outfn = os.path.join(picdir, '%s_%s_%s.jpg'%(university, team, group))
    printjpg(studentc[0], outfn)

    for s in students:
        printcount += 1
        snstr = getsnstr(group, award, printcount)
        tspsettext(studentc[4], snstr)

        setstudenttext(studentc[1], university, s, group, division)
        tsprv()
        outfn = '%s\\%s_%s_%s.jpg'%(picdir, university, team, s)
        printjpg(studentc[0], outfn)

    for s in mentors:
        printcount += 1
        snstr = getsnstr(group, award, printcount)
        tspsettext(studentc[4], snstr)

        setmentortext(studentc[1], university, s, team, group, division)
        tsprv()
        outfn = '%s\\%s_%s_%s.jpg'%(picdir, university, team, s)
        printjpg(studentc[0], outfn)



#------------------------------------------------------------
if __name__ == "__main__":

    outdir = r'd:\temp\CERTIFCATION'
    if not os.path.isdir(outdir):
        os.mkdir(outdir)

    sstr = ['银杏', '红桃']
    mstr = ['金鱼', '银鱼']

    printcert('大红枣大学', '风火轮四轮', '讯飞智慧农业', '一等奖', '第一名', sstr, mstr, picdir=outdir)

    printf('\a')


#------------------------------------------------------------
#        END OF FILE : CERT.PY
#============================================================

工程挑战赛

#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# FINALPRINT.PY                -- by Dr. ZhuoQing 2021-08-26
#
# Note:
#============================================================

from head import *
import cert
import shutil
import openpyxl

#------------------------------------------------------------

group = 'MicroPython 编程车模现场挑战赛'
division = '全国总决赛'
cert.printcount = 110

scorefile = r'H:\SmartCar\2023\CertPrint\DOP\工程挑战赛\MicroPython现场挑战赛成绩单.xlsx'
wb = openpyxl.load_workbook(scorefile, data_only=True)
ws = wb.get_sheet_by_name("Sheet1")

corders = "零一二三四五六七八九十"

#------------------------------------------------------------
outdir = r'd:\temp\CERTIFCATION'

picdirdef = outdir
if not os.path.isdir(picdirdef):
    os.mkdir(picdirdef)
else:
    shutil.rmtree(picdirdef)
    os.mkdir(picdirdef)

#------------------------------------------------------------
for id,a in enumerate(ws):

    astr = [str(aa.value) for aa in a]

#   printf(astr)
    if not astr[0].isdigit(): continue


    university = astr[2]
    team = astr[3]

    mentors = [s for s in astr[5].split() if len(s) >= 2 and s != 'None']
    students = [s for s in astr[4].split() if len(s) >= 2 and s != 'None']
    N = int(astr[0])
    award = '团体第%s名'%(corders[N])

    order = ''


    printff(id,university, team, mentors, students, award, order)

#    continue

    cert.printcert(university,
              team,
              group,
              award,
              order,
              students,
              mentors,
              division,
              picdir = picdirdef)

    printf('\a')
#    break

#------------------------------------------------------------
printf('\a')


#------------------------------------------------------------
#        END OF FILE : FINALPRINT.PY
#============================================================
#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# CERT.PY                      -- by Dr. ZhuoQing 2021-08-25
#
# Note:
#============================================================

from head import *

#------------------------------------------------------------
studentc = [27, 4, 3, 11, 19]        # template, text, award, order, sn

snhead = '○ NCSC2023-09'
text_width = 40

#------------------------------------------------------------
testid = 16

#------------------------------------------------------------
groupdict = {
    
    '负压电磁':'01', '专科电磁':'02', '摄像头':'03',
             '电能接力':'04', '独轮车':'05', '智能视觉':'06',
             '完全模型':'07', '极速越野':'08', '单车越野':'09',
             '声音信标':10, '百度智慧交通':11,
             '讯飞智慧农业':12, '大疆智慧物流':13,
             '航天智慧物流':14,  'MicroPython工程挑战赛':15,
             '高中':16, '初中':17, '小学':18,
             '特邀表演':19, '智能巡线竞速':20, '机械大师拼装':21}

awarddict = {
    
    '一等奖':1, '二等奖':2, '三等奖':3, '优胜奖':4, '专项奖':5, '挑战赛':6}

def printjpg(cid, filename):
    tspsaveimagerange(cid, filename,0, 50)
    printff(cid, filename)


#------------------------------------------------------------
def getsnstr(group, award, num):
    printff(group, award, num)
    return '%s-%s-%d%03d'%(snhead, 0, 111, num)

#------------------------------------------------------------
def boldheitifont(s):
    rets = ''
    for c in s:
        rets = rets + '\h\*%s\.'%c
    return rets

def boldfont(s):
    rets = ''
    for c in s:
        rets = rets + '\*%s\.'%c
    return rets

def settextwidth(s, width):
    rets = ''
    count = 0

    for id,c in enumerate(s):
        if c in '\\ . * h'.split():
            rets = rets + c
            if c == '.':
                if count >= width - 1:
                    count -= (width - 1)
                    rets += '\r\n'

            continue

        if ord(c) < 127: count += 1
        else: count += 2


        appendcount = 0
        if s[id:id+4] == '2022':
            if count+3 >= width:
                rets += '\r\n'
                count = 0

        rets = rets + c
        if count+appendcount >= width:
            count -= width
            rets += '\r\n'

    return rets


#------------------------------------------------------------
def setstudenttext(tid, university, student, group, division):
    global text_width

    university = boldheitifont(university)
    student = boldheitifont(student)
    group = boldfont(group)

    setstr = '%s %s 同学在2023年第十八届全国大学生智能车竞赛中荣获%s%s组比赛'%(university, student, division,group)
    setstr = settextwidth(setstr, text_width)

    tspsettext(tid, setstr)

def setmentortext(tid, university, mentor, team, group, division):
    global text_width

    university = boldheitifont(university)
    mentor = boldheitifont(mentor)

    nameflag = 0
    if len(team) > 0:
        if team[-1] == '队':
            nameflag = 1

    team = boldfont(team)

    if nameflag == 0:
        team = team + ' 队'
    else: team = team + ''


    group = boldfont(group)

    setstr = '%s %s 教师指导%s在2023年第十八届全国大学生智能车竞赛中荣获%s%s组比赛'%(university, mentor, team, division,group)
    setstr = settextwidth(setstr, text_width)
    tspsettext(tid, setstr)


def setteamtext(tid, university, team, group, division):
    global text_width

    university = boldheitifont(university)

    nameflag = 0
    if len(team) > 0:
        if team[-1] == '队':
            nameflag = 1

    team = boldfont(team)

    if nameflag == 0:
        team = team + ' 队'
    else: team = team + ''

    group = boldfont(group)

    setstr = '%s %s在2023年第十八届全国大学生智能车竞赛中荣获%s%s组比赛'%(university, team, division, group)
    setstr = settextwidth(setstr, text_width)
    tspsettext(tid, setstr)


def setawardstr(awardstr):
    tspsettext(studentc[2], awardstr)

def setorderstr(orderstr):
    if len(orderstr) > 2:
        orderstr = '(%s)'%orderstr
    else: orderstr = ' '

    printf(orderstr)

    tspsettext(studentc[3], orderstr)

#------------------------------------------------------------
printcount = 0
def printcert(university, team, group, award, order, students,
              mentors, division = '全国总决赛', picdir=r'd:\temp'):

    global printcount

    printcount += 1
    snstr = getsnstr(group, award, printcount)
    tspsettext(studentc[4], snstr)

    if len(order) < 2: order = ''

    team = team.replace('"', '')

    setawardstr(award)
    setorderstr(order)

    setteamtext(studentc[1], university, team, group, division)
    tsprv()
    outfn = os.path.join(picdir, '%s_%s_%s.jpg'%(university, team, group))
    printjpg(studentc[0], outfn)

    for s in students:
        printcount += 1
        snstr = getsnstr(group, award, printcount)
        tspsettext(studentc[4], snstr)

        setstudenttext(studentc[1], university, s, group, division)
        tsprv()
        outfn = '%s\\%s_%s_%s.jpg'%(picdir, university, team, s)
        printjpg(studentc[0], outfn)

    for s in mentors:
        printcount += 1
        snstr = getsnstr(group, award, printcount)
        tspsettext(studentc[4], snstr)

        setmentortext(studentc[1], university, s, team, group, division)
        tsprv()
        outfn = '%s\\%s_%s_%s.jpg'%(picdir, university, team, s)
        printjpg(studentc[0], outfn)



#------------------------------------------------------------
if __name__ == "__main__":

    outdir = r'd:\temp\CERTIFCATION'
    if not os.path.isdir(outdir):
        os.mkdir(outdir)

    sstr = ['银杏', '红桃']
    mstr = ['金鱼', '银鱼']

    printcert('大红枣大学', '风火轮四轮', '讯飞智慧农业', '一等奖', '第一名', sstr, mstr, picdir=outdir)

    printf('\a')


#------------------------------------------------------------
#        END OF FILE : CERT.PY
#============================================================

航天三院

#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# FINALPRINT.PY                -- by Dr. ZhuoQing 2021-08-26
#
# Note:
#============================================================

from head import *
import cert
import shutil
import openpyxl

#------------------------------------------------------------

group = '航天智慧物流'
division = '全国总决赛'
cert.printcount = 110

scorefile = r'H:\SmartCar\2023\CertPrint\DOP\航天三院\获奖信息-航天组20230825.xlsx'
wb = openpyxl.load_workbook(scorefile, data_only=True)
ws = wb.get_sheet_by_name("Sheet1")

corders = "零一二三四五六七八九十"

#------------------------------------------------------------
outdir = r'd:\temp\CERTIFCATION'

picdirdef = outdir
if not os.path.isdir(picdirdef):
    os.mkdir(picdirdef)
else:
    shutil.rmtree(picdirdef)
    os.mkdir(picdirdef)

flag = 1
#------------------------------------------------------------
for id,a in enumerate(ws):

    astr = [str(aa.value) for aa in a]


    if not astr[0].isdigit(): continue

    university = astr[1]
    team = astr[2]

    mentors = [s for s in astr[8:10] if len(s) >= 2 and s != 'None']
    students = [s for s in astr[3:8] if len(s) >= 2 and s != 'None']

    #--------------------------------------------------------
    award = astr[11]

    if award.find('赛') > 0:
        aa = award.split('赛')
        division = aa[0]+'赛'
        award = aa[1]
    else:
        award = ''

    order = ''
    printff(id,university, team, mentors, students, award, order, division)

    if flag > 0 and len(award) > 0:
        cert.printcert(university,
              team,
              group,
              award,
              order,
              students,
              mentors,
              division,
              picdir = picdirdef)




    #--------------------------------------------------------
    printf('\a')


#    break

#------------------------------------------------------------
printf('\a')


#------------------------------------------------------------
#        END OF FILE : FINALPRINT.PY
#============================================================
#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# CERT.PY                      -- by Dr. ZhuoQing 2021-08-25
#
# Note:
#============================================================

from head import *

#------------------------------------------------------------
studentc = [27, 4, 3, 11, 19]        # template, text, award, order, sn

snhead = '○ NCSC2023-09'
text_width = 40

#------------------------------------------------------------
testid = 16

#------------------------------------------------------------
groupdict = {
    
    '负压电磁':'01', '专科电磁':'02', '摄像头':'03',
             '电能接力':'04', '独轮车':'05', '智能视觉':'06',
             '完全模型':'07', '极速越野':'08', '单车越野':'09',
             '声音信标':10, '百度智慧交通':11,
             '讯飞智慧农业':12, '大疆智慧物流':13,
             '航天智慧物流':14,  'MicroPython工程挑战赛':15,
             '高中':16, '初中':17, '小学':18,
             '特邀表演':19}

awarddict = {
    
    '一等奖':1, '二等奖':2, '三等奖':3, '优胜奖':4, '专项奖':5, '挑战赛':6}

def printjpg(cid, filename):
    tspsaveimagerange(cid, filename,0, 50)
    printff(cid, filename)


#------------------------------------------------------------
def getsnstr(group, award, num):
    printff(group, award, num)
    return '%s-%s-%d%03d'%(snhead, groupdict[group], 0, num)

#------------------------------------------------------------
def boldheitifont(s):
    rets = ''
    for c in s:
        rets = rets + '\h\*%s\.'%c
    return rets

def boldfont(s):
    rets = ''
    for c in s:
        rets = rets + '\*%s\.'%c
    return rets

def settextwidth(s, width):
    rets = ''
    count = 0

    for id,c in enumerate(s):
        if c in '\\ . * h'.split():
            rets = rets + c
            if c == '.':
                if count >= width - 1:
                    count -= (width - 1)
                    rets += '\r\n'

            continue

        if ord(c) < 127: count += 1
        else: count += 2


        appendcount = 0
        if s[id:id+4] == '2022':
            if count+3 >= width:
                rets += '\r\n'
                count = 0

        rets = rets + c
        if count+appendcount >= width:
            count -= width
            rets += '\r\n'

    return rets


#------------------------------------------------------------
def setstudenttext(tid, university, student, group, division):
    global text_width

    university = boldheitifont(university)
    student = boldheitifont(student)
    group = boldfont(group)

    setstr = '%s %s 同学在2023年第十八届全国大学生智能车竞赛中荣获%s%s组比赛'%(university, student, division,group)
    setstr = settextwidth(setstr, text_width)

    tspsettext(tid, setstr)

def setmentortext(tid, university, mentor, team, group, division):
    global text_width

    university = boldheitifont(university)
    mentor = boldheitifont(mentor)

    nameflag = 0
    if len(team) > 0:
        if team[-1] == '队':
            nameflag = 1

    team = boldfont(team)

    if nameflag == 0:
        team = team + ' 队'
    else: team = team + ''


    group = boldfont(group)

    setstr = '%s %s 教师指导%s在2023年第十八届全国大学生智能车竞赛中荣获%s%s组比赛'%(university, mentor, team, division,group)
    setstr = settextwidth(setstr, text_width)
    tspsettext(tid, setstr)


def setteamtext(tid, university, team, group, division):
    global text_width

    university = boldheitifont(university)

    nameflag = 0
    if len(team) > 0:
        if team[-1] == '队':
            nameflag = 1

    team = boldfont(team)

    if nameflag == 0:
        team = team + ' 队'
    else: team = team + ''

    group = boldfont(group)

    setstr = '%s %s在2023年第十八届全国大学生智能车竞赛中荣获%s%s组比赛'%(university, team, division, group)
    setstr = settextwidth(setstr, text_width)
    tspsettext(tid, setstr)


def setawardstr(awardstr):
    tspsettext(studentc[2], awardstr)

def setorderstr(orderstr):
    if len(orderstr) > 2:
        orderstr = '(%s)'%orderstr
    else: orderstr = ' '

    printf(orderstr)

    tspsettext(studentc[3], orderstr)

#------------------------------------------------------------
printcount = 0
def printcert(university, team, group, award, order, students,
              mentors, division = '全国总决赛', picdir=r'd:\temp'):

    global printcount

    printcount += 1
    snstr = getsnstr(group, award, printcount)
    tspsettext(studentc[4], snstr)

    if len(order) < 2: order = ''

    team = team.replace('"', '')

    setawardstr(award)
    setorderstr(order)

    setteamtext(studentc[1], university, team, group, division)
    tsprv()
    outfn = os.path.join(picdir, '%s_%s_%s.jpg'%(university, team, group))
    printjpg(studentc[0], outfn)

    for s in students:
        printcount += 1
        snstr = getsnstr(group, award, printcount)
        tspsettext(studentc[4], snstr)

        setstudenttext(studentc[1], university, s, group, division)
        tsprv()
        outfn = '%s\\%s_%s_%s.jpg'%(picdir, university, team, s)
        printjpg(studentc[0], outfn)

    for s in mentors:
        printcount += 1
        snstr = getsnstr(group, award, printcount)
        tspsettext(studentc[4], snstr)

        setmentortext(studentc[1], university, s, team, group, division)
        tsprv()
        outfn = '%s\\%s_%s_%s.jpg'%(picdir, university, team, s)
        printjpg(studentc[0], outfn)



#------------------------------------------------------------
if __name__ == "__main__":

    outdir = r'd:\temp\CERTIFCATION'
    if not os.path.isdir(outdir):
        os.mkdir(outdir)

    sstr = ['银杏', '红桃']
    mstr = ['金鱼', '银鱼']

    printcert('大红枣大学', '风火轮四轮', '讯飞智慧农业', '一等奖', '第一名', sstr, mstr, picdir=outdir)

    printf('\a')


#------------------------------------------------------------
#        END OF FILE : CERT.PY
#============================================================

科大讯飞

#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# FINALPRINT.PY                -- by Dr. ZhuoQing 2021-08-26
#
# Note:
#============================================================

from head import *
import cert
import shutil
import openpyxl

#------------------------------------------------------------

group = '讯飞智慧农业'
division = '全国总决赛'
cert.printcount = 110

scorefile = r'H:\SmartCar\2023\CertPrint\DOP\科大讯飞\【国赛获奖汇总版】第十八届全国大学生智能汽车竞赛-讯飞创意组.xlsx'
wb = openpyxl.load_workbook(scorefile, data_only=True)
ws = wb.get_sheet_by_name("职业院校组别")

corders = "零一二三四五六七八九十"

#------------------------------------------------------------
outdir = r'd:\temp\CERTIFCATION'

picdirdef = outdir
if not os.path.isdir(picdirdef):
    os.mkdir(picdirdef)
else:
    shutil.rmtree(picdirdef)
    os.mkdir(picdirdef)

#------------------------------------------------------------
for id,a in enumerate(ws):

    astr = [str(aa.value) for aa in a]

#    printf(astr)

    if not astr[0].isdigit(): continue

    university = astr[3]
    team = astr[4]

    mentors = [s for s in astr[5:7] if len(s) >= 2]
    students = [s for s in astr[7:12] if len(s) >= 2]
    award = astr[2]

    N = int(astr[0])
    if N >= 0 and N <= 3:
        order = '第%s名'%corders[N]
    else: order = ''


    printff(id,university, team, mentors, students, award, order)

#    continue

    cert.printcert(university,
              team,
              group,
              award,
              order,
              students,
              mentors,
              division,
              picdir = picdirdef)

    printf('\a')
#    break

#------------------------------------------------------------
printf('\a')


#------------------------------------------------------------
#        END OF FILE : FINALPRINT.PY
#============================================================
#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# CERT.PY                      -- by Dr. ZhuoQing 2021-08-25
#
# Note:
#============================================================

from head import *

#------------------------------------------------------------
studentc = [27, 4, 3, 11, 19]        # template, text, award, order, sn

snhead = '○ NCSC2023-09'
text_width = 40

#------------------------------------------------------------
testid = 16

#------------------------------------------------------------
groupdict = {
    
    '负压电磁':'01', '专科电磁':'02', '摄像头':'03',
             '电能接力':'04', '独轮车':'05', '智能视觉':'06',
             '完全模型':'07', '极速越野':'08', '单车越野':'09',
             '声音信标':10, '百度智慧交通':11,
             '讯飞智慧农业':12, '大疆智慧物流':13,
             '航天智慧物流':14,  'MicroPython工程挑战赛':15,
             '高中':16, '初中':17, '小学':18,
             '特邀表演':19}

awarddict = {
    
    '一等奖':1, '二等奖':2, '三等奖':3, '优胜奖':4, '专项奖':5, '挑战赛':6}

def printjpg(cid, filename):
    tspsaveimagerange(cid, filename,0, 50)
    printff(cid, filename)


#------------------------------------------------------------
def getsnstr(group, award, num):
    printff(group, award, num)
    return '%s-%s-%d%03d'%(snhead, groupdict[group], awarddict[award], num)

#------------------------------------------------------------
def boldheitifont(s):
    rets = ''
    for c in s:
        rets = rets + '\h\*%s\.'%c
    return rets

def boldfont(s):
    rets = ''
    for c in s:
        rets = rets + '\*%s\.'%c
    return rets

def settextwidth(s, width):
    rets = ''
    count = 0

    for id,c in enumerate(s):
        if c in '\\ . * h'.split():
            rets = rets + c
            if c == '.':
                if count >= width - 1:
                    count -= (width - 1)
                    rets += '\r\n'

            continue

        if ord(c) < 127: count += 1
        else: count += 2


        appendcount = 0
        if s[id:id+4] == '2022':
            if count+3 >= width:
                rets += '\r\n'
                count = 0

        rets = rets + c
        if count+appendcount >= width:
            count -= width
            rets += '\r\n'

    return rets


#------------------------------------------------------------
def setstudenttext(tid, university, student, group, division):
    global text_width

    university = boldheitifont(university)
    student = boldheitifont(student)
    group = boldfont(group)

    setstr = '%s %s 同学在2023年第十八届全国大学生智能车竞赛中荣获%s%s组比赛'%(university, student, division,group)
    setstr = settextwidth(setstr, text_width)

    tspsettext(tid, setstr)

def setmentortext(tid, university, mentor, team, group, division):
    global text_width

    university = boldheitifont(university)
    mentor = boldheitifont(mentor)

    nameflag = 0
    if len(team) > 0:
        if team[-1] == '队':
            nameflag = 1

    team = boldfont(team)

    if nameflag == 0:
        team = team + ' 队'
    else: team = team + ''


    group = boldfont(group)

    setstr = '%s %s 教师指导%s在2023年第十八届全国大学生智能车竞赛中荣获%s%s组比赛'%(university, mentor, team, division,group)
    setstr = settextwidth(setstr, text_width)
    tspsettext(tid, setstr)


def setteamtext(tid, university, team, group, division):
    global text_width

    university = boldheitifont(university)

    nameflag = 0
    if len(team) > 0:
        if team[-1] == '队':
            nameflag = 1

    team = boldfont(team)

    if nameflag == 0:
        team = team + ' 队'
    else: team = team + ''

    group = boldfont(group)

    setstr = '%s %s在2023年第十八届全国大学生智能车竞赛中荣获%s%s组比赛'%(university, team, division, group)
    setstr = settextwidth(setstr, text_width)
    tspsettext(tid, setstr)


def setawardstr(awardstr):
    tspsettext(studentc[2], awardstr)

def setorderstr(orderstr):
    if len(orderstr) > 2:
        orderstr = '(%s)'%orderstr
    else: orderstr = ' '

    printf(orderstr)

    tspsettext(studentc[3], orderstr)

#------------------------------------------------------------
printcount = 0
def printcert(university, team, group, award, order, students,
              mentors, division = '全国总决赛', picdir=r'd:\temp'):

    global printcount

    printcount += 1
    snstr = getsnstr(group, award, printcount)
    tspsettext(studentc[4], snstr)

    if len(order) < 2: order = ''

    team = team.replace('"', '')

    setawardstr(award)
    setorderstr(order)

    setteamtext(studentc[1], university, team, group, division)
    tsprv()
    outfn = os.path.join(picdir, '%s_%s_%s.jpg'%(university, team, group))
    printjpg(studentc[0], outfn)

    for s in students:
        printcount += 1
        snstr = getsnstr(group, award, printcount)
        tspsettext(studentc[4], snstr)

        setstudenttext(studentc[1], university, s, group, division)
        tsprv()
        outfn = '%s\\%s_%s_%s.jpg'%(picdir, university, team, s)
        printjpg(studentc[0], outfn)

    for s in mentors:
        printcount += 1
        snstr = getsnstr(group, award, printcount)
        tspsettext(studentc[4], snstr)

        setmentortext(studentc[1], university, s, team, group, division)
        tsprv()
        outfn = '%s\\%s_%s_%s.jpg'%(picdir, university, team, s)
        printjpg(studentc[0], outfn)



#------------------------------------------------------------
if __name__ == "__main__":

    outdir = r'd:\temp\CERTIFCATION'
    if not os.path.isdir(outdir):
        os.mkdir(outdir)

    sstr = ['银杏', '红桃']
    mstr = ['金鱼', '银鱼']

    printcert('大红枣大学', '风火轮四轮', '讯飞智慧农业', '一等奖', '第一名', sstr, mstr, picdir=outdir)

    printf('\a')


#------------------------------------------------------------
#        END OF FILE : CERT.PY
#============================================================

特邀表演

#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# FINALPRINT.PY                -- by Dr. ZhuoQing 2021-08-26
#
# Note:
#============================================================

from head import *
import cert
import shutil
import openpyxl

#------------------------------------------------------------

group = '特邀表演'
division = '全国总决赛'
cert.printcount = 110

corders = "零一二三四五六七八九十"

#------------------------------------------------------------


strid = 28
strall = tspgetdopstring(strid).split('\r\n')


#------------------------------------------------------------
outdir = r'd:\temp\CERTIFCATION'

picdirdef = outdir
if not os.path.isdir(picdirdef):
    os.mkdir(picdirdef)
else:
    shutil.rmtree(picdirdef)
    os.mkdir(picdirdef)

#------------------------------------------------------------
for id,s in enumerate(zip(strall[0::2], strall[1::2])):

    ss = s[0].split('组')
    group = ss[0]
    award = ss[1]

    ss = s[1].split('\t')
    university = ss[1]
    team = ss[2]

    sss = ss[3].replace(',', ' ').replace(',', ' ')
    sdim = sss.split(' ')
    students = [ssss for ssss in sdim if len(ssss.replace(' ', '')) > 0]

    sss = ss[4].replace(',', ' ').replace(',', ' ')
    sdim = sss.split(' ')
    mentors = [ssss for ssss in sdim if len(ssss.replace(' ', '')) > 0]

    order = ''


    printff(id,university, team, mentors, students, award, order)

#    continue

    cert.printcert(university,
              team,
              group,
              award,
              order,
              students,
              mentors,
              division,
              picdir = picdirdef)

    printf('\a')
#    break

#------------------------------------------------------------
printf('\a')


#------------------------------------------------------------
#        END OF FILE : FINALPRINT.PY
#============================================================
#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# CERT.PY                      -- by Dr. ZhuoQing 2021-08-25
#
# Note:
#============================================================

from head import *

#------------------------------------------------------------
studentc = [27, 4, 3, 11, 19]        # template, text, award, order, sn

snhead = '○ NCSC2023-09'
text_width = 40

#------------------------------------------------------------
testid = 16

#------------------------------------------------------------
groupdict = {
    
    '负压电磁':'01', '专科电磁':'02', '摄像头':'03',
             '电能接力':'04', '独轮车':'05', '智能视觉':'06',
             '完全模型':'07', '极速越野':'08', '单车越野':'09',
             '声音信标':10, '百度智慧交通':11,
             '讯飞智慧农业':12, '大疆智慧物流':13,
             '航天智慧物流':14,  'MicroPython工程挑战赛':15,
             '高中':16, '初中':17, '小学':18,
             '特邀表演':19, '智能巡线竞速':20, '机械大师拼装':21}

awarddict = {
    
    '一等奖':1, '二等奖':2, '三等奖':3, '优胜奖':4, '专项奖':5, '挑战赛':6}

def printjpg(cid, filename):
    tspsaveimagerange(cid, filename,0, 50)
    printff(cid, filename)


#------------------------------------------------------------
def getsnstr(group, award, num):
    printff(group, award, num)
    return '%s-%s-%d%03d'%(snhead, 0, 111, num)

#------------------------------------------------------------
def boldheitifont(s):
    rets = ''
    for c in s:
        rets = rets + '\h\*%s\.'%c
    return rets

def boldfont(s):
    rets = ''
    for c in s:
        rets = rets + '\*%s\.'%c
    return rets

def settextwidth(s, width):
    rets = ''
    count = 0

    for id,c in enumerate(s):
        if c in '\\ . * h'.split():
            rets = rets + c
            if c == '.':
                if count >= width - 1:
                    count -= (width - 1)
                    rets += '\r\n'

            continue

        if ord(c) < 127: count += 1
        else: count += 2


        appendcount = 0
        if s[id:id+4] == '2022':
            if count+3 >= width:
                rets += '\r\n'
                count = 0

        rets = rets + c
        if count+appendcount >= width:
            count -= width
            rets += '\r\n'

    return rets


#------------------------------------------------------------
def setstudenttext(tid, university, student, group, division):
    global text_width

    university = boldheitifont(university)
    student = boldheitifont(student)
    group = boldfont(group)

    setstr = '%s %s 同学在2023年第十八届全国大学生智能车竞赛中荣获%s%s组比赛'%(university, student, division,group)
    setstr = settextwidth(setstr, text_width)

    tspsettext(tid, setstr)

def setmentortext(tid, university, mentor, team, group, division):
    global text_width

    university = boldheitifont(university)
    mentor = boldheitifont(mentor)

    nameflag = 0
    if len(team) > 0:
        if team[-1] == '队':
            nameflag = 1

    team = boldfont(team)

    if nameflag == 0:
        team = team + ' 队'
    else: team = team + ''


    group = boldfont(group)

    setstr = '%s %s 教师指导%s在2023年第十八届全国大学生智能车竞赛中荣获%s%s组比赛'%(university, mentor, team, division,group)
    setstr = settextwidth(setstr, text_width)
    tspsettext(tid, setstr)


def setteamtext(tid, university, team, group, division):
    global text_width

    university = boldheitifont(university)

    nameflag = 0
    if len(team) > 0:
        if team[-1] == '队':
            nameflag = 1

    team = boldfont(team)

    if nameflag == 0:
        team = team + ' 队'
    else: team = team + ''

    group = boldfont(group)

    setstr = '%s %s在2023年第十八届全国大学生智能车竞赛中荣获%s%s组比赛'%(university, team, division, group)
    setstr = settextwidth(setstr, text_width)
    tspsettext(tid, setstr)


def setawardstr(awardstr):
    tspsettext(studentc[2], awardstr)

def setorderstr(orderstr):
    if len(orderstr) > 2:
        orderstr = '(%s)'%orderstr
    else: orderstr = ' '

    printf(orderstr)

    tspsettext(studentc[3], orderstr)

#------------------------------------------------------------
printcount = 0
def printcert(university, team, group, award, order, students,
              mentors, division = '全国总决赛', picdir=r'd:\temp'):

    global printcount

    printcount += 1
    snstr = getsnstr(group, award, printcount)
    tspsettext(studentc[4], snstr)

    if len(order) < 2: order = ''

    team = team.replace('"', '')

    setawardstr(award)
    setorderstr(order)

    setteamtext(studentc[1], university, team, group, division)
    tsprv()
    outfn = os.path.join(picdir, '%s_%s_%s.jpg'%(university, team, group))
    printjpg(studentc[0], outfn)

    for s in students:
        printcount += 1
        snstr = getsnstr(group, award, printcount)
        tspsettext(studentc[4], snstr)

        setstudenttext(studentc[1], university, s, group, division)
        tsprv()
        outfn = '%s\\%s_%s_%s.jpg'%(picdir, university, team, s)
        printjpg(studentc[0], outfn)

    for s in mentors:
        printcount += 1
        snstr = getsnstr(group, award, printcount)
        tspsettext(studentc[4], snstr)

        setmentortext(studentc[1], university, s, team, group, division)
        tsprv()
        outfn = '%s\\%s_%s_%s.jpg'%(picdir, university, team, s)
        printjpg(studentc[0], outfn)



#------------------------------------------------------------
if __name__ == "__main__":

    outdir = r'd:\temp\CERTIFCATION'
    if not os.path.isdir(outdir):
        os.mkdir(outdir)

    sstr = ['银杏', '红桃']
    mstr = ['金鱼', '银鱼']

    printcert('大红枣大学', '风火轮四轮', '讯飞智慧农业', '一等奖', '第一名', sstr, mstr, picdir=outdir)

    printf('\a')


#------------------------------------------------------------
#        END OF FILE : CERT.PY
#============================================================

英飞凌企业奖

#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# FINALPRINT.PY                -- by Dr. ZhuoQing 2021-08-26
#
# Note:
#============================================================

from head import *
import cert
import shutil
import openpyxl

#------------------------------------------------------------

group = '特邀表演'
division = '全国总决赛'
cert.printcount = 110

corders = "零一二三四五六七八九十"

#------------------------------------------------------------


strid = 29
strall = tspgetdopstring(strid).split('\r\n')


#------------------------------------------------------------
outdir = r'd:\temp\CERTIFCATION'

picdirdef = outdir
if not os.path.isdir(picdirdef):
    os.mkdir(picdirdef)
else:
    shutil.rmtree(picdirdef)
    os.mkdir(picdirdef)

#------------------------------------------------------------
for id,s in enumerate(strall):

    ss = s.split('\t')
#    printf(ss)


    group = '英飞凌杯技术创新'
    award = ss[0].replace("英飞凌杯.", "")

    if award.find('赛') > 0:
        award = award.split('赛')[-1]
    if award.find('杯') > 0:
        award = award.split('杯')[-1]


    university = ss[1]
    team = ss[2]

    sss = ss[3].replace(',', ' ').replace(',', ' ')
    sdim = sss.split(' ')
    students = [ssss for ssss in sdim if len(ssss.replace(' ', '')) > 0]

    sss = ss[4].replace(',', ' ').replace(',', ' ')
    sdim = sss.split(' ')
    mentors = [ssss for ssss in sdim if len(ssss.replace(' ', '')) > 0]

    order = ''


    printff(id,university, team, mentors, students, award, order)

#    continue

    cert.printcert(university,
              team,
              group,
              award,
              order,
              students,
              mentors,
              division,
              picdir = picdirdef)

    printf('\a')
#    break

#------------------------------------------------------------
printf('\a')


#------------------------------------------------------------
#        END OF FILE : FINALPRINT.PY
#============================================================
#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# CERT.PY                      -- by Dr. ZhuoQing 2021-08-25
#
# Note:
#============================================================

from head import *

#------------------------------------------------------------
studentc = [27, 4, 3, 11, 19]        # template, text, award, order, sn

snhead = '○ NCSC2023-09'
text_width = 40

#------------------------------------------------------------
testid = 16

#------------------------------------------------------------
groupdict = {
    
    '负压电磁':'01', '专科电磁':'02', '摄像头':'03',
             '电能接力':'04', '独轮车':'05', '智能视觉':'06',
             '完全模型':'07', '极速越野':'08', '单车越野':'09',
             '声音信标':10, '百度智慧交通':11,
             '讯飞智慧农业':12, '大疆智慧物流':13,
             '航天智慧物流':14,  'MicroPython工程挑战赛':15,
             '高中':16, '初中':17, '小学':18,
             '特邀表演':19, '智能巡线竞速':20, '机械大师拼装':21}

awarddict = {
    
    '一等奖':1, '二等奖':2, '三等奖':3, '优胜奖':4, '专项奖':5, '挑战赛':6}

def printjpg(cid, filename):
    tspsaveimagerange(cid, filename,0, 50)
    printff(cid, filename)


#------------------------------------------------------------
def getsnstr(group, award, num):
    printff(group, award, num)
    return '%s-%s-%d%03d'%(snhead, 0, 111, num)

#------------------------------------------------------------
def boldheitifont(s):
    rets = ''
    for c in s:
        rets = rets + '\h\*%s\.'%c
    return rets

def boldfont(s):
    rets = ''
    for c in s:
        rets = rets + '\*%s\.'%c
    return rets

def settextwidth(s, width):
    rets = ''
    count = 0

    for id,c in enumerate(s):
        if c in '\\ . * h'.split():
            rets = rets + c
            if c == '.':
                if count >= width - 1:
                    count -= (width - 1)
                    rets += '\r\n'

            continue

        if ord(c) < 127: count += 1
        else: count += 2


        appendcount = 0
        if s[id:id+4] == '2022':
            if count+3 >= width:
                rets += '\r\n'
                count = 0

        rets = rets + c
        if count+appendcount >= width:
            count -= width
            rets += '\r\n'

    return rets


#------------------------------------------------------------
def setstudenttext(tid, university, student, group, division):
    global text_width

    university = boldheitifont(university)
    student = boldheitifont(student)
    group = boldfont(group)

    setstr = '%s %s 同学在2023年第十八届全国大学生智能车竞赛中荣获%s%s组比赛'%(university, student, division,group)
    setstr = settextwidth(setstr, text_width)

    tspsettext(tid, setstr)

def setmentortext(tid, university, mentor, team, group, division):
    global text_width

    university = boldheitifont(university)
    mentor = boldheitifont(mentor)

    nameflag = 0
    if len(team) > 0:
        if team[-1] == '队':
            nameflag = 1

    team = boldfont(team)

    if nameflag == 0:
        team = team + ' 队'
    else: team = team + ''


    group = boldfont(group)

    setstr = '%s %s 教师指导%s在2023年第十八届全国大学生智能车竞赛中荣获%s%s组比赛'%(university, mentor, team, division,group)
    setstr = settextwidth(setstr, text_width)
    tspsettext(tid, setstr)


def setteamtext(tid, university, team, group, division):
    global text_width

    university = boldheitifont(university)

    nameflag = 0
    if len(team) > 0:
        if team[-1] == '队':
            nameflag = 1

    team = boldfont(team)

    if nameflag == 0:
        team = team + ' 队'
    else: team = team + ''

    group = boldfont(group)

    setstr = '%s %s在2023年第十八届全国大学生智能车竞赛中荣获%s%s组比赛'%(university, team, division, group)
    setstr = settextwidth(setstr, text_width)
    tspsettext(tid, setstr)


def setawardstr(awardstr):
    tspsettext(studentc[2], awardstr)

def setorderstr(orderstr):
    if len(orderstr) > 2:
        orderstr = '(%s)'%orderstr
    else: orderstr = ' '

    printf(orderstr)

    tspsettext(studentc[3], orderstr)

#------------------------------------------------------------
printcount = 0
def printcert(university, team, group, award, order, students,
              mentors, division = '全国总决赛', picdir=r'd:\temp'):

    global printcount

    printcount += 1
    snstr = getsnstr(group, award, printcount)
    tspsettext(studentc[4], snstr)

    if len(order) < 2: order = ''

    team = team.replace('"', '')

    setawardstr(award)
    setorderstr(order)

    setteamtext(studentc[1], university, team, group, division)
    tsprv()
    outfn = os.path.join(picdir, '%s_%s_%s.jpg'%(university, team, group))
    printjpg(studentc[0], outfn)

    for s in students:
        printcount += 1
        snstr = getsnstr(group, award, printcount)
        tspsettext(studentc[4], snstr)

        setstudenttext(studentc[1], university, s, group, division)
        tsprv()
        outfn = '%s\\%s_%s_%s.jpg'%(picdir, university, team, s)
        printjpg(studentc[0], outfn)

    for s in mentors:
        printcount += 1
        snstr = getsnstr(group, award, printcount)
        tspsettext(studentc[4], snstr)

        setmentortext(studentc[1], university, s, team, group, division)
        tsprv()
        outfn = '%s\\%s_%s_%s.jpg'%(picdir, university, team, s)
        printjpg(studentc[0], outfn)



#------------------------------------------------------------
if __name__ == "__main__":

    outdir = r'd:\temp\CERTIFCATION'
    if not os.path.isdir(outdir):
        os.mkdir(outdir)

    sstr = ['银杏', '红桃']
    mstr = ['金鱼', '银鱼']

    printcert('大红枣大学', '风火轮四轮', '讯飞智慧农业', '一等奖', '第一名', sstr, mstr, picdir=outdir)

    printf('\a')


#------------------------------------------------------------
#        END OF FILE : CERT.PY
#============================================================

中小学生组

#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# FINALPRINT.PY                -- by Dr. ZhuoQing 2021-08-26
#
# Note:
#============================================================

from head import *
import cert
import shutil
import openpyxl

#------------------------------------------------------------

group = '讯飞智慧农业'
division = '全国总决赛'
cert.printcount = 110

scorefile = r'H:\SmartCar\2023\CertPrint\DOP\中小学组\2023国赛中小学获奖名单.xlsx'
wb = openpyxl.load_workbook(scorefile, data_only=True)
ws = wb.get_sheet_by_name("Sheet1")

corders = "零一二三四五六七八九十"

#------------------------------------------------------------
outdir = r'd:\temp\CERTIFCATION'

picdirdef = outdir
if not os.path.isdir(picdirdef):
    os.mkdir(picdirdef)
else:
    shutil.rmtree(picdirdef)
    os.mkdir(picdirdef)

#------------------------------------------------------------
for id,a in enumerate(ws):

    astr = [str(aa.value) for aa in a]

#    printf(astr)
    if not astr[0].isdigit(): continue

    university = astr[2]
    team = astr[3]
    group = astr[1] + '(%s)'%astr[5]

    mentors = [s for s in astr[4:5] if len(s) >= 2 and s != 'None']
    students = [s for s in astr[6:8] if len(s) >= 2 and s != 'None']
    award = astr[8]

    order = ''


    printff(id,university, team, mentors, students, award, order)

#    continue

    cert.printcert(university,
              team,
              group,
              award,
              order,
              students,
              mentors,
              division,
              picdir = picdirdef)

    printf('\a')
#    break

#------------------------------------------------------------
printf('\a')


#------------------------------------------------------------
#        END OF FILE : FINALPRINT.PY
#============================================================
#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# CERT.PY                      -- by Dr. ZhuoQing 2021-08-25
#
# Note:
#============================================================

from head import *

#------------------------------------------------------------
studentc = [27, 4, 3, 11, 19]        # template, text, award, order, sn

snhead = '○ NCSC2023-09'
text_width = 40

#------------------------------------------------------------
testid = 16

#------------------------------------------------------------
groupdict = {
    
    '负压电磁':'01', '专科电磁':'02', '摄像头':'03',
             '电能接力':'04', '独轮车':'05', '智能视觉':'06',
             '完全模型':'07', '极速越野':'08', '单车越野':'09',
             '声音信标':10, '百度智慧交通':11,
             '讯飞智慧农业':12, '大疆智慧物流':13,
             '航天智慧物流':14,  'MicroPython工程挑战赛':15,
             '高中':16, '初中':17, '小学':18,
             '特邀表演':19, '智能巡线竞速':20, '机械大师拼装':21}

awarddict = {
    
    '一等奖':1, '二等奖':2, '三等奖':3, '优胜奖':4, '专项奖':5, '挑战赛':6}

def printjpg(cid, filename):
    tspsaveimagerange(cid, filename,0, 50)
    printff(cid, filename)


#------------------------------------------------------------
def getsnstr(group, award, num):
    printff(group, award, num)
    return '%s-%s-%d%03d'%(snhead, 0, awarddict[award], num)

#------------------------------------------------------------
def boldheitifont(s):
    rets = ''
    for c in s:
        rets = rets + '\h\*%s\.'%c
    return rets

def boldfont(s):
    rets = ''
    for c in s:
        rets = rets + '\*%s\.'%c
    return rets

def settextwidth(s, width):
    rets = ''
    count = 0

    for id,c in enumerate(s):
        if c in '\\ . * h'.split():
            rets = rets + c
            if c == '.':
                if count >= width - 1:
                    count -= (width - 1)
                    rets += '\r\n'

            continue

        if ord(c) < 127: count += 1
        else: count += 2


        appendcount = 0
        if s[id:id+4] == '2022':
            if count+3 >= width:
                rets += '\r\n'
                count = 0

        rets = rets + c
        if count+appendcount >= width:
            count -= width
            rets += '\r\n'

    return rets


#------------------------------------------------------------
def setstudenttext(tid, university, student, group, division):
    global text_width

    university = boldheitifont(university)
    student = boldheitifont(student)
    group = boldfont(group)

    setstr = '%s %s 同学在2023年第十八届全国大学生智能车竞赛中荣获%s%s组比赛'%(university, student, division,group)
    setstr = settextwidth(setstr, text_width)

    tspsettext(tid, setstr)

def setmentortext(tid, university, mentor, team, group, division):
    global text_width

    university = boldheitifont(university)
    mentor = boldheitifont(mentor)

    nameflag = 0
    if len(team) > 0:
        if team[-1] == '队':
            nameflag = 1

    team = boldfont(team)

    if nameflag == 0:
        team = team + ' 队'
    else: team = team + ''


    group = boldfont(group)

    setstr = '%s %s 教师指导%s在2023年第十八届全国大学生智能车竞赛中荣获%s%s组比赛'%(university, mentor, team, division,group)
    setstr = settextwidth(setstr, text_width)
    tspsettext(tid, setstr)


def setteamtext(tid, university, team, group, division):
    global text_width

    university = boldheitifont(university)

    nameflag = 0
    if len(team) > 0:
        if team[-1] == '队':
            nameflag = 1

    team = boldfont(team)

    if nameflag == 0:
        team = team + ' 队'
    else: team = team + ''

    group = boldfont(group)

    setstr = '%s %s在2023年第十八届全国大学生智能车竞赛中荣获%s%s组比赛'%(university, team, division, group)
    setstr = settextwidth(setstr, text_width)
    tspsettext(tid, setstr)


def setawardstr(awardstr):
    tspsettext(studentc[2], awardstr)

def setorderstr(orderstr):
    if len(orderstr) > 2:
        orderstr = '(%s)'%orderstr
    else: orderstr = ' '

    printf(orderstr)

    tspsettext(studentc[3], orderstr)

#------------------------------------------------------------
printcount = 0
def printcert(university, team, group, award, order, students,
              mentors, division = '全国总决赛', picdir=r'd:\temp'):

    global printcount

    printcount += 1
    snstr = getsnstr(group, award, printcount)
    tspsettext(studentc[4], snstr)

    if len(order) < 2: order = ''

    team = team.replace('"', '')

    setawardstr(award)
    setorderstr(order)

    setteamtext(studentc[1], university, team, group, division)
    tsprv()
    outfn = os.path.join(picdir, '%s_%s_%s.jpg'%(university, team, group))
    printjpg(studentc[0], outfn)

    for s in students:
        printcount += 1
        snstr = getsnstr(group, award, printcount)
        tspsettext(studentc[4], snstr)

        setstudenttext(studentc[1], university, s, group, division)
        tsprv()
        outfn = '%s\\%s_%s_%s.jpg'%(picdir, university, team, s)
        printjpg(studentc[0], outfn)

    for s in mentors:
        printcount += 1
        snstr = getsnstr(group, award, printcount)
        tspsettext(studentc[4], snstr)

        setmentortext(studentc[1], university, s, team, group, division)
        tsprv()
        outfn = '%s\\%s_%s_%s.jpg'%(picdir, university, team, s)
        printjpg(studentc[0], outfn)



#------------------------------------------------------------
if __name__ == "__main__":

    outdir = r'd:\temp\CERTIFCATION'
    if not os.path.isdir(outdir):
        os.mkdir(outdir)

    sstr = ['银杏', '红桃']
    mstr = ['金鱼', '银鱼']

    printcert('大红枣大学', '风火轮四轮', '讯飞智慧农业', '一等奖', '第一名', sstr, mstr, picdir=outdir)

    printf('\a')


#------------------------------------------------------------
#        END OF FILE : CERT.PY
#============================================================

猜你喜欢

转载自blog.csdn.net/zhuoqingjoking97298/article/details/132484685