#!/usr/bin/python3

import csv

NUM_NODES=3
NUM_CPUS=6
RAFT_GROUP=3
TOTAL_SLOTS=16384


def bucket(seq, num):
    avg = len(seq) / float(num)
    out = []
    last = 0.0

    while last < len(seq):
        out.append(seq[int(last):int(last + avg)])
        last += avg

    return out


with open('/tmp/slots.csv', mode='w') as slots_file:
    slots_writer = csv.writer(
        slots_file,
        delimiter=',',
        quotechar='"',
        quoting=csv.QUOTE_MINIMAL)
    p = 1
    slot_row = []
    for x in bucket(range(TOTAL_SLOTS), (NUM_NODES*NUM_CPUS)/RAFT_GROUP):
        r = "Slots: %s-%s Port: %d" %(x[0], x[-1], 19900 +p)
        for i in range(0,4):
            if len(slot_row) == NUM_NODES:
                slots_writer.writerow(slot_row)
                slot_row = []
            else:
                slot_row.append(r)

        p += 1

    slots_writer.writerow(slot_row)
