def action()

in online_attacks/online_algorithms/stochastic_optimistic.py [0:0]


    def action(self, value: float, index: int):
        if self.sampling_phase:
            self.R.append([value, index])
            self.R.sort(key=lambda tup: tup[0], reverse=True)  # sorts in place
            self.R = self.R[: self.k]

            if index >= self.threshold:
                self.sampling_phase = False
        else:
            num_picked = len(self.S)
            num_left_to_pick = self.k - num_picked
            num_samples_left = self.N - index
            if len(self.R) > 0:
                self.k_value, self.k_index = self.R[-1]
            if num_left_to_pick > 0:
                if num_samples_left <= num_left_to_pick and self.exhaust:
                    # Just Pick the last samples to exhaust K
                    self.S.append([value, index])
                elif value > self.k_value:
                    # Update and pick
                    self.S.append([value, index])
                    self.R = self.R[:-2]