示例#1
0
def generatecfromobj(excel_file, pobj, pvalue):
    removefile("./.tmp")
    removefile("./" + excel_file)
    object_parse_childs(pobj, pvalue)

    wb = Workbook(style_compression=2)
    sheet = wb.add_sheet('CWMP-USP')
    xlwt.add_palette_colour("custom_colour_yellow", 0x10)
    xlwt.add_palette_colour("custom_colour_green", 0x20)
    xlwt.add_palette_colour("custom_colour_grey", 0x30)
    wb.set_colour_RGB(0x10, 255, 255, 153)
    wb.set_colour_RGB(0x20, 102, 205, 170)
    wb.set_colour_RGB(0x30, 153, 153, 153)

    style_title = xlwt.easyxf(
        'pattern: pattern solid, fore_colour custom_colour_grey;'
        'font: bold 1, color black;'
        'alignment: horizontal center;')
    sheet.write(0, 0, 'OBJ/PARAM/OPERATE', style_title)
    sheet.write(0, 1, 'Protocols', style_title)
    sheet.write(0, 2, 'Supported', style_title)

    i = 0
    file = open("./.tmp", "r")
    for line in file:
        param = line.split("::")
        i += 1

        if param[3] == "object":
            style_name = xlwt.easyxf(
                'pattern: pattern solid, fore_colour custom_colour_yellow')
            style = xlwt.easyxf(
                'pattern: pattern solid, fore_colour custom_colour_yellow;'
                'alignment: horizontal center;')
        elif param[3] == "operate":
            style_name = xlwt.easyxf(
                'pattern: pattern solid, fore_colour custom_colour_green')
            style = xlwt.easyxf(
                'pattern: pattern solid, fore_colour custom_colour_green;'
                'alignment: horizontal center;')
        else:
            style_name = None
            style = xlwt.easyxf('alignment: horizontal center;')

        if style_name != None:
            sheet.write(i, 0, param[0], style_name)
        else:
            sheet.write(i, 0, param[0])

        sheet.write(i, 1, param[1], style)
        sheet.write(i, 2, param[2], style)

    sheet.col(0).width = 1300 * 20
    sheet.col(1).width = 175 * 20
    sheet.col(2).width = 175 * 20
    wb.save(excel_file)
    removefile("./.tmp")
示例#2
0
def build_excel_shit(Stock1):

    #Workbook is created
    wb = Workbook()

    # add new colour to palette and set RGB colour value
    xlwt.add_palette_colour("custom_colour", 0x21)
    wb.set_colour_RGB(0x21, 1, 183, 2)
    # now you can use the colour in styles
    sheet1 = wb.add_sheet('Sheet 1')
    style = xlwt.easyxf('pattern: pattern solid, fore_colour custom_colour')

    sheet1.write(1, 0, 'Sales')
    sheet1.write(2, 0, 'Current Ratio')
    sheet1.write(3, 0, 'P/E')
    sheet1.write(4, 0, 'Graham Multiplier ')
    sheet1.write(5, 0, 'Eps Growth')
    sheet1.write(7, 0, 'ROE')
    sheet1.write(8, 0, 'ROI')

    if (Stock1.total_revenue[4] > 350000000):
        sheet1.write(1, 1, Stock1.total_revenue[4], style)
    else:
        sheet1.write(1, 1, Stock1.total_revenue[4])

    if (Stock1.current_ratio) > 2:
        sheet1.write(2, 1, Stock1.current_ratio, style)
    else:
        sheet1.write(2, 1, Stock1.current_ratio)

    if (Stock1.p_e) > 5 and (Stock1.p_e) < 15:
        sheet1.write(3, 1, Stock1.p_e, style)
    else:
        sheet1.write(3, 1, Stock1.p_e)

    if (Stock1.graham_multiplier) < 22:
        sheet1.write(4, 1, Stock1.graham_multiplier, style)
    else:
        sheet1.write(4, 1, Stock1.graham_multiplier)

    if (Stock1.eps_growth[4]) > 0.3:
        sheet1.write(5, 1, Stock1.eps_growth[4], style)
    else:
        sheet1.write(5, 1, Stock1.eps_growth[4])

    if (Stock1.return_on_equity) > 15:
        sheet1.write(7, 1, Stock1.return_on_equity, style)
    else:
        sheet1.write(7, 1, Stock1.return_on_equity)

    if (Stock1.return_on_invested_capital) > 15:
        sheet1.write(8, 1, Stock1.return_on_invested_capital, style)
    else:
        sheet1.write(8, 1, Stock1.return_on_invested_capital)

    wb.save('xlwt example.xls')
