from __future__ import print_function
from builtins import range as xrange, int

import json
import sys
import traceback


def main(ts_count, col_count):
    data = {}
    data['shard_size'] = '30d'
    data['columns'] = [{'parser': 'epoch', 'into': '$timestamp'}]
    for ts in range(ts_count):
        data['columns'].extend([{'parser': 'int64', 'into': {
                               'ts': 'ts-{}'.format(ts), 'col': 'col-{}'.format(col)}} for col in range(col_count)])

    f = open('ts-{}--col-{}-config.json'.format(ts_count, col_count), 'w')
    f.write(json.dumps(data, indent=4, sort_keys=True))
    f.close()


if __name__ == "__main__":
    try:
        if len(sys.argv) != 3:
            print("usage: ", sys.argv[0],
                  " ts_count col_count")
            sys.exit(1)
        main(int(sys.argv[1]), int(sys.argv[2]))

    except Exception as ex:  # pylint: disable=W0703
        print("An error ocurred:", str(ex))
        traceback.print_exc()
