from exceptions import Exception
from frq_info import FRQInfo, IncorrectFormatException

class FeaturesMissingException(Exception):
    pass


class FRQFeatures(FRQInfo):
    #feature vector
    names = ("Length", "Curvitude", "Center",  
              "FillF", "Curv1", "Curv2", "NZPD",
              "P00", "P01", "P02", "P03", "P04", 
              "P05", "P06", "P07", "P08", "P09",
              "P10", "P11", "P12", "P13", "P14", 
              "P15", "P16", "P17", "P18", "P19",
              "Pb" , "Pe",  "KlasRes", "KlT",
              "KlV", "WDir", "LoopWidth")

    def __init__(self, filename):
        try:
            FRQInfo.__init__(self, filename)
        except IncorrectFormatException, e:
            self.features = []
            raise e

        self.features = []

        for name in self.names:
            if not name in self.info.keys():
                self.features = []
                msg = "Cant read feature vector, some of features missing: " + \
                       str(self.filename)
                raise FeaturesMissingException(msg)
            else:
                self.features.append(float(self.info[name].replace(',', '.')))
    
    def __str__(self):
        if len(self.features) != len(self.names):
            return "features missing"

        res = ""
        for idx, name in enumerate(self.names):
            res += name + ":" + str(self.features[idx]) + ", "
        return res