Example #1
0
 def __init__(self, data=None, index=None, columns=None, dtype=None,
              copy=False, sampling_rate=1.0):
     """Construct dataframe-like object."""
     DataFrame.__init__(self, data=data, index=index, columns=columns,
                        dtype=dtype, copy=copy)
     if sampling_rate is not None:
         self.index = np.arange(0, len(self) * sampling_rate, sampling_rate)
Example #2
0
 def __init__(self,x,y,d=0.025,verbose=False,xml=None,**kwargs):
     if not xml:
         xml = osm_xml_download(x,y,d,verbose)
     osm = etree.fromstring(xml.encode('utf-8'))
     data = [Series({key:value for key,value in node.attrib.items() if key in ['lat','lon']},name=node.attrib['id'])  for node in osm.findall('node')]
     DataFrame.__init__(self,data,dtype=float,**kwargs)
     self.street_setter(osm.findall('way'))
     self.index = self.index.astype(int)
Example #3
0
    def __init__(self, data=None, index=None, columns=_col_names, dtype=None,
                 copy=False, tick_id=None, unit_amount=None):
#        print tick_id, dates, data
        if tick_id == None:
            raise ValueError("tick_id must be set")
        if columns == None:
            columns = _col_names
        DataFrame.__init__(self, data, index, columns, dtype, copy)
        self.tick_id = tick_id
        self.sort(inplace=True)
        self.unit_amount = unit_amount
        self.fix_split()
Example #4
0
    def __init__(self, *args, **kwargs):

        skip = kwargs.get('skiplines', 1)
        times = kwargs.get('readtime', slice(0, None))
        name = kwargs.get('name', 'None')
        symb = kwargs.get('symb', 'o')
        files = kwargs.get('search_files', None)
        properties = kwargs.get('properties', None)
        lines = kwargs.get('maxlines', 0)
        search = kwargs.get('search_pattern', FPNUMBER)
        folder = kwargs.get('folder', None)
        plot_properties = kwargs.get('plot_properties', PlotProperties())
        show_func = kwargs.get('show_func', None)
        validate = kwargs.get('validate', True)
        preHooks = kwargs.get('preHooks', None)
        exclude = kwargs.get('exclude', [" "])  # FIXME
        times_stride = kwargs.get('times_stride', 1)
        times_range = kwargs.get('times_range', "all") # FIXME implement strides
        times_slice = times_range

        keys = ['skiplines',
                'readtime',
                'preHooks',
                'name',
                'symb',
                'search_files',
                'properties',
                'maxlines',
                'search_pattern',
                'folder',
                'plot_properties',
                'show_func',
                'exclude',
                'times_stride',
                'times_range',
                ]

        for k in keys:
            if k in kwargs:
                kwargs.pop(k)

        # TODO explain what happens here
        if folder is None:
            # super(FoamFrame, self).__init__(*args, **kwargs)
            DataFrame.__init__(self, *args, **kwargs)
        else:
            if preHooks:
                for hook in preHooks:
                    hook.execute()
            if (folder in case_data_base) and Database:
                print("re-importing", end=" ")
            else:
                print("importing", end=" ")
            print(name + ": ", end="")
            origins, data = import_foam_folder(
                path=folder,
                search=search,
                files=files,
                skiplines=skip,
                maxlines=lines,
                skiptimes=times,
                exclude=exclude,
                times_slice=times_slice
                )
            try:
                DataFrame.__init__(self, data)
            except Exception as e:
                print(e)
            self.properties = Props(
                origins,
                name,
                plot_properties,
                folder,
                symb,
                show_func)
            if validate and Database:
                self.validate_origins(folder, origins)
            # register to database
            if Database:
                case_data_base.sync()
    def __init__(self, sourcefilename, sourceDataFrame, teamname, teamno):

        DataFrame.__init__(self, sourceDataFrame)
        self.SN = sourcefilename[0:15]
        self.data = sourceDataFrame
        self.teamname = teamname
        self.teamno = teamno
        self.home = 0 if self.teamno == 1 else 1
        self.oppteamname = sourcefilename[9:12] if self.teamno == 2 else sourcefilename[12:15]
        self.oppteamno = 2 if self.teamno == 1 else 1

        selector = sourceDataFrame[sourceDataFrame["team"] == teamname]
        self.FGM = calculate_FGM(selector)
        self.FGA = calculate_FGA(selector)
        self.FGP = float(self.FGM) / self.FGA if self.FGA != 0 else 0
        self.B3M = calculate_3M(selector)
        self.B3A = calculate_3A(selector)
        self.B3P = float(self.B3M) / self.B3A if self.B3A != 0 else 0
        self.FTM = calculate_FTM(selector)
        self.FTA = calculate_FTA(selector)
        self.FTP = float(self.FTM) / self.FTA if self.FTA != 0 else 0
        self.P = int(score_calculate(selector))
        self.ORB = calculate_ORB(selector)
        self.DRB = calculate_DRB(selector)
        self.TRB = self.ORB + self.DRB
        self.TOV = calculate_TOV(selector)
        self.TOVP = (
            self.TOV / (self.FGA + self.FTA * 0.44 + self.TOV) if (self.FGA + self.FTA * 0.44 + self.TOV) != 0 else 0
        )
        self.AST = calculate_AST(selector)
        self.F = calculate_F(selector)

        """-------------the code here will be used to produce rows that will aid the calculation of time interval-------------"""
        _set_dummies(self, self.teamname)

        combination_starter = self._combinaiton_reference()
        self.totalcombi = combination_starter.etype.count()

        """-------------this calculates for every row what the combination number is------------------ """
        counter = 0
        combinations = combination_starter.index
        for identifier in combinations:
            counter += 1
            self.data.ix[identifier:, "combination_number"] = counter

        """this is to calculate the time remaining of each row, notice that overtime is considered here"""

        self["time remaining"] = 0
        end_period = self.data.tail(1).period.item()
        self.data.ix[(self.data.period <= 4), "time remaining"] = (end_period - 4) * 5 * 60
        if end_period > 4:
            self.data.ix[(self.data.period > 4), "time remaining"] = (end_period - self.data.period) * 5 * 60
        self.data.ix[self.data.period <= 4, "time remaining"] += (4 - self.data.period) * 12 * 60
        self.data.ix[:, "time"] = pd.to_datetime(self.data.time, format="%M:%S")
        self.data.ix[:, "time remaining"] = (
            self.data.ix[:, "time remaining"]
            + pd.DatetimeIndex(self.data.time).minute * 60
            + pd.DatetimeIndex(self.data.time).second
        )

        self.MP = self.data.head(1).ix[:, "time remaining"].item() / 60

        oppselector = sourceDataFrame[sourceDataFrame["team"] == self.oppteamname]
        self.ORBP = float(self.ORB) / (self.ORB + calculate_DRB(oppselector))
        self.DRBP = float(self.DRB) / (self.DRB + calculate_ORB(oppselector))
        self.TRBP = float(self.TRB) / (self.TRB + calculate_DRB(oppselector) + calculate_ORB(oppselector))
        self.PTD = int(self.P - score_calculate(oppselector))
        self.STL = calculate_STL(oppselector)
        self.BLK = calculate_BLK(oppselector)
        self.interval = self.data.head(1).ix[:, "time remaining"].item()
        nameindex = detect_team(self.teamno)
        self.players = pd.Series(self.data[nameindex].values.ravel()).unique()