示例#3
0
class ExcelCalidadArgos():
    def __init__(self, ruta, nombreArchivo):
        self.ruta = ruta
        self.nombreArchivo = nombreArchivo
        self.wb = Workbook()
        self.save_workbook
        self.sheet = None

    def save_workbook(self):
        self.wb.save(self.ruta + '//' + self.nombreArchivo + '.xls')

    def add_sheet(self, sheet_name, list_columns, list_data, style_tittle,
                  desc_Validacion):
        self.sheet = self.wb.add_sheet(sheet_name)

        self.add_write(0, round(len(list_columns) / 2), desc_Validacion,
                       style_tittle)
        self.add_write(0,
                       round(len(list_columns) / 2) + 1, desc_Validacion,
                       style_tittle)
        desc_Validacion
        li_Row = 1
        li_Column = 0
        for col in list_columns:
            self.add_write(li_Row, li_Column, col, style_tittle)
            li_Column += 1

        li_Row += 1
        for row in list_data:
            li_Column = 0
            for data in row:
                self.add_write(li_Row, li_Column, data)
                li_Column += 1
            li_Row += 1

        return self.sheet

    def add_write(self, row, column, content, style=''):

        if len(style) > 0:
            xlwt.add_palette_colour("custom_colour", 0x21)
            self.wb.set_colour_RGB(0x21, 200, 200, 100)
            l_style = xlwt.easyxf(style)
            self.sheet.write(row, column, content, l_style)
        else:
            self.sheet.write(row, column, content)

    def add_write_all_row(self, content, row=0, column=0, style=''):

        for column, heading in enumerate(content, column):
            self.sheet.write(row, column, heading)
示例#4
0
def collection(file_name):
    quartz_file = open('../data/' + file_name, 'r')
    save_file_name = '../data/test_' + time.strftime(
        '%Y.%m.%d', time.localtime(time.time())) + '.xls'
    if os.path.exists(save_file_name):
        os.remove(save_file_name)

    line_lines = quartz_file.readlines()

    xls = Workbook(encoding='utf-8')
    sheet = xls.add_sheet('trigger_bpm')
    # 生成表头
    sheet.write(0, 0, "a")
    sheet.write(0, 1, "b")
    sheet.write(0, 2, "c")
    sheet.write(0, 3, "d")
    sheet.write(0, 4, "e")
    xls.set_colour_RGB(8, 169, 169, 169)

    for i in range(0, line_lines.__len__()):
        line = line_lines[i]

        line_list = line.split('|')
        id = line_list[0]
        name = line_list[1]
        _id = line_list[2]
        enable = line_list[3]
        quartz = line_list[4]

        if id in test_list:
            continue
        sheet.write(i + 1, 0, id)
        sheet.write(i + 1, 1, name)
        sheet.write(i + 1, 2, _id)
        sheet.write(i + 1, 3, enable)
        sheet.write(i + 1, 4, quartz)

        if not line:
            break

    xls.save(save_file_name)
    quartz_file.close()
