-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathBatchEvent.swift
More file actions
156 lines (137 loc) · 4.03 KB
/
BatchEvent.swift
File metadata and controls
156 lines (137 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//
// Copyright 2019-2022, Optimizely, Inc. and contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
struct BatchEvent: Codable, Equatable {
let revision: String
let accountID: String
let clientVersion: String
let visitors: [Visitor]
let projectID: String
let clientName: String
let anonymizeIP: Bool
let enrichDecisions: Bool
let region: String
enum CodingKeys: String, CodingKey {
case revision
case accountID = "account_id"
case clientVersion = "client_version"
case visitors
case projectID = "project_id"
case clientName = "client_name"
case anonymizeIP = "anonymize_ip"
case enrichDecisions = "enrich_decisions"
case region
}
func getEventAttribute(key: String) -> EventAttribute? {
for visitor in visitors {
if let attribute = visitor.attributes.filter({ $0.key == key }).first {
return attribute
}
}
return nil
}
}
struct Visitor: Codable, Equatable {
let attributes: [EventAttribute]
let snapshots: [Snapshot]
let visitorID: String
enum CodingKeys: String, CodingKey {
case attributes
case snapshots
case visitorID = "visitor_id"
}
}
struct EventAttribute: Codable, Equatable {
let value: AttributeValue
let key: String
let type: String
let entityID: String
enum CodingKeys: String, CodingKey {
case value
case key
case type
case entityID = "entity_id"
}
}
struct Snapshot: Codable, Equatable {
let decisions: [Decision]?
let events: [DispatchEvent]
}
struct DecisionMetadata: Codable, Equatable {
let ruleType: String
let ruleKey: String
let flagKey: String
let variationKey: String
let enabled: Bool
var cmabUUID: String?
enum CodingKeys: String, CodingKey {
case ruleType = "rule_type"
case ruleKey = "rule_key"
case flagKey = "flag_key"
case variationKey = "variation_key"
case enabled = "enabled"
case cmabUUID = "cmab_uuid"
}
}
struct Decision: Codable, Equatable {
let variationID: String
let campaignID: String
let experimentID: String
let metaData: DecisionMetadata
enum CodingKeys: String, CodingKey {
case variationID = "variation_id"
case campaignID = "campaign_id"
case experimentID = "experiment_id"
case metaData = "metadata"
}
}
struct DispatchEvent: Codable, Equatable {
static let revenueKey = "revenue"
static let valueKey = "value"
static let activateEventKey = "campaign_activated"
// entityID is the layer id for impression events.
let entityID: String
let key: String
let timestamp: Int64
let uuid: String
var tags: [String: AttributeValue]?
var revenue: Int64?
var value: Double?
enum CodingKeys: String, CodingKey {
case entityID = "entity_id"
case key
case tags
case timestamp
case uuid
case revenue
case value
}
init(timestamp: Int64,
key: String,
entityID: String,
uuid: String,
tags: [String: AttributeValue]? = [:],
value: Double? = nil,
revenue: Int64? = nil) {
self.timestamp = timestamp
self.key = key
self.entityID = entityID
self.uuid = uuid
self.tags = tags
self.value = value
self.revenue = revenue
}
}