Example #6
0
    def __init__(self, *args, **kwargs):

      skip = kwargs.get('skiplines', 1)
      times = kwargs.get('skiptimes', 1)
      name = kwargs.get('name', 'None')
      symb = kwargs.get('symb', 'o')
      files = kwargs.get('search_files', None)
      properties = kwargs.get('properties', None)
      lines = kwargs.get('maxlines', 0)
      search = kwargs.get('search_pattern', io.FPNUMBER)
      folder = kwargs.get('folder', None)
      plot_properties = kwargs.get('plot_properties', PlotProperties())
      show_func = kwargs.get('show_func', None)
      validate = kwargs.get('validate', True)
      preHooks = kwargs.get('preHooks', None)

      keys = [
          'skiplines',
          'skiptimes',
          'preHooks',
          'name',
          'symb',
          'search_files',
          'properties',
          'maxlines',
          'search_pattern',
          'folder',
          'plot_properties',
          'show_func']

      for k in keys:
        try:
            kwargs.pop(k)
        except:
            pass

      #TODO explain what happens here
      if folder == None:
           #super(FoamFrame, self).__init__(*args, **kwargs)
           DataFrame.__init__(self, *args, **kwargs)
      else:
           if preHooks:
                for hook in preHooks:
                    hook.execute()
           if case_data_base.has_key(folder) and Database:
                print "re-importing",
           else:
                print "importing",
           print name + ": ",
           origins, data = io.import_foam_folder(
                       path=folder,
                       search=search,
                       files=files,
                       skiplines=skip,
                       maxlines=lines,
                       skiptimes=times,
                  )
           DataFrame.__init__(self, data)
           self.properties = Props(
                origins,
                name,
                plot_properties,
                folder,
                # FIXME fix it for read logs
                data.index.levels[0],
                symb,
                show_func)
           if validate and Database:
                self.validate_origins(folder, origins)
           # register to database
           if Database:
                case_data_base.sync()
Example #7
0
 def __init__(self,data,*args,**kwargs):
     DataFrame.__init__(self,data,*args,**kwargs)