示例#5
0
文件: actions.py 项目: Giackgamba/l4s
def new_xlwt_colored_workbook():
    """
    Get an Xlwt Workbook with the custom colors.

    :return: xlwt Woorkbook
    """
    new_workbook = XWorkbook(encoding="UTF-8")
    new_workbook.set_colour_RGB(0x21, 139, 31, 63)
    new_workbook.set_colour_RGB(0x22, 255, 255, 255)
    new_workbook.set_colour_RGB(0x23, 31, 85, 111)
    add_palette_colour("custom_colour", 0x21)
    add_palette_colour("white", 0x22)
    add_palette_colour("blue", 0x23)
    return new_workbook
示例#6
0
def xuat_bao_cao_SV(TW_dstk, masv):
    wb = Workbook()
    xlwt.add_palette_colour("custom_colour", 0x21)
    wb.set_colour_RGB(0x21, 251, 228, 228)
    sheet = wb.add_sheet('sheet 1')
    style = xlwt.easyxf('font: bold off, color black;\
                            borders: top_color black, bottom_color black, right_color black, left_color black,\
                                     left thin, right thin, top thin, bottom thin;\
                            pattern: pattern solid, fore_color white;')
    style1 = xlwt.easyxf('font: bold on, color black, height 260;\
                               borders: top_color black, bottom_color black, right_color black, left_color black,\
                                        left thin, right thin, top thin, bottom thin;\
                               pattern: pattern solid,  fore_color custom_colour;\
                             align: vertical center, horizontal center;')

    style2 = xlwt.easyxf('font: bold on, color black;\
                            borders: top_color black, bottom_color black, right_color black, left_color black,\
                                     left thin, right thin, top thin, bottom thin;\
                            pattern: pattern solid, fore_color yellow;')
    style3 = xlwt.easyxf('font: bold on, color black;\
                            borders: top_color black, bottom_color black, right_color black, left_color black,\
                                     left thin, right thin, top thin, bottom thin;\
                            pattern: pattern solid, fore_color white;')
    cot = 5
    hang = 1
    ttSinhVien = XLDL.xldl_SinhVien.layThonTinSinhVien(masv.split(' ')[0])
    sheet.write_merge(0, 1, 1, 3, "BÁO CÁO THỐNG KÊ ĐIỂM DANH", style1)
    sheet.write_merge(2, 2, 0, 1, "Mã sinh viên: " + ttSinhVien[0], style2)
    sheet.write_merge(2, 2, 2, 4, "Họ và tên: " + ttSinhVien[1], style2)
    sheet.write_merge(2, 2, 5, 6, "Giới tính: " + ttSinhVien[2], style2)
    sheet.write_merge(2, 2, 7, 8, "Địa chỉ: " + str(ttSinhVien[3]), style2)

    sum = 0
    for row in range(TW_dstk.rowCount()):
        sum = sum + int(TW_dstk.item(row, 3).text())
    sheet.write_merge(2, 2, 9, 10, "Tổng vắng: " + str(sum), style2)

    heder = [
        "STT", "Mã lớp học", "Tên lớp học", "Tên môn học", "Tổng vắng",
        "Số buổi học", "Tỉ lệ đi học(%)"
    ]
    for i in range(len(heder)):  # ghi các herder
        cwidth = sheet.col(i).width  # lấy độ rộng hiện tại của column
        if (len(str(heder[i])) * 367) > cwidth:
            sheet.col(i).width = (len(str(heder[i])) * 367)
        sheet.write(4, 0 + i, str(heder[i]), style3)

    for row in range(TW_dstk.rowCount()):
        sheet.write(cot + row, 0, row + 1, style)
        for col in range(TW_dstk.columnCount()):
            # auto chỉnh size của cột
            cwidth = sheet.col(col).width  # lấy độ rộng hiện tại của column
            if (len(TW_dstk.item(row, col).text()) * 367) > cwidth:
                sheet.col(col +
                          1).width = (len(TW_dstk.item(row, col).text()) * 367)
            if col == 4 or col == 3:
                sheet.write(cot + row, hang + col,
                            int(TW_dstk.item(row, col).text()), style)
            elif col == 5:
                sheet.write(cot + row, hang + col,
                            float(TW_dstk.item(row, col).text()), style)
            else:
                sheet.write(cot + row, hang + col,
                            TW_dstk.item(row, col).text(), style)
    wb.save('bao_cao_SinhVien_' + masv + '.xls')
