<commit_before>
import zephyr.signal

def sign(value):
    return cmp(value, 0)

class RREventParser:
    def __init__(self, samplerate):
        self.samplerate = float(samplerate)
        self.received_value_count = 0
        self.latest_value_sign = 0
    
    def handle_values(self, values):
        for value in values:
            value_sign = sign(value)
            if value_sign != self.latest_value_sign:
                yield self.received_value_count / self.samplerate, abs(value)
            
            self.received_value_count += 1
            self.latest_value_sign = value_sign

class SignalCollectorWithRRProcessing(zephyr.signal.SignalCollector):
    def __init__(self):
        zephyr.signal.SignalCollector.__init__(self)
        
        self.initialize_event_stream("rr_event")
        self.rr_event_parser = None
    
    def handle_packet(self, signal_packet):
        zephyr.signal.SignalCollector.handle_packet(self, signal_packet)
        
        if signal_packet.type == "rr":
            if self.rr_event_parser is None:
                self.rr_event_parser = RREventParser(signal_packet.samplerate)
            
            rr_signal_start_timestamp = self.signal_streams["rr"].start_timestamp
            for relative_rr_event_timestamp, rr_event_value in self.rr_event_parser.handle_values(signal_packet.signal_values):
                rr_event_timestamp = relative_rr_event_timestamp + rr_signal_start_timestamp
                
                self.event_streams["rr_event"].append((rr_event_timestamp, rr_event_value))
<commit_msg>Improved R-to-R detection.<commit_after>
import zephyr.signal

def sign(value):
    return cmp(value, 0)

class SignalCollectorWithRRProcessing(zephyr.signal.SignalCollector):
    def __init__(self):
        zephyr.signal.SignalCollector.__init__(self)
        self.initialize_event_stream("rr_event")
        self.latest_value_sign = 0
    
    def handle_packet(self, signal_packet):
        zephyr.signal.SignalCollector.handle_packet(self, signal_packet)
        
        if signal_packet.type == "rr":
            signal_stream = self.signal_streams["rr"]
            
            received_values_before_this_packet = len(signal_stream.signal_values) - len(signal_packet.signal_values)
            
            for sample_index, rr_value in enumerate(signal_packet.signal_values, start=received_values_before_this_packet):
                rr_value_sign = sign(rr_value)
                if rr_value_sign != self.latest_value_sign:
                    rr_timestamp = sample_index / signal_stream.samplerate + signal_stream.start_timestamp
                    self.event_streams["rr_event"].append((rr_timestamp, abs(rr_value)))
                self.latest_value_sign = rr_value_sign

{'fraction_non_alphanumeric': 0.07545164718384698, 'fraction_numerical': 0.0021253985122210413, 'mean_word_length': 2.5080745341614907, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7283473', 'n_tokens_mistral': 860, 'n_tokens_neox': 802, 'n_words': 123}