__author__ = 'agerber'

import os

class part(object):
    def __init__(self, name, part_, data_sep=",", comment="#"):
        self.name = name
        self.data_sep = data_sep
        self.comment = comment
        self.r_quad = []
        self.time = []
        self.part_ = part_

    def get(self, scheme="time:par:x:y"): #scheme not impelented -- par = particle
        f = open(self.name, "r")
        list_scheme = scheme.split(':')
        x0 = 0.0
        y0 = 0.0
        count = 0
        for line in f:
            list_line = line.split(',')
            zip_list = zip(list_scheme,list_line)
            dict_line = dict(zip_list)
            dict_line["par"] = int(dict_line["par"])
            dict_line["time"] = float(dict_line["time"])
            dict_line["x"] = float(dict_line["x"])
            dict_line["y"] = float(dict_line["y"])

            if (self.part_ == dict_line["par"]):
                dict_line["x"] /= 10.0
                dict_line["y"] /= 10.0
                if count == 0:
                    x0 = dict_line["x"]
                    y0 = dict_line["y"]
                else:
                    self.r_quad.append((dict_line["x"] - x0) ** 2 + (dict_line["y"] - y0) ** 2)
                    self.time.append(dict_line["time"] / 15.0)
                count += 1
        f.close()
        return self.r_quad