示例#7
0
def xuat_bao_cao(TW_dstk, malophoc, nam):
    wb = Workbook()
    xlwt.add_palette_colour("custom_colour", 0x21)
    wb.set_colour_RGB(0x21, 251, 228, 228)
    sheet = wb.add_sheet('sheet 1')
    style = xlwt.easyxf('font: bold off, color black;\
                         borders: top_color black, bottom_color black, right_color black, left_color black,\
                                  left thin, right thin, top thin, bottom thin;\
                         pattern: pattern solid, fore_color white;')
    style1 = xlwt.easyxf('font: bold on, color black, height 260;\
                            borders: top_color black, bottom_color black, right_color black, left_color black,\
                                     left thin, right thin, top thin, bottom thin;\
                            pattern: pattern solid,  fore_color custom_colour;\
                          align: vertical center, horizontal center;')

    style2 = xlwt.easyxf('font: bold on, color black;\
                         borders: top_color black, bottom_color black, right_color black, left_color black,\
                                  left thin, right thin, top thin, bottom thin;\
                         pattern: pattern solid, fore_color yellow;')
    style3 = xlwt.easyxf('font: bold on, color black;\
                         borders: top_color black, bottom_color black, right_color black, left_color black,\
                                  left thin, right thin, top thin, bottom thin;\
                         pattern: pattern solid, fore_color white;')
    cot = 5
    hang = 1
    ttlophoc = XLDL.xldl_LopHoc.layThonTinLopHoc(malophoc.split(' ')[0])
    # write_merge(top_row, bottom_row, left_col , right_col)
    sheet.write_merge(0, 1, 1, 3, "BÁO CÁO THỐNG KÊ ĐIỂM DANH LỚP HỌC", style1)
    sheet.write(0, 6, "Năm: " + nam)
    sheet.write_merge(2, 2, 0, 1, "Mã lớp học: " + ttlophoc[0], style2)
    sheet.write_merge(2, 2, 2, 3, "Tên lớp học: " + ttlophoc[1], style2)
    sheet.write_merge(2, 2, 4, 6, "Tên giảng viên: " + ttlophoc[2], style2)
    sheet.write_merge(2, 2, 7, 7, "Sỉ số: " + str(ttlophoc[3]), style2)
    sum = 0
    for row in range(TW_dstk.rowCount()):
        sum = sum + int(TW_dstk.item(row, 4).text())
    sheet.write_merge(2, 2, 8, 9, "Tổng vắng: " + str(sum), style2)

    heder = [
        "STT", "Mã sinh viên", "Tên sinh viên", "Lớp hinh hoạt", "giới tính",
        "Tổng vắng", "Tỉ lệ đi học(%)"
    ]
    for i in range(len(heder)):  # ghi các herder
        cwidth = sheet.col(i).width  # lấy độ rộng hiện tại của column
        if (len(str(heder[i])) * 367) > cwidth:
            sheet.col(i).width = (len(str(heder[i])) * 367)
        sheet.write(4, 0 + i, str(heder[i]), style3)

    dsNgay = XLDL.xldl_ThongKe.layDSngayDD(malophoc.split(' ')[0])
    for i in range(len(dsNgay)):  # ghi các cột ngày điểm danh
        cwidth = sheet.col(7 + i).width  # lấy độ rộng hiện tại của column
        if (len(str(dsNgay[i])) * 367) > cwidth:
            sheet.col(7 + i).width = (len(str(dsNgay[i])) * 367)
        sheet.write(4, 7 + i, str(dsNgay[i]), style3)

    for row in range(TW_dstk.rowCount()):
        sheet.write(cot + row, 0, row + 1, style)
        for col in range(TW_dstk.columnCount()):
            # auto chỉnh size của cột
            cwidth = sheet.col(col).width  # lấy độ rộng hiện tại của column
            if (len(TW_dstk.item(row, col).text()) * 367) > cwidth:
                sheet.col(col +
                          1).width = (len(TW_dstk.item(row, col).text()) * 367)

            if col == 4:
                sheet.write(cot + row, hang + col,
                            int(TW_dstk.item(row, col).text()), style)
            elif col == 5:
                sheet.write(cot + row, hang + col,
                            float(TW_dstk.item(row, col).text()), style)
            else:
                sheet.write(cot + row, hang + col,
                            TW_dstk.item(row, col).text(), style)

    wb.save('bao_cao_lopHoc_' + malophoc + '.xls')
