<commit_before>import cStringIO
import json

from flask import Blueprint
from flask import Response
import xlsxwriter

from testrail_reporting.auth.decorators import auth_required
from testrail_reporting.testrail.models import (
    Users, Projects, Milestones, Plans, Suites, Runs, Sections, Cases, Tests,
    Results, CaseTypes, Statuses, Priorities, Configs)

testrail = Blueprint('testrail', __name__)


def _calc_column_width(col, val):
    return '{0}:{0}'.format(chr(col + ord('A')), len(str(val)) + 2)


def _generate_xlsx(filename):
    objects = [Users, CaseTypes, Statuses, Priorities, Projects, Milestones,
               Plans, Configs, Suites, Cases, Sections, Runs, Tests, Results]

    str_io = cStringIO.StringIO()
    workbook = xlsxwriter.Workbook(str_io)
    bold = workbook.add_format({'bold': True})

    for obj in objects:
        row = 1
        worksheet = workbook.add_worksheet(obj.__name__)
        for record in obj.objects:
            col = 0
            for k, v in record.to_mongo().items():
                # TODO(rsalin): auto column width
                # width = _calc_column_width(col, v)
                # worksheet.set_column(width)

                if row == 1:
                    worksheet.write(0, col, k, bold)

                # Remove?
                if isinstance(v, list):
                    v = json.dumps(v)

                worksheet.write(row, col, v)
                col += 1
            row += 1

    workbook.close()
    return str_io.getvalue()


@testrail.route('/download-vghe32yfta98mwtv8oviyd3nqbfeq6dh')
# @auth_required
def index():<commit_msg>Fixes<commit_after>import cStringIO
import json

from flask import Blueprint
from flask import Response
import xlsxwriter

from testrail_reporting.auth.decorators import auth_required
from testrail_reporting.testrail.models import (
    Users, Projects, Milestones, Plans, Suites, Runs, Sections, Cases, Tests,
    Results, CaseTypes, Statuses, Priorities, Configs)

testrail = Blueprint('testrail', __name__)


def _calc_column_width(col, val):
    return '{0}:{0}'.format(chr(col + ord('A')), len(str(val)) + 2)


def _generate_xlsx(filename):
    objects = [Users, CaseTypes, Statuses, Priorities, Projects, Milestones,
               Plans, Configs, Suites, Cases, Sections, Runs, Tests, Results]

    str_io = cStringIO.StringIO()
    workbook = xlsxwriter.Workbook(str_io)
    bold = workbook.add_format({'bold': True})

    for obj in objects:
        row = 1
        worksheet = workbook.add_worksheet(obj.__name__)
        for record in obj.objects:
            col = 0
            record_items = sorted(record.to_mongo().items(),
                                  key=lambda e: e[0])
            for k, v in record_items:
                # TODO(rsalin): auto column width
                # width = _calc_column_width(col, v)
                # worksheet.set_column(width)

                if row == 1:
                    worksheet.write(0, col, k, bold)

                # Remove?
                if isinstance(v, list):
                    v = json.dumps(v)

                worksheet.write(row, col, v)
                col += 1
            row += 1

    workbook.close()
    return str_io.getvalue()


@testrail.route('/download-vghe32yfta98mwtv8oviyd3nqbfeq6dh')
# @auth_required
def index():
{'fraction_non_alphanumeric': 0.10434258142340169, 'fraction_numerical': 0.009951749095295536, 'mean_word_length': 2.381243628950051, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1196330', 'n_tokens_mistral': 1095, 'n_tokens_neox': 999, 'n_words': 252}