Пример #1
0
    def getThermalResidency(self, temp_range, window, percent=False):
        """Returns the total time spent in a given temperature range
        Args:
            temp_range (tuple): A tuple of (low_temp, high_temp)
                which the specifies the range of temperature that
                one intends to calculate the residency for.
            window (tuple): A (start, end) tuple to limit the scope of the
                residency calculation.
            percent: Returns the residency as a percentage of the total
                duration of the trace
        """

        # Get a pivoted thermal temperature data using the grammar
        data = self._analyzer.getStatement("trappy.thermal.Thermal:temp")

        result = {}
        for pivot, data_frame in data.groupby(axis=1, level=0):

            series = data_frame[pivot]
            series = Utils.select_window(series, window)
            mask = (series >= temp_range[0]) & (series <= temp_range[1])
            index = series.index.values
            # pylint fails to recognize numpy members.
            # pylint: disable=no-member
            shift_index = np.roll(index, 1)
            # pylint: enable=no-member
            shift_index[0] = 0

            result[pivot] = sum((index - shift_index)[mask.values])

            if percent:
                result[pivot] = (
                    result[pivot] * 100.0) / self._run.get_duration()

        return result