示例#8
0
#print(running_mel_extractor_function())

print('')
print('Completed MEL Extractions from TAFs')
print('')

import xlwt
from xlwt import Workbook

# Workbook is created
wb = Workbook()

# add new colour to palette and set RGB colour value for "Surface Icing Types:"
xlwt.add_palette_colour("custom_colour1", 0x21)
wb.set_colour_RGB(0x21, 242, 242, 242)

# add new colour to palette and set RGB colour value for "sn = snow:"
xlwt.add_palette_colour("custom_colour2", 0x22)
wb.set_colour_RGB(0x22, 0, 176, 240)

# add new colour to palette and set RGB colour value for "pl=sleet:"
xlwt.add_palette_colour("custom_colour3", 0x23)
wb.set_colour_RGB(0x23, 0, 176, 80)

#
#hubs_list = mel_list[54:58]
#hubs_list_icao=station_ids[54:58]
#print(hubs_list,hubs_list_icao)
#
#print(mel_list)
示例#9
0
sheet1.write(row, column, 'Share Name')
sheet1.write(row, column + 1, 'Last Date')
sheet1.write(row, column + 2, 'Last Day Closing Price')
sheet1.write(row, column + 3, 'Two Days Back')
sheet1.write(row, column + 4, 'Two Days Back Close Price')
sheet1.write(row, column + 5, 'Profit/Loss')

for key, value in stocks_dict.iteritems():
    row += 1
    sheet1.write(row, column, value.get('company_name'))
    sheet1.write(row, column + 1, value.get('top_1').get('date'))
    sheet1.write(row, column + 2, value.get('top_1').get('close'))
    sheet1.write(row, column + 3, value.get('top_2').get('date'))
    sheet1.write(row, column + 4, value.get('top_2').get('close'))

    if not value.get('profit'):
        xlwt.add_palette_colour("custom_colour", 0x08)
        wb.set_colour_RGB(0x08, 255, 000, 000)
        message = 'Loss'
    else:
        xlwt.add_palette_colour("custom_colour", 0x21)
        wb.set_colour_RGB(0x21, 000, 255, 000)
        message = 'Profit'
    style = xlwt.easyxf('pattern: pattern solid, fore_colour custom_colour')
    sheet1.write(row, column + 5, message, style)
    column = 0
    row += 1

