def add_test_to_item(item):
    stdin, stdout = '', ''
    description = click.prompt('Description')
    timeout = click.prompt('Timeout (in seconds)', type=int, default=10)
    if click.confirm("Get input and output from files?", default=False):
        while True:
            infname = click.prompt('Path to input file')
            outfname = click.prompt('Path to output file')
            with open(infname, 'r') as infile, open(outfname, 'r') as outfile:
                stdin = infile.read()
                stdout = outfile.read()

                click.echo('\nTest input:\n')
                click.echo(stdin)
                click.echo('\nTest output:\n')
                click.echo(stdout)

                if click.confirm('\nIs this correct?', default=True):
                    break
    else:
        while True:
            stdin, stdout = getTestInOut()
            click.echo('\nTest input:\n')
            click.echo(stdin)
            click.echo('\nTest output:\n')
            click.echo(stdout)

            if click.confirm('\nIs this correct?', default=True):
                break

    t = item.add_test(description, stdin, stdout, timeout)
    click.echo('Created test with id: ' + testserializer.dumps(t.id))
Exemple #2
0
def serialize_homework(hw):
    """
    Unpacks a Homework object into a dictionary for easy JSON parsing.
    :param hw: A Homework item to be unpacked.
    :return: Dictionary containing the Homework along with nested Items and
    Tests.
    """
    items = []
    for item in hw.items:
        tests = []
        for test in item.tests:
            tests.append(
                {
                    'id': testserializer.dumps(test.id),
                    'description': test.description,
                    'input': test.stdin,
                    'timeout': test.timeout
                }
            )

        items.append(
            {
                'id': itemserializer.dumps(item.id),
                'name': item.name,
                'description': item.description,
                'tests': tests
            }
        )

    return {
        'id': hwserializer.dumps(hw.id),
        'name': hw.name,
        'description': hw.description,
        'items': items
    }
Exemple #3
0
def serialize_homework(hw):
    """
    Unpacks a Homework object into a dictionary for easy JSON parsing.
    :param hw: A Homework item to be unpacked.
    :return: Dictionary containing the Homework along with nested Items and
    Tests.
    """
    items = []
    for item in hw.items:
        tests = []
        for test in item.tests:
            tests.append(
                {
                    'id': testserializer.dumps(test.id),
                    'description': test.description,
                    'input': test.stdin,
                    'timeout': test.timeout
                }
            )

        items.append(
            {
                'id': itemserializer.dumps(item.id),
                'name': item.name,
                'description': item.description,
                'tests': tests
            }
        )

    return {
        'id': hwserializer.dumps(hw.id),
        'name': hw.name,
        'description': hw.description,
        'items': items
    }
def add_test_to_item(item):
    stdin, stdout = '', ''
    description = click.prompt('Description')
    timeout = click.prompt('Timeout (in seconds)', type=int, default=10)
    if click.confirm("Get input and output from files?", default=False):
        while True:
            infname = click.prompt('Path to input file')
            outfname = click.prompt('Path to output file')
            with open(infname, 'r') as infile, open(outfname, 'r') as outfile:
                stdin = infile.read()
                stdout = outfile.read()

                click.echo('\nTest input:\n')
                click.echo(stdin)
                click.echo('\nTest output:\n')
                click.echo(stdout)

                if click.confirm('\nIs this correct?', default=True):
                    break
    else:
        while True:
            stdin, stdout = getTestInOut()
            click.echo('\nTest input:\n')
            click.echo(stdin)
            click.echo('\nTest output:\n')
            click.echo(stdout)

            if click.confirm('\nIs this correct?', default=True):
                break

    t = item.add_test(description, stdin, stdout, timeout)
    click.echo('Created test with id: ' + testserializer.dumps(t.id))
Exemple #5
0
    def get(self):
        startdate = datetime.today().date() - timedelta(days=7)
        print(startdate)
        logs = RequestLog.query.filter(
            RequestLog.created > startdate
        ).all()
        result = []

        for log in logs:
            result.append(
                {
                    "client_id": clientserializer.dumps(log.client_id),
                    "test_id": testserializer.dumps(log.test_id),
                    "result": log.result,
                    "error": log.error,
                    "timestamp": log.created.isoformat()
                }
            )

        print(startdate.isoformat())
        return {"results": result, "startdate": startdate.isoformat()}
Exemple #6
0
    def get(self):
        args = self.parser.parse_args()
        if args.get('summary'):
            logs = RequestLog.query.order_by(RequestLog.created).all()

            if len(logs) < 1:
                return {}

            first_d = logs[0].created.date()
            last_d = logs[-1].created.date()

            result = OrderedDict()

            t_date = ddate(first_d.year, first_d.month, first_d.day)
            while t_date != last_d:
                result[str(t_date)] = 0
                t_date += timedelta(days=1)

            for log in logs:
                date = log.created.date()
                sdate = str(date)
                if result.get(sdate):
                    result[sdate] += 1
                else:
                    result[sdate] = 1

            if args.get('csv'):
                csv_tmp = tempfile.NamedTemporaryFile(mode='w+',
                                                      prefix='logs_csv_',
                                                      delete=False)
                csv_writer = csv.writer(csv_tmp)
                csv_writer.writerow(['DATE', 'N_REQUESTS'])

                for k, v in result.items():
                    csv_writer.writerow([k, v])

                csv_tmp.close()

                tmp_send = BytesIO()
                with open(csv_tmp.name, mode='rb') as f:
                    tmp_send.write(f.read())

                tmp_send.seek(0)
                response = send_file(tmp_send,
                                     mimetype='text/csv',
                                     as_attachment=True,
                                     attachment_filename='logs.csv')

                os.remove(csv_tmp.name)
                return response

            else:
                return result

        else:
            startdate = datetime.today().date() - timedelta(days=7)
            logs = RequestLog.query.filter(
                RequestLog.created > startdate).all()
            result = []

            for log in logs:
                result.append({
                    "client_id":
                    clientserializer.dumps(log.client_id),
                    "test_id":
                    testserializer.dumps(log.test_id),
                    "result":
                    log.result,
                    "error":
                    log.error,
                    "timestamp":
                    log.created.isoformat()
                })

            return {"results": result, "startdate": startdate.isoformat()}