<commit_before>//
//  SensorTimestampGlucoseEvent.swift
//  RileyLink
//
//  Created by <NAME> on 10/16/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation

public struct SensorTimestampGlucoseEvent: GlucoseEvent {
    public let length: Int
    public let rawData: Data
    public let timestamp: DateComponents
    private let timestampType: String
    
    public init?(availableData: Data, relativeTimestamp: DateComponents) {
        length = 5
        
        guard length <= availableData.count else {
            return nil
        }
        
        func d(_ idx:Int) -> Int {
            return Int(availableData[idx] as UInt8)
        }
        
        rawData = availableData.subdata(in: 0..<length)
        timestamp = DateComponents(glucoseEventBytes: availableData.subdata(in: 1..<5))
        
        switch (d(3) >> 5 & 0b00000011) {
        case 0x00:
            timestampType = "last_rf"
        case 0x01:
            timestampType = "page_end"
        case 0x02:
            timestampType = "gap"
        default:
            timestampType = "unknown"
        }

    }
    
    public var dictionaryRepresentation: [String: Any] {
        return [
            "name": "SensorTimestamp",
            "timestampType": timestampType
        ]
    }
}<commit_msg>Move timestampType into an enum<commit_after>//
//  SensorTimestampGlucoseEvent.swift
//  RileyLink
//
//  Created by <NAME> on 10/16/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation

public enum SensorTimestampType: String {
    case lastRf
    case pageEnd
    case gap
    case unknown
    
    public static func eventType(code: UInt8) -> SensorTimestampType {
        switch code {
        case 0x00:
            return .lastRf
        case 0x01:
            return .pageEnd
        case 0x02:
            return .gap
        default:
            return .unknown
        }
    }
    
}

public struct SensorTimestampGlucoseEvent: GlucoseEvent {
    public let length: Int
    public let rawData: Data
    public let timestamp: DateComponents
    public let timestampType: SensorTimestampType
    
    public init?(availableData: Data, relativeTimestamp: DateComponents) {
        length = 5
        
        guard length <= availableData.count else {
            return nil
        }
        
        func d(_ idx:Int) -> Int {
            return Int(availableData[idx] as UInt8)
        }
        
        rawData = availableData.subdata(in: 0..<length)
        timestamp = DateComponents(glucoseEventBytes: availableData.subdata(in: 1..<5))
        timestampType = SensorTimestampType.eventType(code: UInt8(d(3) >> 5) & 0b00000011)

    }
    
    public var dictionaryRepresentation: [String: Any] {
        return [
            "name": "SensorTimestamp",
            "timestampType": timestampType
        ]
    }
}
{'fraction_non_alphanumeric': 0.08715435771788589, 'fraction_numerical': 0.02520126006300315, 'mean_word_length': 1.9342915811088295, 'pattern_counts': {'":': 4, '<': 13, '<?xml version=': 0, '>': 14, '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': '3224699', 'n_tokens_mistral': 857, 'n_tokens_neox': 793, 'n_words': 213}