Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flatten Time Index #50

Merged
merged 2 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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 @@
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 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
Loading