168 lines
9.2 KiB
Swift
168 lines
9.2 KiB
Swift
//
|
|
// EQNData.swift
|
|
// Earthquake Network
|
|
//
|
|
// Created by Busi Andrea on 26/08/2020.
|
|
// Copyright © 2020 Earthquake Network. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
|
|
@objc class EQNData: NSObject {
|
|
static let MaxRaggioSisma = "100000"
|
|
static let DefaultSettingSeismicNetworkNotificationRadius = EQNGenericValue(value:"500", display:"500 km")
|
|
static let DefaultSettingSeismicNetworkNotificationMagitude = EQNGenericValue(value:"2.0", display:"official_magnitude_value_20")
|
|
static let DefaultSettingUserReportNotificationRadius = EQNGenericValue(value:"1000", display:"1000 km")
|
|
static let DefaultFilterRadius = EQNGenericValue(value:"250", display:"250 km")
|
|
static let DefaultFilterMagnitude = EQNGenericValue(value:"0.0", display:"official_magnitude_value_00")
|
|
|
|
// MARK: - Public
|
|
|
|
// Distances for "seismic network notifications"
|
|
static let settingSeismicNetworkNotificationRadius: [EQNGenericValue] = [
|
|
EQNGenericValue(value:"100", display:"100 km"),
|
|
EQNGenericValue(value:"250", display:"250 km"),
|
|
EQNGenericValue(value:"500", display:"500 km"),
|
|
EQNGenericValue(value:"1000", display:"1000 km")
|
|
]
|
|
|
|
// Magnitudes for "seismic network notifications"
|
|
static let settingSeismicNetworkNotificationMagnitudes: [EQNGenericValue] = [
|
|
EQNGenericValue(value:"0.0", display:"0.0"),
|
|
EQNGenericValue(value:"0.5", display:"0.5"),
|
|
EQNGenericValue(value:"1.0", display:"1.0"),
|
|
EQNGenericValue(value:"1.5", display:"1.5"),
|
|
EQNGenericValue(value:"2.0", display:"2.0"),
|
|
EQNGenericValue(value:"2.5", display:"2.5"),
|
|
EQNGenericValue(value:"3.0", display:"3.0"),
|
|
EQNGenericValue(value:"3.5", display:"3.5"),
|
|
EQNGenericValue(value:"4.0", display:"4.0"),
|
|
EQNGenericValue(value:"4.5", display:"4.5"),
|
|
EQNGenericValue(value:"5.0", display:"5.0"),
|
|
EQNGenericValue(value:"5.5", display:"5.5")
|
|
]
|
|
|
|
// Distances for "user report notifications"
|
|
static let settingUserReportNotificationRadius: [EQNGenericValue] = [
|
|
EQNGenericValue(value:"100", display:"100 km"),
|
|
EQNGenericValue(value:"250", display:"250 km"),
|
|
EQNGenericValue(value:"500", display:"500 km"),
|
|
EQNGenericValue(value:"1000", display:"1000 km")
|
|
]
|
|
|
|
// Misure raggio utilizzate nei filtri
|
|
static let filterRadius: [EQNGenericValue] = [
|
|
EQNGenericValue(value:"100", display:"100 km"),
|
|
EQNGenericValue(value:"250", display:"250 km"),
|
|
EQNGenericValue(value:"500", display:"500 km"),
|
|
EQNGenericValue(value:"750", display:"750 km"),
|
|
EQNGenericValue(value:"1000", display:"1000 km"),
|
|
EQNGenericValue(value:"1500", display:"1500 km"),
|
|
EQNGenericValue(value:"2000", display:"2000 km")
|
|
]
|
|
|
|
// Magnitudo utilizzate nei filtri
|
|
static let filterMagnitude: [EQNGenericValue] = [
|
|
EQNGenericValue(value:"0.0", display:"0.0"),
|
|
EQNGenericValue(value:"1.0", display:"1.0"),
|
|
EQNGenericValue(value:"2.0", display:"2.0"),
|
|
EQNGenericValue(value:"3.0", display:"3.0"),
|
|
EQNGenericValue(value:"4.0", display:"4.0"),
|
|
EQNGenericValue(value:"5.0", display:"5.0"),
|
|
EQNGenericValue(value:"6.0", display:"6.0")
|
|
]
|
|
|
|
/// Returns the EQNGenericValue for the given value, or the default one
|
|
/// - Parameter value: Sisma radius to search
|
|
/// - Returns: Found value or default
|
|
@objc(getSettingSeismicNetworkAlertRadiusForValue:)
|
|
class func getSettingSeismicNetworkNotificationRadius(for value: String?) -> EQNGenericValue {
|
|
if let value = value, let genericValue = settingSeismicNetworkNotificationRadius.first(where: { $0.value == value }) {
|
|
return genericValue
|
|
}
|
|
return DefaultSettingSeismicNetworkNotificationRadius
|
|
}
|
|
|
|
/// Returns the EQNGenericValue for the given value, or the default one
|
|
/// - Parameter value: Magnitudo value to search
|
|
/// - Returns: Found value or default
|
|
class func getSettingSeismicNetworkNotificationMagnitudes(for value: String?) -> EQNGenericValue {
|
|
if let value = value, let genericValue = settingSeismicNetworkNotificationMagnitudes.first(where: { $0.value == value }) {
|
|
return genericValue
|
|
}
|
|
return DefaultSettingSeismicNetworkNotificationMagitude
|
|
}
|
|
|
|
/// Returns the EQNGenericValue for the given value, or the default one
|
|
/// - Parameter value: Sisma radius to search
|
|
/// - Returns: Found value or default
|
|
class func getSettingUserReportNotificationRadius(for value: String?) -> EQNGenericValue {
|
|
if let value = value, let genericValue = settingUserReportNotificationRadius.first(where: { $0.value == value }) {
|
|
return genericValue
|
|
}
|
|
return DefaultSettingUserReportNotificationRadius
|
|
}
|
|
|
|
/// Returns the EQNGenericValue for the given value, or the default one
|
|
/// - Parameter value: Sisma radius to search
|
|
/// - Returns: Found value or default
|
|
class func filterRadius(for value: String?) -> EQNGenericValue {
|
|
if let value = value, let genericValue = filterRadius.first(where: { $0.value == value }) {
|
|
return genericValue
|
|
}
|
|
return DefaultFilterRadius
|
|
}
|
|
|
|
/// Returns the EQNGenericValue for the given value, or the default one
|
|
/// - Parameter value: Magnitudo value to search
|
|
/// - Returns: Found value or default
|
|
class func filterMagnitude(for value: String?) -> EQNGenericValue {
|
|
if let value = value, let genericValue = filterMagnitude.first(where: { $0.value == value }) {
|
|
return genericValue
|
|
}
|
|
return DefaultFilterMagnitude
|
|
}
|
|
|
|
class func seismicNetworks() -> [EQNSeismicNetwork] {
|
|
[
|
|
EQNSeismicNetwork(acronym: "USGS", country: NSLocalizedString("configuration_countries_united_states", comment: ""), extended: ""),
|
|
EQNSeismicNetwork(acronym: "INGV", country: NSLocalizedString("configuration_countries_italy", comment: ""), extended: ""),
|
|
EQNSeismicNetwork(acronym: "IGN", country: NSLocalizedString("configuration_countries_spain", comment: ""), extended: ""),
|
|
EQNSeismicNetwork(acronym: "UOA", country: NSLocalizedString("configuration_countries_greece", comment: ""), extended: ""),
|
|
EQNSeismicNetwork(acronym: "EMSC", country: NSLocalizedString("configuration_countries_france", comment: ""), extended: ""),
|
|
EQNSeismicNetwork(acronym: "EMSC", country: NSLocalizedString("configuration_countries_croatia", comment: ""), extended: ""),
|
|
EQNSeismicNetwork(acronym: "CSI", country: NSLocalizedString("configuration_countries_china", comment: ""), extended: ""),
|
|
EQNSeismicNetwork(acronym: "JMA", country: NSLocalizedString("configuration_countries_japan", comment: ""), extended: ""),
|
|
EQNSeismicNetwork(acronym: "Ineter", country: NSLocalizedString("configuration_countries_nicaragua", comment: ""), extended: ""),
|
|
EQNSeismicNetwork(acronym: "SSN", country: NSLocalizedString("configuration_countries_mexico", comment: ""), extended: ""),
|
|
EQNSeismicNetwork(acronym: "SGC", country: NSLocalizedString("configuration_countries_colombia", comment: ""), extended: ""),
|
|
EQNSeismicNetwork(acronym: "RSN", country: NSLocalizedString("configuration_countries_costa_rica", comment: ""), extended: ""),
|
|
EQNSeismicNetwork(acronym: "CSN", country: NSLocalizedString("configuration_countries_cila", comment: ""), extended: ""),
|
|
EQNSeismicNetwork(acronym: "FUNVISIS", country: NSLocalizedString("configuration_countries_venezuela", comment: ""), extended: ""),
|
|
EQNSeismicNetwork(acronym: "GeoNet", country: NSLocalizedString("configuration_countries_new_zeland", comment: ""), extended: ""),
|
|
EQNSeismicNetwork(acronym: "INPRES", country: NSLocalizedString("configuration_countries_argentina", comment: ""), extended: ""),
|
|
EQNSeismicNetwork(acronym: "IGEPN", country: NSLocalizedString("configuration_countries_ecuador", comment: ""), extended: ""),
|
|
EQNSeismicNetwork(acronym: "IGP", country: NSLocalizedString("configuration_countries_peru", comment: ""), extended: ""),
|
|
EQNSeismicNetwork(acronym: "UASD", country: NSLocalizedString("configuration_countries_dominican_republic", comment: ""), extended: ""),
|
|
EQNSeismicNetwork(acronym: "NCS", country: NSLocalizedString("configuration_countries_india", comment: ""), extended: ""),
|
|
EQNSeismicNetwork(acronym: "RSPR", country: NSLocalizedString("configuration_countries_puerto_rico", comment: ""), extended: ""),
|
|
EQNSeismicNetwork(acronym: "BDTIM", country: NSLocalizedString("configuration_countries_turkey", comment: ""), extended: ""),
|
|
EQNSeismicNetwork(acronym: "EMSC", country: NSLocalizedString("configuration_countries_other", comment: ""), extended: "")
|
|
]
|
|
}
|
|
|
|
class func seismicNetworkAcronyms() -> [String] {
|
|
Self.seismicNetworks().map { $0.acronym }
|
|
}
|
|
|
|
class func seismicNetworkCountries() -> [String] {
|
|
Self.seismicNetworks().map { $0.country }
|
|
}
|
|
|
|
class func seismic(for acronym: String?) -> EQNSeismicNetwork? {
|
|
guard let acronym = acronym else { return nil }
|
|
return Self.seismicNetworks().first(where: { $0.acronym == acronym })
|
|
}
|
|
}
|