Skip to content

Commit

Permalink
start using named params, to avoid silly mistakes like with yesterday…
Browse files Browse the repository at this point in the history
…'s params reordering #11
  • Loading branch information
sobri909 committed Jun 3, 2018
1 parent 7b7998c commit 8260b0a
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions LocoKit/LocalStore/PersistentProcessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public class PersistentProcessor {
}

// find the overlapping items
let overlappers = store.items(where: "endDate > ? AND startDate < ? AND deleted = 0 ORDER BY startDate",
arguments: [segmentRange.start, segmentRange.end])
let overlappers = store.items(
where: "endDate > :startDate AND startDate < :endDate AND deleted = 0 ORDER BY startDate",
arguments: ["startDate": segmentRange.start, "endDate": segmentRange.end])

var modifiedItems: [TimelineItem] = []
var samplesToSteal: [LocomotionSample] = []
Expand Down Expand Up @@ -134,8 +135,12 @@ public class PersistentProcessor {
guard let dateRange = brokenItem.dateRange else { return }

if let overlapper = store.item(
where: "startDate < ? AND endDate > ? AND startDate IS NOT NULL AND endDate IS NOT NULL AND deleted = 0 AND itemId != ?",
arguments: [brokenItem.itemId.uuidString, dateRange.start, dateRange.end]),
where: """
startDate <= :startDate AND endDate >= :endDate AND startDate IS NOT NULL AND endDate IS NOT NULL
AND deleted = 0 AND itemId != :itemId
""",
arguments: ["startDate": dateRange.start, "endDate": dateRange.end,
"itemId": brokenItem.itemId.uuidString]),
!overlapper.deleted
{
print("healEdges(of: \(brokenItem.itemId.shortString)) MERGED INTO CONTAINING ITEM")
Expand All @@ -155,8 +160,10 @@ public class PersistentProcessor {
print("healNextEdge(of: \(brokenItem.itemId.shortString))")

if let nearest = store.item(
where: "startDate >= ? AND deleted = 0 AND itemId != ? ORDER BY ABS(strftime('%s', startDate) - ?)",
arguments: [brokenItem.itemId.uuidString, endDate, endDate.timeIntervalSince1970]), !nearest.deleted
where: "startDate >= :endDate AND deleted = 0 AND itemId != :itemId ORDER BY ABS(strftime('%s', startDate) - :timestamp)",
arguments: ["endDate": endDate, "itemId": brokenItem.itemId.uuidString,
"timestamp": endDate.timeIntervalSince1970]),
!nearest.deleted
{
if nearest.previousItemId == brokenItem.itemId {
print("healNextEdge(of: \(brokenItem.itemId.shortString)) NOT BROKEN")
Expand Down Expand Up @@ -193,8 +200,13 @@ public class PersistentProcessor {
}

if let overlapper = store.item(
where: "startDate < ? AND endDate > ? AND startDate IS NOT NULL AND endDate IS NOT NULL AND isVisit = ? AND deleted = 0 AND itemId != ?",
arguments: [brokenItem.itemId.uuidString, brokenItem is Visit, endDate, endDate]), !overlapper.deleted
where: """
startDate < :endDate1 AND endDate > :endDate2 AND startDate IS NOT NULL AND endDate IS NOT NULL
AND isVisit = :isVisit AND deleted = 0 AND itemId != :itemId
""",
arguments: ["endDate1": endDate, "endDate2": endDate, "isVisit": brokenItem is Visit,
"itemId": brokenItem.itemId.uuidString]),
!overlapper.deleted
{
print("healNextEdge(of: \(brokenItem.itemId.shortString)) MERGED INTO OVERLAPPING ITEM")
overlapper.add(brokenItem.samples)
Expand All @@ -214,8 +226,10 @@ public class PersistentProcessor {
print("healPreviousEdge(of: \(brokenItem.itemId.shortString))")

if let nearest = store.item(
where: "endDate <= ? AND deleted = 0 AND itemId != ? ORDER BY ABS(strftime('%s', endDate) - ?)",
arguments: [brokenItem.itemId.uuidString, startDate, startDate.timeIntervalSince1970]), !nearest.deleted
where: "endDate <= :startDate AND deleted = 0 AND itemId != :itemId ORDER BY ABS(strftime('%s', endDate) - :timestamp)",
arguments: ["startDate": startDate, "itemId": brokenItem.itemId.uuidString,
"timestamp": startDate.timeIntervalSince1970]),
!nearest.deleted
{
if nearest.nextItemId == brokenItem.itemId {
print("healPreviousEdge(of: \(brokenItem.itemId.shortString)) NOT BROKEN")
Expand Down Expand Up @@ -252,8 +266,13 @@ public class PersistentProcessor {
}

if let overlapper = store.item(
where: "startDate < ? AND endDate > ? AND startDate IS NOT NULL AND endDate IS NOT NULL AND isVisit = ? AND deleted = 0 AND itemId != ?",
arguments: [brokenItem.itemId.uuidString, brokenItem is Visit, startDate, startDate]), !overlapper.deleted
where: """
startDate < :startDate1 AND endDate > :startDate2 AND startDate IS NOT NULL AND endDate IS NOT NULL
AND isVisit = :isVisit AND deleted = 0 AND itemId != :itemId
""",
arguments: ["startDate1": startDate, "startDate2": startDate, "isVisit": brokenItem is Visit,
"itemId": brokenItem.itemId.uuidString]),
!overlapper.deleted
{
print("healPreviousEdge(of: \(brokenItem.itemId.shortString)) MERGED INTO OVERLAPPING ITEM")
overlapper.add(brokenItem.samples)
Expand Down

0 comments on commit 8260b0a

Please sign in to comment.