Commit 9cdcebe9 by Demid Merzlyakov

IOS-171: minutely storage

parent c635c149
...@@ -38,6 +38,10 @@ ...@@ -38,6 +38,10 @@
CD69DBC22666381500FD2A7C /* OneWeatherAnalytics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD69DBC12666381500FD2A7C /* OneWeatherAnalytics.framework */; }; CD69DBC22666381500FD2A7C /* OneWeatherAnalytics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD69DBC12666381500FD2A7C /* OneWeatherAnalytics.framework */; };
CD8EA914265D42E2000D3D63 /* 1WModel.xcdatamodeld in Resources */ = {isa = PBXBuildFile; fileRef = CD3884372657BA420070FD6F /* 1WModel.xcdatamodeld */; }; CD8EA914265D42E2000D3D63 /* 1WModel.xcdatamodeld in Resources */ = {isa = PBXBuildFile; fileRef = CD3884372657BA420070FD6F /* 1WModel.xcdatamodeld */; };
CE0E006C26C739680060CBB6 /* CoreDataStack.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE0E006B26C739680060CBB6 /* CoreDataStack.swift */; }; CE0E006C26C739680060CBB6 /* CoreDataStack.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE0E006B26C739680060CBB6 /* CoreDataStack.swift */; };
CEC40AF42705A2BF00C98305 /* _CoreMinutelyForecast.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC40AF22705A2BE00C98305 /* _CoreMinutelyForecast.swift */; };
CEC40AF52705A2BF00C98305 /* _CoreMinutelyItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC40AF32705A2BE00C98305 /* _CoreMinutelyItem.swift */; };
CEC40AF82705A2C900C98305 /* CoreMinutelyItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC40AF62705A2C900C98305 /* CoreMinutelyItem.swift */; };
CEC40AF92705A2C900C98305 /* CoreMinutelyForecast.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEC40AF72705A2C900C98305 /* CoreMinutelyForecast.swift */; };
CEEF40F9265E2EE600425D8F /* OneWeatherCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CEEF40F8265E2EE600425D8F /* OneWeatherCore.framework */; }; CEEF40F9265E2EE600425D8F /* OneWeatherCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CEEF40F8265E2EE600425D8F /* OneWeatherCore.framework */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
...@@ -88,6 +92,11 @@ ...@@ -88,6 +92,11 @@
CD38843A2657BA420070FD6F /* CoreDataStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataStorage.swift; sourceTree = "<group>"; }; CD38843A2657BA420070FD6F /* CoreDataStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataStorage.swift; sourceTree = "<group>"; };
CD69DBC12666381500FD2A7C /* OneWeatherAnalytics.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = OneWeatherAnalytics.framework; sourceTree = BUILT_PRODUCTS_DIR; }; CD69DBC12666381500FD2A7C /* OneWeatherAnalytics.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = OneWeatherAnalytics.framework; sourceTree = BUILT_PRODUCTS_DIR; };
CE0E006B26C739680060CBB6 /* CoreDataStack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataStack.swift; sourceTree = "<group>"; }; CE0E006B26C739680060CBB6 /* CoreDataStack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataStack.swift; sourceTree = "<group>"; };
CEC40AF1270587F600C98305 /* 1.2.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = 1.2.xcdatamodel; sourceTree = "<group>"; };
CEC40AF22705A2BE00C98305 /* _CoreMinutelyForecast.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = _CoreMinutelyForecast.swift; sourceTree = "<group>"; };
CEC40AF32705A2BE00C98305 /* _CoreMinutelyItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = _CoreMinutelyItem.swift; sourceTree = "<group>"; };
CEC40AF62705A2C900C98305 /* CoreMinutelyItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreMinutelyItem.swift; sourceTree = "<group>"; };
CEC40AF72705A2C900C98305 /* CoreMinutelyForecast.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreMinutelyForecast.swift; sourceTree = "<group>"; };
CEEF40F8265E2EE600425D8F /* OneWeatherCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = OneWeatherCore.framework; sourceTree = BUILT_PRODUCTS_DIR; }; CEEF40F8265E2EE600425D8F /* OneWeatherCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = OneWeatherCore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
E5F0E97C8CB8930C9E20B7FD /* Pods-CoreDataStorage.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CoreDataStorage.debug.xcconfig"; path = "Target Support Files/Pods-CoreDataStorage/Pods-CoreDataStorage.debug.xcconfig"; sourceTree = "<group>"; }; E5F0E97C8CB8930C9E20B7FD /* Pods-CoreDataStorage.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CoreDataStorage.debug.xcconfig"; path = "Target Support Files/Pods-CoreDataStorage/Pods-CoreDataStorage.debug.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
...@@ -173,6 +182,8 @@ ...@@ -173,6 +182,8 @@
CD3884262657BA410070FD6F /* CoreHourlyWeather.swift */, CD3884262657BA410070FD6F /* CoreHourlyWeather.swift */,
CD3884272657BA410070FD6F /* CoreNotifications.swift */, CD3884272657BA410070FD6F /* CoreNotifications.swift */,
CD3884282657BA410070FD6F /* CoreNWSAlert.swift */, CD3884282657BA410070FD6F /* CoreNWSAlert.swift */,
CEC40AF72705A2C900C98305 /* CoreMinutelyForecast.swift */,
CEC40AF62705A2C900C98305 /* CoreMinutelyItem.swift */,
); );
path = Human; path = Human;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -190,6 +201,8 @@ ...@@ -190,6 +201,8 @@
CD3884312657BA410070FD6F /* _CoreDailyWeather.swift */, CD3884312657BA410070FD6F /* _CoreDailyWeather.swift */,
CD3884322657BA410070FD6F /* _CoreNotifications.swift */, CD3884322657BA410070FD6F /* _CoreNotifications.swift */,
CD3884332657BA410070FD6F /* _CoreNWSAlert.swift */, CD3884332657BA410070FD6F /* _CoreNWSAlert.swift */,
CEC40AF22705A2BE00C98305 /* _CoreMinutelyForecast.swift */,
CEC40AF32705A2BE00C98305 /* _CoreMinutelyItem.swift */,
); );
path = Machine; path = Machine;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -365,10 +378,12 @@ ...@@ -365,10 +378,12 @@
CD3884442657BA550070FD6F /* CoreHealth.swift in Sources */, CD3884442657BA550070FD6F /* CoreHealth.swift in Sources */,
CD3884452657BA550070FD6F /* CoreLocation.swift in Sources */, CD3884452657BA550070FD6F /* CoreLocation.swift in Sources */,
CD3884462657BA550070FD6F /* CoreDailyWeather.swift in Sources */, CD3884462657BA550070FD6F /* CoreDailyWeather.swift in Sources */,
CEC40AF52705A2BF00C98305 /* _CoreMinutelyItem.swift in Sources */,
CD3884472657BA550070FD6F /* CoreHourlyWeather.swift in Sources */, CD3884472657BA550070FD6F /* CoreHourlyWeather.swift in Sources */,
CD3884482657BA550070FD6F /* CoreNotifications.swift in Sources */, CD3884482657BA550070FD6F /* CoreNotifications.swift in Sources */,
CD3884492657BA550070FD6F /* CoreNWSAlert.swift in Sources */, CD3884492657BA550070FD6F /* CoreNWSAlert.swift in Sources */,
CD38844A2657BA550070FD6F /* _CoreAppData.swift in Sources */, CD38844A2657BA550070FD6F /* _CoreAppData.swift in Sources */,
CEC40AF82705A2C900C98305 /* CoreMinutelyItem.swift in Sources */,
CD38844B2657BA550070FD6F /* _CoreAirQuality.swift in Sources */, CD38844B2657BA550070FD6F /* _CoreAirQuality.swift in Sources */,
CD38844C2657BA550070FD6F /* _CorePollutant.swift in Sources */, CD38844C2657BA550070FD6F /* _CorePollutant.swift in Sources */,
CD38844D2657BA550070FD6F /* _CoreHourlyWeather.swift in Sources */, CD38844D2657BA550070FD6F /* _CoreHourlyWeather.swift in Sources */,
...@@ -376,11 +391,13 @@ ...@@ -376,11 +391,13 @@
CD38844F2657BA550070FD6F /* _CoreLocation.swift in Sources */, CD38844F2657BA550070FD6F /* _CoreLocation.swift in Sources */,
CD3884502657BA550070FD6F /* _CoreCurrentWeather.swift in Sources */, CD3884502657BA550070FD6F /* _CoreCurrentWeather.swift in Sources */,
CD3884512657BA550070FD6F /* _CoreDailyWeather.swift in Sources */, CD3884512657BA550070FD6F /* _CoreDailyWeather.swift in Sources */,
CEC40AF42705A2BF00C98305 /* _CoreMinutelyForecast.swift in Sources */,
CD3884522657BA550070FD6F /* _CoreNotifications.swift in Sources */, CD3884522657BA550070FD6F /* _CoreNotifications.swift in Sources */,
CD3884532657BA550070FD6F /* _CoreNWSAlert.swift in Sources */, CD3884532657BA550070FD6F /* _CoreNWSAlert.swift in Sources */,
CE0E006C26C739680060CBB6 /* CoreDataStack.swift in Sources */, CE0E006C26C739680060CBB6 /* CoreDataStack.swift in Sources */,
CD38843F2657BA430070FD6F /* CoreDataStorage.swift in Sources */, CD38843F2657BA430070FD6F /* CoreDataStorage.swift in Sources */,
CD38843B2657BA430070FD6F /* CoreDataAppModelConvertable.swift in Sources */, CD38843B2657BA430070FD6F /* CoreDataAppModelConvertable.swift in Sources */,
CEC40AF92705A2C900C98305 /* CoreMinutelyForecast.swift in Sources */,
CD38843D2657BA430070FD6F /* CoreDataError.swift in Sources */, CD38843D2657BA430070FD6F /* CoreDataError.swift in Sources */,
CD38843E2657BA430070FD6F /* CoreDataUtils.swift in Sources */, CD38843E2657BA430070FD6F /* CoreDataUtils.swift in Sources */,
); );
...@@ -655,9 +672,10 @@ ...@@ -655,9 +672,10 @@
CD3884372657BA420070FD6F /* 1WModel.xcdatamodeld */ = { CD3884372657BA420070FD6F /* 1WModel.xcdatamodeld */ = {
isa = XCVersionGroup; isa = XCVersionGroup;
children = ( children = (
CEC40AF1270587F600C98305 /* 1.2.xcdatamodel */,
CD3884362657BA420070FD6F /* Model.xcdatamodel */, CD3884362657BA420070FD6F /* Model.xcdatamodel */,
); );
currentVersion = CD3884362657BA420070FD6F /* Model.xcdatamodel */; currentVersion = CEC40AF1270587F600C98305 /* 1.2.xcdatamodel */;
path = 1WModel.xcdatamodeld; path = 1WModel.xcdatamodeld;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>_XCCurrentVersionName</key>
<string>1.2.xcdatamodel</string>
</dict>
</plist>
...@@ -37,6 +37,7 @@ open class CoreLocation: _CoreLocation, CoreDataAppModelConvertable { ...@@ -37,6 +37,7 @@ open class CoreLocation: _CoreLocation, CoreDataAppModelConvertable {
location.health = try self.health?.toAppModel() location.health = try self.health?.toAppModel()
location.notifications = try self.notifications?.toAppModel() location.notifications = try self.notifications?.toAppModel()
location.minutely = try self.minutely?.toAppModel()
return location return location
} }
...@@ -86,6 +87,9 @@ open class CoreLocation: _CoreLocation, CoreDataAppModelConvertable { ...@@ -86,6 +87,9 @@ open class CoreLocation: _CoreLocation, CoreDataAppModelConvertable {
self.notifications = skipIfError(attribute: "notifications", action: { self.notifications = skipIfError(attribute: "notifications", action: {
try CoreNotifications(context: context, appModel: appModel.notifications) try CoreNotifications(context: context, appModel: appModel.notifications)
}) })
self.minutely = skipIfError(attribute: "minutely", action: {
try CoreMinutelyForecast(context: context, appModel: appModel.minutely)
})
} }
private func skipIfError<T>(attribute: String, action: () throws -> T?) -> T? { private func skipIfError<T>(attribute: String, action: () throws -> T?) -> T? {
......
import Foundation
import CoreData
import OneWeatherCore
import OneWeatherAnalytics
@objc(CoreMinutelyForecast)
open class CoreMinutelyForecast: _CoreMinutelyForecast, CoreDataAppModelConvertable {
func toAppModel() throws -> MinutelyForecast {
let lastUpdateTime: Date = self.lastUpdateTime
var minutely = [MinutelyItem]()
try CoreDataUtils.foreach(in: items, of: self, attributeName: "minutely") { (coreMinutelyItem: CoreMinutelyItem) in
minutely.append(try coreMinutelyItem.toAppModel())
}
return MinutelyForecast(lastUpdateTime: lastUpdateTime, forecast: minutely)
}
/// This is here just so that we could inherit the generated init(managedObjectContext) convenience initializer.
public override init(entity: NSEntityDescription, insertInto context: NSManagedObjectContext?) {
super.init(entity: entity, insertInto: context)
}
required public init?(context: NSManagedObjectContext, appModel: MinutelyForecast?) throws {
guard let appModel = appModel else {
return nil
}
self.init(managedObjectContext: context)
self.lastUpdateTime = appModel.lastUpdateTime
self.items = NSOrderedSet(array: appModel.forecast.compactMap { elem in
skipIfError(attribute: "minutely") {
try CoreMinutelyItem(context: context, appModel: elem)
}
})
}
private func skipIfError<T>(attribute: String, action: () throws -> T?) -> T? {
do {
let result = try action()
return result
}
catch {
Logger(componentName: "CoreLocation").error("Couldn't parse \(attribute) in CoreLocation due to error: \(error)")
return nil
}
}
typealias AppModel = MinutelyForecast
}
import Foundation
import CoreData
import OneWeatherCore
@objc(CoreMinutelyItem)
open class CoreMinutelyItem: _CoreMinutelyItem, CoreDataAppModelConvertable {
func toAppModel() throws -> MinutelyItem {
guard let temp: Temperature = try CoreDataUtils.measurement(from: self.temp, in: self, attributeName: "temp") else {
throw CoreDataError.LoadAttributeError(entity: self, attributeName: "temp", value: self.temp, nestedError: nil)
}
guard let windSpeed: WindSpeed = try CoreDataUtils.measurement(from: self.windSpeed, in: self, attributeName: "windSpeed") else {
throw CoreDataError.LoadAttributeError(entity: self, attributeName: "windSpeed", value: self.windSpeed, nestedError: nil)
}
guard let pressure: Pressure = try CoreDataUtils.measurement(from: self.pressure, in: self, attributeName: "pressure") else {
throw CoreDataError.LoadAttributeError(entity: self, attributeName: "pressure", value: self.pressure, nestedError: nil)
}
return MinutelyItem(time: time, temp: temp, precipitation: precipitation, windSpeed: windSpeed, pressure: pressure)
}
/// This is here just so that we could inherit the generated init(managedObjectContext) convenience initializer.
public override init(entity: NSEntityDescription, insertInto context: NSManagedObjectContext?) {
super.init(entity: entity, insertInto: context)
}
required public init?(context: NSManagedObjectContext, appModel: MinutelyItem?) throws {
guard let appModel = appModel else {
return nil
}
self.init(managedObjectContext: context)
self.time = appModel.time
self.precipitation = appModel.precipitation
self.temp = try CoreDataUtils.measurementToData(appModel.temp, in: self, attributeName: "temp")
self.windSpeed = try CoreDataUtils.measurementToData(appModel.windSpeed, in: self, attributeName: "windSpeed")
self.pressure = try CoreDataUtils.measurementToData(appModel.pressure, in: self, attributeName: "pressure")
}
typealias AppModel = MinutelyItem
}
...@@ -25,6 +25,7 @@ public enum CoreLocationRelationships: String { ...@@ -25,6 +25,7 @@ public enum CoreLocationRelationships: String {
case daily = "daily" case daily = "daily"
case health = "health" case health = "health"
case hourly = "hourly" case hourly = "hourly"
case minutely = "minutely"
case notifications = "notifications" case notifications = "notifications"
case today = "today" case today = "today"
} }
...@@ -121,6 +122,9 @@ open class _CoreLocation: NSManagedObject { ...@@ -121,6 +122,9 @@ open class _CoreLocation: NSManagedObject {
} }
@NSManaged open @NSManaged open
var minutely: CoreMinutelyForecast?
@NSManaged open
var notifications: CoreNotifications? var notifications: CoreNotifications?
@NSManaged open @NSManaged open
......
// DO NOT EDIT. This file is machine-generated and constantly overwritten.
// Make changes to CoreMinutelyForecast.swift instead.
import Foundation
import CoreData
public enum CoreMinutelyForecastAttributes: String {
case lastUpdateTime = "lastUpdateTime"
}
public enum CoreMinutelyForecastRelationships: String {
case items = "items"
case location = "location"
}
open class _CoreMinutelyForecast: NSManagedObject {
// MARK: - Class methods
open class func entityName () -> String {
return "CoreMinutelyForecast"
}
open class func entity(managedObjectContext: NSManagedObjectContext) -> NSEntityDescription? {
return NSEntityDescription.entity(forEntityName: self.entityName(), in: managedObjectContext)
}
@nonobjc
open class func fetchRequest() -> NSFetchRequest<CoreMinutelyForecast> {
return NSFetchRequest(entityName: self.entityName())
}
// MARK: - Life cycle methods
public override init(entity: NSEntityDescription, insertInto context: NSManagedObjectContext?) {
super.init(entity: entity, insertInto: context)
}
public convenience init?(managedObjectContext: NSManagedObjectContext) {
guard let entity = _CoreMinutelyForecast.entity(managedObjectContext: managedObjectContext) else { return nil }
self.init(entity: entity, insertInto: managedObjectContext)
}
// MARK: - Properties
@NSManaged open
var lastUpdateTime: Date!
// MARK: - Relationships
@NSManaged open
var items: NSOrderedSet
open func itemsSet() -> NSMutableOrderedSet {
return self.items.mutableCopy() as! NSMutableOrderedSet
}
@NSManaged open
var location: CoreLocation
}
extension _CoreMinutelyForecast {
open func addItems(_ objects: NSOrderedSet) {
let mutable = self.items.mutableCopy() as! NSMutableOrderedSet
mutable.union(objects)
self.items = mutable.copy() as! NSOrderedSet
}
open func removeItems(_ objects: NSOrderedSet) {
let mutable = self.items.mutableCopy() as! NSMutableOrderedSet
mutable.minus(objects)
self.items = mutable.copy() as! NSOrderedSet
}
open func addItemsObject(_ value: CoreMinutelyItem) {
let mutable = self.items.mutableCopy() as! NSMutableOrderedSet
mutable.add(value)
self.items = mutable.copy() as! NSOrderedSet
}
open func removeItemsObject(_ value: CoreMinutelyItem) {
let mutable = self.items.mutableCopy() as! NSMutableOrderedSet
mutable.remove(value)
self.items = mutable.copy() as! NSOrderedSet
}
}
// DO NOT EDIT. This file is machine-generated and constantly overwritten.
// Make changes to CoreMinutelyItem.swift instead.
import Foundation
import CoreData
public enum CoreMinutelyItemAttributes: String {
case precipitation = "precipitation"
case pressure = "pressure"
case temp = "temp"
case time = "time"
case windSpeed = "windSpeed"
}
public enum CoreMinutelyItemRelationships: String {
case forecast = "forecast"
}
open class _CoreMinutelyItem: NSManagedObject {
// MARK: - Class methods
open class func entityName () -> String {
return "CoreMinutelyItem"
}
open class func entity(managedObjectContext: NSManagedObjectContext) -> NSEntityDescription? {
return NSEntityDescription.entity(forEntityName: self.entityName(), in: managedObjectContext)
}
@nonobjc
open class func fetchRequest() -> NSFetchRequest<CoreMinutelyItem> {
return NSFetchRequest(entityName: self.entityName())
}
// MARK: - Life cycle methods
public override init(entity: NSEntityDescription, insertInto context: NSManagedObjectContext?) {
super.init(entity: entity, insertInto: context)
}
public convenience init?(managedObjectContext: NSManagedObjectContext) {
guard let entity = _CoreMinutelyItem.entity(managedObjectContext: managedObjectContext) else { return nil }
self.init(entity: entity, insertInto: managedObjectContext)
}
// MARK: - Properties
@NSManaged open
var precipitation: Double
@NSManaged open
var pressure: Data!
@NSManaged open
var temp: Data!
@NSManaged open
var time: Date!
@NSManaged open
var windSpeed: Data!
// MARK: - Relationships
@NSManaged open
var forecast: CoreMinutelyForecast
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment