Skip to content

Commit

Permalink
ActionPlan and freebase WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
wildthink-pub committed Sep 15, 2024
1 parent 9259cac commit 606cb87
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 42 deletions.
6 changes: 3 additions & 3 deletions Sources/AnyMeasure/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public extension Unit {

// MARK: - Presentation
public protocol UnitPresentation {
var subject: String { get }
var label: String { get }
var range: ClosedRange<Double> { get }
}

Expand All @@ -74,9 +74,9 @@ public struct UnitPresentationConfig: UnitPresentation {
self.value = value
}

public var subject: String {
public var label: String {
if let p = value.unit as? UnitPresentation {
return p.subject
return p.label
} else {
return String(String(describing: type(of: value.unit)))
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/AnyMeasure/Interval.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import RealModule

public protocol IntervalElement: Real,
public protocol IntervalElement: Real, Codable,
ExpressibleByFloatLiteral, CustomDebugStringConvertible {}

extension Double: IntervalElement {}
Expand All @@ -11,7 +11,7 @@ extension Float: IntervalElement {}
// extension Float80: IntervalElement {}
#endif
/// definition
public struct Interval<F:IntervalElement> : Hashable {
public struct Interval<F:IntervalElement> : Hashable, Codable {
public typealias Element = F
public var (min, max):(F, F)
public init(min:F, max:F) {
Expand Down Expand Up @@ -333,7 +333,7 @@ extension Interval : CustomStringConvertible, CustomDebugStringConvertible {
return "(\(self.min.debugDescription)...\(self.max.debugDescription))"
}
}
extension Interval : Codable where F:Codable {
extension Interval {
public enum CodingKeys : String, CodingKey {
public typealias RawValue = String
case min, max
Expand Down
36 changes: 18 additions & 18 deletions Sources/AnyMeasure/Metric.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@
import Foundation

public class Metric: Unit, UnitPresentation {
public var subject: String { label.name }
public var label: String { subject.name }
public var range: ClosedRange<Double> { _range.range }

public private(set) var label: Subject
public private(set) var subject: Subject
var _range: Interval<Double>
var units: Unit
// cadance, frequeny, recurs
var cycle: TimeFrame
// var cycle: TimeFrame

public init(
_ label: Subject,
_ subject: Subject,
units: Unit,
cycle: TimeFrame = .zero,
// cycle: TimeFrame = .zero,
range: Interval<Double>
) {
self.label = label
self.subject = subject
self._range = range
self.units = units
self.cycle = cycle
// self.cycle = cycle
super.init(symbol: units.symbol)
}

Expand Down Expand Up @@ -54,13 +54,13 @@ public class Metric: Unit, UnitPresentation {
) -> String {
switch style {
case .short:
return "\(label.name)_\(units.symbol)"
return "\(label)_\(units.symbol)"
case .medium:
return "\(label.name) in \(units.symbol)"
return "\(label) in \(units.symbol)"
case .long:
return "\(label.name) in \(units.symbol)"
return "\(label) in \(units.symbol)"
@unknown default:
return "\(label.name)_\(units.symbol)"
return "\(label)_\(units.symbol)"
}
}

Expand All @@ -73,13 +73,13 @@ public class Metric: Unit, UnitPresentation {

switch style {
case .short:
return "\(label.name)(\(ms))"
return "\(label)(\(ms))"
case .medium:
return "\(label.name) in \(ms)"
return "\(label) in \(ms)"
case .long:
return "\(label.name) in \(ms)"
return "\(label) in \(ms)"
@unknown default:
return "\(label.name)_\(units.symbol)"
return "\(label)_\(units.symbol)"
}
}
}
Expand All @@ -92,12 +92,12 @@ extension Metric {

public class
func metric(count: Subject, range: Interval<Double>) -> Metric {
return Metric(count, units: .count(of: count.name), range: range)
return Metric(count, units: .count(), range: range)
}

public class
func metric(count: Subject, range: ClosedRange<Int>) -> Metric {
return Metric(count, units: .count(of: count.name), range: .init(range))
return Metric(count, units: .count(), range: .init(range))
}
}

Expand All @@ -112,7 +112,7 @@ public extension Measurement where UnitType == Metric {
}
}

public struct Subject: ExpressibleByStringLiteral {
public struct Subject: ExpressibleByStringLiteral, Codable, Equatable, Hashable {
public static func named(_ name: String) -> Self {
.init(name)
}
Expand Down
35 changes: 17 additions & 18 deletions Sources/AnyMeasure/UnitCount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ public typealias Count = Measurement<UnitCount>


public final class UnitCount: Unit, UnitPresentation {
public let subject: String
public var label: String { "Count" }
var _range: Interval<Double>

public var range: ClosedRange<Double> {
_range.range
// Range(uncheckedBounds: (lower: min, upper: max)))
}

public init(subject: String, symbol: String = "#", range: ClosedRange<Double>) {
self.subject = subject
public init(symbol: String = "#", range: ClosedRange<Double>) {
self._range = .init(range)
super.init(symbol: symbol)
}
Expand Down Expand Up @@ -49,13 +48,13 @@ public final class UnitCount: Unit, UnitPresentation {
) -> String {
switch style {
case .short:
return "#\(subject)"
return "#\(label)"
case .medium:
return "# of \(subject)"
return "# of \(label)"
case .long:
return "count of \(subject)"
return "count of \(label)"
@unknown default:
return "#\(subject)"
return "#\(label)"
}
}

Expand All @@ -69,34 +68,34 @@ public final class UnitCount: Unit, UnitPresentation {
let vs = fmt.string(for: value.doubleValue) ?? String(value.doubleValue)
switch style {
case .short:
return "\(vs)#\(subject)"
return "\(vs)#\(label)"
case .medium:
return "\(vs)#_\(subject)"
return "\(vs)#_\(label)"
case .long:
return "\(vs) count of \(subject)"
return "\(vs) count of \(label)"
@unknown default:
return "\(vs)#\(subject)"
return "\(vs)#\(label)"
}
}
}

extension Unit {
@objc
public class func count(of subj: String, max: Double = 100) -> UnitCount {
return UnitCount(subject: subj, range: 0...max)
public class func count(max: Double = 100) -> UnitCount {
return UnitCount(range: 0...max)
}
}

extension UnitCount {
@objc
public override class func count(of subj: String, max: Double = 100) -> UnitCount {
return UnitCount(subject: subj, range: 0...max)
public override class func count(max: Double = 100) -> UnitCount {
return UnitCount(range: 0...max)
}
}

public extension NSMeasurement {
static func count(start: Double = 0, of subj: String, max: Double = 100) -> NSMeasurement {
NSMeasurement(doubleValue: start, unit: .count(of: subj, max: max))
static func count(start: Double = 0, max: Double = 100) -> NSMeasurement {
NSMeasurement(doubleValue: start, unit: .count(max: max))
}
}

Expand All @@ -107,7 +106,7 @@ public extension Measurement where UnitType == UnitCount {
}

static var zero: Measurement<UnitType> {
Measurement(value: 0, unit: .count(of: "empty"))
Measurement(value: 0, unit: .count())
}

var description: String {
Expand Down

0 comments on commit 606cb87

Please sign in to comment.