-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChartDefinitionDTO.swift
More file actions
69 lines (55 loc) · 1.95 KB
/
ChartDefinitionDTO.swift
File metadata and controls
69 lines (55 loc) · 1.95 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
//
// ChartDefinitionDTO.swift
//
//
// Created by Daniel Jilg on 10.11.21.
//
import Foundation
/// Chart-Representable data that was calculated from an Insight
struct ChartDefinitionDTO: Codable {
/// The ID of the insight that was calculated
public let id: UUID
public let metadata: MetadataSection
public let data: DataSection
public let axis: AxisSection
public struct MetadataSection: Codable {
/// The insight that was calculated
public let insight: DTOv2.Insight
/// When was this result calculated?
public let calculatedAt: Date
/// How long did this result take to calculate?
public let calculationDuration: TimeInterval
}
public struct DataSection: Codable {
public let x: String
public let xFormat: String?
public let columns: [Column]
public struct Column: Codable, Equatable {
public init(label: String, data: [String?]) {
self.label = label
self.data = data
}
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
let array = try container.decode([String?].self)
label = (array.first ?? "No Label") ?? "No Label"
data = Array(array.dropFirst())
}
public let label: String
public let data: [String?]
public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
var containingArray = [String?]()
containingArray.append(label)
containingArray.append(contentsOf: data)
try container.encode(containingArray)
}
}
}
public struct AxisSection: Codable {
public let x: AxisDefinition
public struct AxisDefinition: Codable {
public let type: String
}
}
}