Caps-Train/Sources/ConfigurationFile.swift
2024-10-28 19:06:45 +01:00

40 lines
919 B
Swift

import Foundation
struct ConfigurationFile {
let folder: String?
let iterations: Int?
let server: String?
let authentication: String?
/// The number of images required to include a cap in training
let minimumImagesPerCap: Int?
}
extension ConfigurationFile: Decodable {
}
extension ConfigurationFile {
init(at url: URL) throws {
guard FileManager.default.fileExists(atPath: url.path) else {
throw TrainingError.configurationFileMissing(url)
}
let data: Data
do {
data = try Data(contentsOf: url)
} catch {
throw TrainingError.configurationFileUnreadable(url, error)
}
do {
self = try JSONDecoder().decode(ConfigurationFile.self, from: data)
} catch {
throw TrainingError.configurationFileDecodingFailed(url, error)
}
}
}