Skip to content

Commit

Permalink
initial incomplete implementations of the new timelines architecture …
Browse files Browse the repository at this point in the history
…(recorder / segment / processor) #11
  • Loading branch information
sobri909 committed May 2, 2018
1 parent 7279bca commit 9323ddc
Show file tree
Hide file tree
Showing 14 changed files with 639 additions and 596 deletions.
28 changes: 7 additions & 21 deletions LocoKit/Base/Timelines/Items/Path.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,41 +214,27 @@ open class Path: TimelineItem {
guard let timeGap = timeInterval(from: otherPath), timeGap < 60 * 10 else { return nil }

// get the activity types
guard let myActivityType = movingActivityType, let theirActivityType = otherPath.movingActivityType else {
return nil
}
guard let myActivityType = self.movingActivityType else { return nil }
guard let theirActivityType = otherPath.movingActivityType else { return nil }

// can't path-path cleanse two paths of same type
if myActivityType == theirActivityType { return nil }

// get the edges
guard let myEdge = self.edgeSample(with: otherPath), let theirEdge = otherPath.edgeSample(with: self) else {
return nil
}
guard myEdge.hasUsableCoordinate, theirEdge.hasUsableCoordinate else {
return nil
}
guard let myEdgeLocation = myEdge.location, let theirEdgeLocation = theirEdge.location else {
return nil
}
guard let myEdge = self.edgeSample(with: otherPath) else { return nil }
guard let theirEdge = otherPath.edgeSample(with: self) else { return nil }
guard myEdge.hasUsableCoordinate, theirEdge.hasUsableCoordinate else { return nil }
guard let myEdgeLocation = myEdge.location, let theirEdgeLocation = theirEdge.location else { return nil }

let mySpeedIsSlow = myEdgeLocation.speed < Path.maximumModeShiftSpeed
let theirSpeedIsSlow = theirEdgeLocation.speed < Path.maximumModeShiftSpeed

// are the edges on opposite sides of the mode change speed boundary?
if mySpeedIsSlow != theirSpeedIsSlow {
let note = Notification(name: .debugInfo, object: self,
userInfo: ["info": "edges are opposite sides of the mode shift boundary"])
NotificationCenter.default.post(note)
return nil
}
if mySpeedIsSlow != theirSpeedIsSlow { return nil }

// is their edge my activity type?
if theirEdge.activityType == myActivityType {
self.add(theirEdge)
let note = Notification(name: .debugInfo, object: self,
userInfo: ["info": "moved path edge (\(theirActivityType)) to adjacent path"])
NotificationCenter.default.post(note)
return theirEdge
}

Expand Down
11 changes: 9 additions & 2 deletions LocoKit/Base/Timelines/Items/TimelineItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ open class TimelineItem: TimelineObject, Hashable, Comparable, Codable {
internal(set) public var inTheStore = false
open var currentInstance: TimelineItem? { return inTheStore ? self : store?.item(for: itemId) }

public var classifier: MLCompositeClassifier? { return store?.manager?.classifier }
public var classifier: MLCompositeClassifier? { return store?.recorder?.classifier }

public var mutex = PThreadMutex(type: .recursive)

Expand All @@ -30,6 +30,13 @@ open class TimelineItem: TimelineObject, Hashable, Comparable, Codable {

open var isMergeLocked: Bool { return false }

public var hasBrokenEdges: Bool {
if deleted { return false }
if previousItem == nil { return true }
if nextItem == nil && !isCurrentItem { return true }
return false
}

public var deleted = false {
willSet(willDelete) {
if willDelete {
Expand Down Expand Up @@ -148,7 +155,7 @@ open class TimelineItem: TimelineObject, Hashable, Comparable, Codable {
}
}

public var isCurrentItem: Bool { return store?.manager?.currentItem == self }
public var isCurrentItem: Bool { return store?.recorder?.currentItem == self }

// MARK: Timeline item validity

Expand Down
6 changes: 0 additions & 6 deletions LocoKit/Base/Timelines/Items/Visit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ open class Visit: TimelineItem {
// path edge is inside and path edge next is inside: move path edge to the visit
if pathEdgeIsInside && pathEdgeNextIsInside {
self.add(pathEdge)
NotificationCenter.default.post(Notification(name: .debugInfo, object: store?.manager,
userInfo: ["info": "moved path edge to visit"]))
return pathEdge
}

Expand All @@ -151,8 +149,6 @@ open class Visit: TimelineItem {
// path edge is outside and visit edge is outside: move visit edge to the path
if !pathEdgeIsInside && !visitEdgeIsInside {
path.add(visitEdge)
NotificationCenter.default.post(Notification(name: .debugInfo, object: store?.manager,
userInfo: ["info": "moved visit edge to path"]))
return visitEdge
}

Expand All @@ -162,8 +158,6 @@ open class Visit: TimelineItem {
visitEdgeType == pathEdge.activityType
{
path.add(visitEdge)
NotificationCenter.default.post(Notification(name: .debugInfo, object: store?.manager,
userInfo: ["info": "moved visit edge to path"]))
return visitEdge
}

Expand Down
11 changes: 6 additions & 5 deletions LocoKit/Base/Timelines/Merge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import os.log

typealias MergeScore = ConsumptionScore

public class Merge: CustomStringConvertible {
internal class Merge: CustomStringConvertible {

var keeper: TimelineItem
var betweener: TimelineItem?
var deadman: TimelineItem

lazy var score: MergeScore = {
if betweener?.isMergeLocked == true { return .impossible }
if keeper.deleted || deadman.deleted { fatalError("TRYING TO MERGE DELETED ITEMS") }
if keeper.isMergeLocked || deadman.isMergeLocked || betweener?.isMergeLocked == true { return .impossible }
if keeper.deleted || deadman.deleted || betweener?.deleted == true { return .impossible }
return self.keeper.scoreForConsuming(item: self.deadman)
}()

Expand All @@ -42,7 +42,7 @@ public class Merge: CustomStringConvertible {
if let betweener = betweener { store.release(betweener) }
}

func doIt() -> (kept: TimelineItem, killed: [TimelineItem]) {
@discardableResult func doIt() -> (kept: TimelineItem, killed: [TimelineItem]) {
merge(deadman, into: keeper)

if let betweener = betweener {
Expand Down Expand Up @@ -79,7 +79,7 @@ public class Merge: CustomStringConvertible {

// MARK: CustomStringConvertible

public var description: String {
var description: String {
if let betweener = betweener {
return String(format: "score: %d (%@) <- (%@) <- (%@)", score.rawValue, String(describing: keeper),
String(describing: betweener), String(describing: deadman))
Expand All @@ -88,4 +88,5 @@ public class Merge: CustomStringConvertible {
String(describing: deadman))
}
}

}
Loading

0 comments on commit 9323ddc

Please sign in to comment.