def sumWith(self, stat):
        """ Used if you want to sum up, for instance, laps' stats to get the activity's stats
            Not all items can be simply summed (min/max), and some just shouldn't (average)
        """
        stat = stat.asUnits(self.Units)
        summable_items = ("Value", "Gain", "Loss")
        for item in summable_items:
            their_value = getattr(stat, item, None)
            my_value = getattr(self, item, None)
            if their_value is not None:
                if my_value is not None:
                    setattr(self, item, my_value + their_value)
                    self._samples[item] = 1 # Break the chain of coalesceWith() calls - this is an entirely fresh "measurement"
                else:
                    setattr(self, item, their_value)
                    self._samples[item] = stat._samples[item]
        self.Average = None
        self._samples["Average"] = 0

        if self.Max is None or (stat.Max is not None and stat.Max > self.Max):
            self.Max = stat.Max
            self._samples["Max"] = stat._samples["Max"]
        if self.Min is None or (stat.Min is not None and stat.Min < self.Min):
            self.Min = stat.Min
            self._samples["Min"] = stat._samples["Min"]
 Used if you want to sum up, for instance, laps' stats to get the activity's stats
            Not all items can be simply summed (min/max), and some just shouldn't (average)
        
tapiriik/services/interchange.py