traffic/core/flight.py
def agg_time(
        self, freq: str = "1T", merge: bool = True, **kwargs,
    ) -> "Flight":
        """Aggregate features on time windows.

        The following is performed:

        - a new column `rounded` rounds the timestamp at the given rate;
        - the groupby/agg is operated with parameters passed in kwargs;
        - if merge is True, the new column in merged into the Flight,
          otherwise a pd.DataFrame is returned.

        For example:

        >>> f.agg_time('3T', groundspeed='mean')

        returns a Flight with a new column groundspeed_mean with groundspeed
        averaged per intervals of 3 minutes.
        """

        def flatten(
            data: pd.DataFrame, how: Callable = "_".join
        ) -> pd.DataFrame:
            data.columns = (
                [
                    how(filter(None, map(str, levels)))
                    for levels in data.columns.values
                ]
                if isinstance(data.columns, pd.MultiIndex)
                else data.columns
            )
            return data

        if len(kwargs) == 0:
            raise RuntimeError("No feature provided for aggregation.")
        temp_flight = self.assign(
            rounded=lambda df: df.timestamp.dt.round(freq)
        )

        # force the agg_data to be multi-indexed in columns
        kwargs_modified: Dict["str", List[Any]] = dict(
            (
                key,
                list(value)
                if any(isinstance(value, x) for x in [list, tuple])
                else [value],
            )
            for key, value in kwargs.items()
        )
        agg_data = flatten(temp_flight.groupby("rounded").agg(kwargs_modified))

        if not merge:  # mostly for debugging purposes
            return agg_data

        return temp_flight.merge(agg_data, left_on="rounded", right_index=True)
Aggregate features on time windows.

        The following is performed:

        - a new column `rounded` rounds the timestamp at the given rate;
        - the groupby/agg is operated with parameters passed in kwargs;
        - if merge is True, the new column in merged into the Flight,
          otherwise a pd.DataFrame is returned.

        For example:

        >>> f.agg_time('3T', groundspeed='mean')

        returns a Flight with a new column groundspeed_mean with groundspeed
        averaged per intervals of 3 minutes.
        
Aggregate features on time windows.
The following is performed.

a new column `rounded` rounds the timestamp at the given rate;
the groupby/agg is operated with parameters passed in kwargs;
if merge is True, the new column in merged into the Flight,
otherwise a pd.DataFrame is returned.

For example.



returns a Flight with a new column groundspeed_mean with groundspeed
averaged per intervals of 3 minutes.
Aggregate features on time windows . The following is performed . a new column ` rounded ` rounds the timestamp at the given rate ; the groupby / agg is operated with parameters passed in kwargs ; if merge is True the new column in merged into the Flight otherwise a pd . DataFrame is returned . For example . returns a Flight with a new column groundspeed_mean with groundspeed averaged per intervals of 3 minutes .
def agg_time(
        self, freq: str = "1T", merge: bool = True, **kwargs,
    ) -> "Flight":
        def flatten(
            data: pd.DataFrame, how: Callable = "_".join
        ) -> pd.DataFrame:
            data.columns = (
                [
                    how(filter(None, map(str, levels)))
                    for levels in data.columns.values
                ]
                if isinstance(data.columns, pd.MultiIndex)
                else data.columns
            )
            return data
        if len(kwargs) == 0:
            raise RuntimeError("No feature provided for aggregation.")
        temp_flight = self.assign(
            rounded=lambda df: df.timestamp.dt.round(freq)
        )
        kwargs_modified: Dict["str", List[Any]] = dict(
            (
                key,
                list(value)
                if any(isinstance(value, x) for x in [list, tuple])
                else [value],
            )
            for key, value in kwargs.items()
        )
        agg_data = flatten(temp_flight.groupby("rounded").agg(kwargs_modified))
        if not merge:  
            return agg_data
        return temp_flight.merge(agg_data, left_on="rounded", right_index=True)
def agg_time ( self , freq : str = "1T" , merge : bool = True , ** kwargs , ) -> "Flight" : def flatten ( data : pd . DataFrame , how : Callable = "_" . join ) -> pd . DataFrame : data . columns = ( [ how ( filter ( None , map ( str , levels ) ) ) for levels in data . columns . values ] if isinstance ( data . columns , pd . MultiIndex ) else data . columns ) return data if len ( kwargs ) == 0 : raise RuntimeError ( "No feature provided for aggregation." ) temp_flight = self . assign ( rounded = lambda df : df . timestamp . dt . round ( freq ) ) kwargs_modified : Dict [ "str" , List [ Any ] ] = dict ( ( key , list ( value ) if any ( isinstance ( value , x ) for x in [ list , tuple ] ) else [ value ] , ) for key , value in kwargs . items ( ) ) agg_data = flatten ( temp_flight . groupby ( "rounded" ) . agg ( kwargs_modified ) ) if not merge : return agg_data return temp_flight . merge ( agg_data , left_on = "rounded" , right_index = True )
Aggregate features on time windows.
Aggregate features on time windows .
"""Aggregate features on time windows.

        The following is performed:

        - a new column `rounded` rounds the timestamp at the given rate;
        - the groupby/agg is operated with parameters passed in kwargs;
        - if merge is True, the new column in merged into the Flight,
          otherwise a pd.DataFrame is returned.

        For example:

        >>> f.agg_time('3T', groundspeed='mean')

        returns a Flight with a new column groundspeed_mean with groundspeed
        averaged per intervals of 3 minutes.
        """ # force the agg_data to be multi-indexed in columns # mostly for debugging purposes
self
freq
str
merge
bool