#!/usr/bin/env python3
# -*- coding: utf-8 -*-


import argparse

from geo_playground.merger import merge

USAGE_MSG = """%(prog)s [--p1 <file-path>] [-p2 <file-path>] [--debug]"""


def main():
    """The scripts takes in input 3 CSV file paths: `p1`, `p2` and `output`. It
    calculates the ratio between the `variable1` and `variable2` (in p1 and p2 respectively)
    and save the results to `out`. Examples of the 3 files are provided below:

        - `p1`:
            id_store;address;variable1;category
            1;"100 High St.";74;A
            2;"382-384 Brixton Rd";91;A

        - `p2`:
            address;variable2
            "100 High Street";88
            "382-384 Brixton Road";42
            "11 Little Stonegate";70

        - `out`:
            store_id;var1;var2;ratio
            1;74.0;88.0;0.84
            2;91.0;42.0;2.17
            3;13.0;70.0;0.19

    The script can be executed as follows:
        python3 merger
            -p1 ./data/data_poi_part_1.csv
            -p2 ./data/data_poi_part_2.csv
            -out ./data/data_join.csv
    """
    args = get_params()

    p1_path = args.p1
    p2_path = args.p2
    output_path = args.out

    merge(p1_path, p2_path, output_path)


def get_params():
    parser = argparse.ArgumentParser(usage=USAGE_MSG, description="Merge two CSV files")
    parser.add_argument("-p1", required=True, help="first CSV path")
    parser.add_argument("-p2", required=True, help="second CSV path")
    parser.add_argument("-out", required=True, help="output CSV path")
    parser.add_argument("-g", "--debug", dest="debug", action="store_true")
    args = parser.parse_args()

    return args


if __name__ == '__main__':
    main()
