def parse_to_dataframe(
        self,
        group: List[str],
        metadata: Optional[Union[BatteryMetadata, dict]] = None
    ) -> BatteryDataFrame:
        """Parse a set of  files into a Pandas dataframe

        Parameters
        ----------
        group: list of str
            List of files to parse as part of the same test. Ordered sequentially
        metadata: dict, optional
            Metadata for the battery, should adhere to the BatteryMetadata schema

        Returns
        -------
        pd.DataFrame
            DataFrame containing the information from all files
        """

        # Initialize counters for the cycle numbers, etc.. Used to determine offsets for the
        start_cycle = 0
        start_time = 0

        # Read the data for each file
        #  Keep track of the ending index and ending time
        output_dfs = []
        for file_number, file in enumerate(group):
            # Read the file
            df_out = self.generate_dataframe(file, file_number, start_cycle,
                                             start_time)
            output_dfs.append(df_out)

            # Increment the start cycle and time to determine starting point of next file
            start_cycle += df_out['cycle_number'].max(
            ) - df_out['cycle_number'].min() + 1
            start_time = df_out['test_time'].max()

        # Combine the data from all files
        df_out = pd.concat(output_dfs, ignore_index=True)

        # Attach the metadata and return the data
        return BatteryDataFrame(data=df_out, metadata=metadata)
Пример #2
0
def test_df():
    return BatteryDataFrame(data={
        'current': [1, 0, -1],
        'voltage': [2, 2, 2]
    },
                            metadata={'name': 'Test data'})