wb.save('Trade.xls')
示例#10
0
def generate_comparison(list_experiments):
    row = easyxf('pattern: pattern solid, fore_colour blue')
    col = easyxf('pattern: pattern solid, fore_colour green')
    header = easyxf(
        'font: bold True; pattern: pattern solid, fore_colour dark_red')
    book = Workbook()
    xlwt.add_palette_colour("dark_red", 0x21)
    book.set_colour_RGB(0x21, 150, 0, 0)

    attributes = ['AVG_DEV', 'MIN_DEV', 'MAX_DEV', 'VAR_DEV', 'FITNESS']

    overview_sheets = []
    for attr in attributes:
        sheet1 = book.add_sheet("Overview %s" % attr, cell_overwrite_ok=True)
        overview_sheets.append(sheet1)

    #from random import randint
    #for x in xrange(1, num_uavs+1):
    #for y in xrange(1, num_samples+1):
    #style = None
    #val = x*y
    #if val < 25:
    #style = easyxf('pattern: pattern solid, fore_colour green')
    #elif val < 50:
    #style = easyxf('pattern: pattern solid, fore_colour white')
    #elif val < 75:
    #style = easyxf('pattern: pattern solid, fore_colour orange')
    #else:
    #style = easyxf('pattern: pattern solid, fore_colour red')
    #sheet1.write(x,y,str(val),style)

    num_uavs = 0
    num_steps = 0
    for experiment in list_experiments:
        exp_num_uavs = experiment.config.getint(GLOBAL_SECTION,
                                                "num_receivers")
        exp_num_steps = experiment.config.getint(GENOTYPE_SECTION,
                                                 "receiver_step_count")

        if num_uavs < exp_num_uavs:
            num_uavs = exp_num_uavs
        if num_steps < exp_num_steps:
            num_steps = exp_num_steps

        best_phenome = experiment.get_phenome(100, 0, "FITNESS", True)
        if best_phenome is None:
            continue
        for attr, sheet in zip(attributes, overview_sheets):
            value = best_phenome[attr]
            value = round(value, 2)
            cell_value = None
            image_path = os.path.join(experiment.experiment_folder,
                                      "figure_best_predictions",
                                      "generation_100.jpg")
            image_path_abs = os.path.join(
                os.path.dirname(os.path.abspath(__file__)), image_path)
            cell_value = Formula('HYPERLINK("file://' + image_path_abs + '";' +
                                 str(value) + ')')

            sheet.write(exp_num_steps, exp_num_uavs, cell_value)

    for sheet in overview_sheets:
        sheet.write(0, 0, "# samples/UAVs", header)

    for x in xrange(1, num_steps + 1):
        for sheet in overview_sheets:
            sheet.write(x, 0, str(x), header)
    for y in xrange(1, num_uavs + 1):
        for sheet in overview_sheets:
            sheet.write(0, y, str(y), header)
    #c = 0
    #for experiment in list_experiments:
    #sheet = book.add_sheet(str(c),cell_overwrite_ok=True)
    #for gen in xrange(11):
    #image_path = os.path.join(experiment.experiment_folder, "figure_best_predictions", "generation_" + str(max(gen*10,1)) + ".jpg")
    #import Image
    #try:
    #im = Image.open("./" + image_path)
    ##open_image(image_path)
    #im.save("temp.bmp", "BMP")
    #except:
    #continue

    #sheet.insert_bitmap("temp.bmp", gen*17+1, 0, scale_x = 0.5, scale_y= 0.5)

    #c += 1
    book.save(os.path.join(experiment_base_folder, 'overview.xls'))
示例#11
0
def export_excel(story_map, file_name, title=None):
    colors = Story.objects.filter(
        theme__story_map=story_map
    ).order_by('color').values("color")
    # we could use distinct here but as we want to support
    # sqlite, we use list(set(x)) instead.
    color_list = [c['color'] for c in colors]
    color_list = list(set(color_list))
    file_name = u"{0}.xls".format(slugify(file_name))
    response = HttpResponse(content_type='application/vnd.ms-excel')
    response['Content-Disposition'] = \
        'attachment; filename="{0}"'.format(file_name)
    book = Workbook()

    i = 0
    ix = 0x21
    for c in color_list:
        add_palette_colour("board_color_{0}".format(i), ix)
        color = Color(c)
        book.set_colour_RGB(ix,
                            int(color.r * 255),
                            int(color.g * 255),
                            int(color.b * 255))
        ix += 1
        i += 1

    header_style = easyxf(
        'font: name Arial, bold True, height 250;'
        'borders: bottom thin;'
        'alignment: horizontal center;'
        'pattern: pattern solid, fore_colour gray25;',
    )

    sheet1 = book.add_sheet('Board')

    row = 0
    row_head = sheet1.row(row)

    themes = story_map.themes.all()
    index = 1
    for theme in themes:
        row_head.write(index, theme.name, header_style)
        sheet1.col(index).width = 5000
        index += 1

    phase_style = easyxf(
        'alignment: horizontal center, vertical center;'
        'font:  bold True;'
        'border: right thin, top thin;'
        'pattern: pattern solid, fore_colour gray25;'
    )

    row += 1
    for phase in story_map.phases.all():
        max_stories = 1
        index = 1
        for theme in themes:
            stories = phase.stories.filter(theme=theme).all()
            row_index = row
            for story in stories:
                color = "board_color_{0}".format(color_list.index(story.color))
                style = easyxf(
                    'alignment: wrap True, horizontal center, vertical top;'
                    'border: left thin, top thin, right thin, bottom thin;'
                    'pattern: pattern solid, fore_colour {0};'.format(color)
                )
                sheet1.write(row_index, index, story.title, style)
                row_index += 1
            index += 1
            max_stories = max(max_stories, len(stories))
        index = 0
        # write theme name
        sheet1.write_merge(row, (row + max_stories - 1), index, index,
                           phase.name, phase_style)
        row += max_stories
    book.save(response)
    return response
