-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFixedSessionFaker.swift
68 lines (62 loc) · 2.59 KB
/
FixedSessionFaker.swift
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
// Created by Lunar on 15/09/2021.
//
import Foundation
import CoreData
class FixedSessionFaker {
init(context: NSManagedObjectContext) {
let req: NSFetchRequest<SessionEntity> = SessionEntity.fetchRequest()
req.predicate = NSPredicate(format: "name LIKE %@", "Its complicated")
var session: SessionEntity!
if let already = try! context.fetch(req).first {
session = already
} else {
session = SessionEntity(context: context)
session.type = .fixed
session.uuid = SessionUUID()
session.name = "Its complicated"
session.tags = ""
session.startTime = DateBuilder.getDateWithTimeIntervalSinceReferenceDate(23443)
session.endTime = DateBuilder.getDateWithTimeIntervalSinceReferenceDate(2344323)
session.gotDeleted = false
session.version = 32
session.status = .RECORDING
session.deviceType = .AIRBEAM
for i in 0..<5 {
let stream = MeasurementStreamEntity(context: context)
stream.gotDeleted = false
stream.measurementShortType = "S\(i)"
stream.measurementType = "S\(i)"
stream.sensorName = "S\(i)"
stream.sensorPackageName = "S\(i)"
stream.thresholdHigh = 100
stream.thresholdLow = 10
stream.thresholdMedium = 20
stream.thresholdVeryHigh = 110
stream.thresholdVeryLow = 0
stream.unitName = "UNiT"
stream.unitSymbol = "UNT"
stream.id = .random(in: 0...999)
stream.session = session
session.addToMeasurementStreams(stream)
let th = SensorThreshold(context: context)
th.sensorName = "S\(i)"
th.thresholdLow = 10
th.thresholdHigh = 100
th.thresholdMedium = 20
th.thresholdVeryLow = 0
th.thresholdVeryHigh = 110
}
try! context.save()
}
Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { _ in
for stream in session.allStreams {
let measurement = MeasurementEntity(context: context)
measurement.time = DateBuilder.getRawDate()
measurement.value = .random(in: 0...120)
measurement.location = .init(latitude: 50.049683, longitude: 19.944544)
stream.addToMeasurements(measurement)
}
try! context.save()
}
}
}