Skip to content

Commit

Permalink
flattening time index
Browse files Browse the repository at this point in the history
  • Loading branch information
mjoerke committed Mar 28, 2024
1 parent 18e0bc8 commit a441543
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions Prisma/Helper/Date+ConstructTimeIndex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ extension Date {
var timeIndex: [String: Any?] = [
"range": isRange,
"timezone": startComponents.timeZone?.identifier,
"datetime.start": startDate.toISOFormat(),
"datetime.end": endDate.toISOFormat()
"datetimeStart": startDate.toISOFormat(),
"datetimeEnd": endDate.toISOFormat()

Check warning on line 25 in Prisma/Helper/Date+ConstructTimeIndex.swift

View check run for this annotation

Codecov / codecov/patch

Prisma/Helper/Date+ConstructTimeIndex.swift#L24-L25

Added lines #L24 - L25 were not covered by tests
]

// passing the timeIndex dictionary by reference so the changes persist
addTimeIndexComponents(&timeIndex, dateComponents: startComponents, suffix: ".start")
addTimeIndexComponents(&timeIndex, dateComponents: endComponents, suffix: ".end")
addTimeIndexComponents(&timeIndex, dateComponents: startComponents, suffix: "Start")
addTimeIndexComponents(&timeIndex, dateComponents: endComponents, suffix: "End")

Check warning on line 30 in Prisma/Helper/Date+ConstructTimeIndex.swift

View check run for this annotation

Codecov / codecov/patch

Prisma/Helper/Date+ConstructTimeIndex.swift#L29-L30

Added lines #L29 - L30 were not covered by tests
addTimeIndexRangeComponents(&timeIndex, startComponents: startComponents, endComponents: endComponents)

return timeIndex
Expand All @@ -54,34 +54,34 @@ extension Date {
startComponents: DateComponents,
endComponents: DateComponents
) {
timeIndex["year.range"] = getRange(
timeIndex["yearRange"] = getRange(

Check warning on line 57 in Prisma/Helper/Date+ConstructTimeIndex.swift

View check run for this annotation

Codecov / codecov/patch

Prisma/Helper/Date+ConstructTimeIndex.swift#L57

Added line #L57 was not covered by tests
start: startComponents.year,
end: endComponents.year,
maxValue: Int.max
)
timeIndex["month.range"] = getRange(
timeIndex["monthRange"] = getRange(

Check warning on line 62 in Prisma/Helper/Date+ConstructTimeIndex.swift

View check run for this annotation

Codecov / codecov/patch

Prisma/Helper/Date+ConstructTimeIndex.swift#L62

Added line #L62 was not covered by tests
start: startComponents.month,
end: endComponents.month,
maxValue: 12,
startValue: 1 // months are 1-indexed
)
timeIndex["day.range"] = getRange(
timeIndex["dayRange"] = getRange(

Check warning on line 68 in Prisma/Helper/Date+ConstructTimeIndex.swift

View check run for this annotation

Codecov / codecov/patch

Prisma/Helper/Date+ConstructTimeIndex.swift#L68

Added line #L68 was not covered by tests
start: startComponents.day,
end: endComponents.day,
maxValue: daysInMonth(month: startComponents.month, year: startComponents.year),
startValue: 1 // days are 1-indexed
)
timeIndex["hour.range"] = getRange(
timeIndex["hourRange"] = getRange(

Check warning on line 74 in Prisma/Helper/Date+ConstructTimeIndex.swift

View check run for this annotation

Codecov / codecov/patch

Prisma/Helper/Date+ConstructTimeIndex.swift#L74

Added line #L74 was not covered by tests
start: startComponents.hour,
end: endComponents.hour,
maxValue: 23
)
timeIndex["dayMinute.range"] = getRange(
timeIndex["dayMinuteRange"] = getRange(

Check warning on line 79 in Prisma/Helper/Date+ConstructTimeIndex.swift

View check run for this annotation

Codecov / codecov/patch

Prisma/Helper/Date+ConstructTimeIndex.swift#L79

Added line #L79 was not covered by tests
start: calculateDayMinute(hour: startComponents.hour, minute: startComponents.minute),
end: calculateDayMinute(hour: endComponents.hour, minute: endComponents.minute),
maxValue: 1439
)
timeIndex["fifteenMinBucket.range"] = getRange(
timeIndex["fifteenMinBucketRange"] = getRange(

Check warning on line 84 in Prisma/Helper/Date+ConstructTimeIndex.swift

View check run for this annotation

Codecov / codecov/patch

Prisma/Helper/Date+ConstructTimeIndex.swift#L84

Added line #L84 was not covered by tests
start: calculate15MinBucket(hour: startComponents.hour, minute: startComponents.minute),
end: calculate15MinBucket(hour: endComponents.hour, minute: endComponents.minute),
maxValue: 95
Expand Down
4 changes: 2 additions & 2 deletions Prisma/Standard/PrismaStandard+HealthKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ extension PrismaStandard: HealthKitConstraint {
var firestoreResource = try encoder.encode(resource)
firestoreResource["device"] = deviceName
// timeIndex is a dictionary with time-related info (range, timezone, datetime.start, datetime.end)
// timeIndex is added a field for this specific HK datapoint so we can just access this part to fetch/sort by time
firestoreResource["time"] = timeIndex
// timeIndex fields are merged with this specific HK datapoint so we can just access this part to fetch/sort by time
firestoreResource.merge(timeIndex as [String : Any]) { (_, new) in new }

Check failure on line 52 in Prisma/Standard/PrismaStandard+HealthKit.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint

Colon Spacing Violation: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals (colon)

Check failure on line 52 in Prisma/Standard/PrismaStandard+HealthKit.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint

Unneeded Parentheses in Closure Argument Violation: Parentheses are not needed when declaring closure arguments (unneeded_parentheses_in_closure_argument)

Check warning on line 52 in Prisma/Standard/PrismaStandard+HealthKit.swift

View check run for this annotation

Codecov / codecov/patch

Prisma/Standard/PrismaStandard+HealthKit.swift#L51-L52

Added lines #L51 - L52 were not covered by tests
firestoreResource["datetimeStart"] = effectiveTimestamp
try await Firestore.firestore().document(path).setData(firestoreResource)
} catch {
Expand Down

0 comments on commit a441543

Please sign in to comment.