示例#12
0
# excel worksheet font control

import os

from xlwt import Workbook
import xlwt


filepath = r'C:\Codes\Snippets\sample data\output.xlsx'

book = Workbook()
sheet1 = book.add_sheet('font')
# book.add_sheet('Sheet 2')

xlwt.add_palette_colour("custom_colour", 0x21)
book.set_colour_RGB(0x21, 255, 255, 0)

style = xlwt.easyxf('pattern: pattern solid, fore_colour custom_colour')
sheet1.write(0, 0, 'Some text', style)

book.save(filepath)

os.startfile(filepath)
示例#13
0
def generate_comparison(list_experiments):
    row = easyxf('pattern: pattern solid, fore_colour blue')
    col = easyxf('pattern: pattern solid, fore_colour green')
    header = easyxf('font: bold True; pattern: pattern solid, fore_colour dark_red')
    book = Workbook()
    xlwt.add_palette_colour("dark_red", 0x21)
    book.set_colour_RGB(0x21, 150, 0, 0)
    
    attributes = ['AVG_DEV','MIN_DEV','MAX_DEV','VAR_DEV','FITNESS']
    
    overview_sheets = []
    for attr in attributes:
        sheet1 = book.add_sheet("Overview %s" % attr,cell_overwrite_ok=True)
        overview_sheets.append(sheet1)
        
    
            
    #from random import randint
    #for x in xrange(1, num_uavs+1):
        #for y in xrange(1, num_samples+1):
            #style = None
            #val = x*y
            #if val < 25:
                #style = easyxf('pattern: pattern solid, fore_colour green')
            #elif val < 50:
                #style = easyxf('pattern: pattern solid, fore_colour white')
            #elif val < 75: 
                #style = easyxf('pattern: pattern solid, fore_colour orange')
            #else: 
                #style = easyxf('pattern: pattern solid, fore_colour red')
            #sheet1.write(x,y,str(val),style)
            
    num_uavs = 0
    num_steps = 0
    for experiment in list_experiments:
        exp_num_uavs = experiment.config.getint(GLOBAL_SECTION,"num_receivers")
        exp_num_steps = experiment.config.getint(GENOTYPE_SECTION,"receiver_step_count")
        
        if num_uavs < exp_num_uavs:
            num_uavs = exp_num_uavs
        if num_steps < exp_num_steps:
            num_steps = exp_num_steps
        
        best_phenome = experiment.get_phenome(100,0,"FITNESS",True)
        if best_phenome is None:
            continue
        for attr, sheet in zip(attributes, overview_sheets):
            value = best_phenome[attr]
            value = round(value,2)
            cell_value = None
            image_path = os.path.join(experiment.experiment_folder, "figure_best_predictions", "generation_100.jpg")
            image_path_abs = os.path.join(os.path.dirname(os.path.abspath(__file__)), image_path)
            cell_value = Formula('HYPERLINK("file://' + image_path_abs + '";' + str(value) + ')')
            
            sheet.write(exp_num_steps,exp_num_uavs,cell_value)
            
    
    for sheet in overview_sheets:
        sheet.write(0,0,"# samples/UAVs",header)
    
    for x in xrange(1,num_steps+1):
        for sheet in overview_sheets:
            sheet.write(x,0,str(x),header)
    for y in xrange(1,num_uavs+1):
        for sheet in overview_sheets:
            sheet.write(0,y,str(y),header)
    #c = 0
    #for experiment in list_experiments:
        #sheet = book.add_sheet(str(c),cell_overwrite_ok=True)
        #for gen in xrange(11):
            #image_path = os.path.join(experiment.experiment_folder, "figure_best_predictions", "generation_" + str(max(gen*10,1)) + ".jpg")
            #import Image
            #try:
                #im = Image.open("./" + image_path)
                ##open_image(image_path)
                #im.save("temp.bmp", "BMP")
            #except:
                #continue
            
            #sheet.insert_bitmap("temp.bmp", gen*17+1, 0, scale_x = 0.5, scale_y= 0.5)
            
        #c += 1
    book.save(os.path.join(experiment_base_folder,'overview.xls'))
