def main(start=None, addr=None, port=None, slave=None):
    if slave:
        client = SeatingSlave(addr, port)
        client.run()
    else:
        if start:
            if start.endswith('.xls') or start.endswith('.xlsx'):
                state = read_excel(open(start).read())
            elif start.endswith('.txt'):
                state = read_text(open(start).read())
            else:
                raise Exception("Don't know how to open %s" % start)

        else:
            state = start_seating()

        print dump(state)
        state.shuffle()

        state_evaluator = SquareStateEvaluator(
            TablePositionAgnosticClosnessEvaluator())
        server = SeatingMaster(
            StateKeeper(HillClimber(state_evaluator), state=state),
            (addr, 5000), state_evaluator)
        server.run()
Exemple #2
0
def explicit_initial():
    return read_text("""
# Meal 1

Alice

*Bob
Charlie
Dave

# Meal 2

Alice
Bob

Charlie

# Meal 3

Alice
Bob

Charlie
Dave

# Group 1 (17)

Alice
Bob

# Group 2 (42)

Charlie
Dave
""")
Exemple #3
0
def test_report():
    state = read_text("""\
# Foo
1
2

3
4

#Bar
1
3

2
4

# Odd (17)
1
3

# Even (42)
2
4
""")

    assert report(state) == """\
def main(start=None, addr=None, port=None, slave=None):
    if slave:
        client = SeatingSlave(addr, port)
        client.run()
    else:
        if start:
            if start.endswith('.xls') or start.endswith('.xlsx'):
                state = read_excel(open(start).read())
            elif start.endswith('.txt'):
                state = read_text(open(start).read())
            else:
                raise Exception("Don't know how to open %s" % start)

        else:
            state = start_seating()

        print dump(state)
        state.shuffle()

        state_evaluator = SquareStateEvaluator(TablePositionAgnosticClosnessEvaluator())
        server = SeatingMaster(
            StateKeeper(
                HillClimber(state_evaluator),
                state=state),
            (addr, 5000),
            state_evaluator
        )
        server.run()
Exemple #5
0
def test_excel_change_geometry():

    start_state = read_text("""\
# Meal #0
3
2

1
0

# Meal #1
3
2

1
0
# Meal #2
2
1

0
""")

    assert dump(start_state) == """\
# Meal #0
   [2 3]
   [0 1]
# Meal #1
   [2 3]
   [0 1]
# Meal #2
   [1 2]
   [0]
"""

    rb = open_workbook(file_contents=(write_excel(start_state)))

    assert int(rb.sheet_by_index(1).cell(0, 1).value) == 2

    wb = copy(rb)
    wb.get_sheet(1).write(0, 1, 3)
    result = BytesIO()
    wb.save(result)
    new_state = read_excel(result.getvalue())

    assert dump(new_state) == """\
Exemple #6
0
def main():
    filename = sys.argv[1] if len(sys.argv) == 2 else "seating.xls"
    if filename.endswith('.xls') or filename.endswith('.xlsx'):
        state = read_excel(open(filename).read())
    elif filename.endswith('.txt'):
        state = read_text(open(filename).read())
    else:
        state = start_seating()

    state.shuffle()
    state = fast_search(state)

    print dump(state)
    print report(state)
    print repr(state)
    print write_text(state)
    with open("seating.xls", "wb") as f:
        f.write(write_excel(state))
Exemple #7
0
def main():
    filename = sys.argv[1] if len(sys.argv) == 2 else "seating.xls"
    if filename.endswith('.xls') or filename.endswith('.xlsx'):
        state = read_excel(open(filename).read())
    elif filename.endswith('.txt'):
        state = read_text(open(filename).read())
    else:
        state = start_seating()

    state.shuffle()
    state = fast_search(state)

    print dump(state)
    print report(state)
    print repr(state)
    print write_text(state)
    with open("seating.xls", "wb") as f:
        f.write(write_excel(state))
Exemple #8
0
def test_text_format(initial):
    text_content = write_text(initial)
    actual = read_text(text_content)
    print repr(actual)
    _assert_same_state(initial, actual)