示例#14
0
def generaExcelRankeds(listaPartidas, nombre):
    rutaArchivo = vars.directorioRanked + nombre + "_" + str(datetime.now().strftime("%d_%m_%Y_%H%M")) + ".xls"
    wb = Workbook()
    sheet = wb.add_sheet("Analisis Stats Ranked", cell_overwrite_ok=True)

    # estilos#######
    # color azul
    xlwt.add_palette_colour("custom_green_color", 0x21)
    wb.set_colour_RGB(0x21, 191, 255, 215)
    # color rojo
    xlwt.add_palette_colour("custom_red_color", 0x22)
    wb.set_colour_RGB(0x22, 251, 204, 150)
    styleBold = xlwt.easyxf('font: bold 1')
    styleNormalBlue = xlwt.easyxf(
        'align: vert centre, horiz center; pattern: pattern solid, fore_colour custom_green_color')
    styleNormalRed = xlwt.easyxf(
        'align: vert centre, horiz center; pattern: pattern solid, fore_colour custom_red_color')
    # /estilos######
    #Ancho columnas
    try:
        sheet.col(0).width = 256 * 12
        sheet.col(1).width = 256 * 24
        sheet.col(2).width = 256 * 6
        sheet.col(3).width = 256 * 6
        sheet.col(4).width = 256 * 10
        sheet.col(5).width = 256 * 15
        sheet.col(6).width = 256 * 15
        sheet.col(7).width = 256 * 5
        sheet.col(8).width = 256 * 5
        sheet.col(9).width = 256 * 5
        sheet.col(10).width = 256 * 16
        sheet.col(11).width = 256 * 15
        sheet.col(12).width = 256 * 10
        sheet.col(13).width = 256 * 5
        sheet.col(14).width = 256 * 12
        sheet.col(15).width = 256 * 13
        sheet.col(16).width = 256 * 13
        sheet.col(17).width = 256 * 13
        sheet.col(18).width = 256 * 14
        sheet.col(19).width = 256 * 14
        sheet.col(20).width = 256 * 13
        sheet.col(21).width = 256 * 15
        sheet.col(22).width = 256 * 13
        sheet.col(23).width = 256 * 15
        sheet.col(24).width = 256 * 12
        sheet.col(25).width = 256 * 12
        sheet.col(26).width = 256 * 12
        sheet.col(27).width = 256 * 13
        sheet.col(28).width = 256 * 13
    except ValueError:
        pass
    #Escribir en el excel

    escribeLinea(sheet,vars.titulosPlayerStatsRanked,0,styleBold)
    i = 1
    for stats in listaPartidas:
        if stats[2] == "Win":
            escribeLinea(sheet, stats, i, styleNormalBlue)
        else:
            escribeLinea(sheet, stats, i, styleNormalRed)
        i = i + 2
    wb.save(rutaArchivo)