@yarkivaev/scada 2.8.0 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/package.json +4 -2
  2. package/stream-processing/dependencies/timeline-segmentation.jar +0 -0
  3. package/stream-processing/src/main/scala/scada/processing/core/Decision.scala +1 -11
  4. package/stream-processing/src/main/scala/scada/processing/core/MachineConfig.scala +1 -0
  5. package/stream-processing/src/main/scala/scada/processing/core/ReadingWorker.scala +6 -16
  6. package/stream-processing/src/main/scala/scada/processing/core/Segments.scala +1 -0
  7. package/stream-processing/src/main/scala/scada/processing/infra/checkpoint/Checkpoint.scala +1 -0
  8. package/stream-processing/src/main/scala/scada/processing/infra/checkpoint/ClickhouseReadingsCheckpoint.scala +1 -0
  9. package/stream-processing/src/main/scala/scada/processing/infra/checkpoint/SupervisorSinkCheckpoint.scala +1 -0
  10. package/stream-processing/src/main/scala/scada/processing/infra/config/AppConfig.scala +2 -2
  11. package/stream-processing/src/main/scala/scada/processing/infra/config/ConfigLoad.scala +1 -0
  12. package/stream-processing/src/main/scala/scada/processing/infra/config/ConfigProfile.scala +0 -1
  13. package/stream-processing/src/main/scala/scada/processing/infra/mqtt/Mqtt.scala +1 -1
  14. package/stream-processing/src/main/scala/scada/processing/infra/state/CheckpointSegments.scala +1 -0
  15. package/stream-processing/src/main/scala/scada/processing/infra/state/SegmentStatePolicy.scala +1 -2
  16. package/stream-processing/src/main/scala/scada/processing/infra/state/Segments.scala +1 -0
  17. package/stream-processing/src/main/scala/scada/processing/infra/stomp/DecisionMessage.scala +2 -2
  18. package/stream-processing/src/main/scala/scada/processing/infra/stomp/SegmentMessage.scala +2 -2
  19. package/stream-processing/src/main/scala/scada/processing/infra/stomp/SegmentWirePolicy.scala +1 -2
  20. package/stream-processing/src/main/scala/scada/processing/infra/stomp/SplitFamily.scala +2 -2
  21. package/stream-processing/src/main/scala/scada/processing/infra/stomp/StompMachineDecisions.scala +1 -1
  22. package/stream-processing/src/main/scala/scada/processing/infra/stomp/StompReadings.scala +1 -1
  23. package/stream-processing/src/main/scala/scada/processing/infra/stomp/StompSegments.scala +1 -0
  24. package/stream-processing/src/main/scala/scada/processing/runtime/ClassifyHistory.scala +2 -1
  25. package/stream-processing/src/main/scala/scada/processing/runtime/ClassifyStreams.scala +1 -0
  26. package/stream-processing/src/main/scala/scada/processing/runtime/Close.scala +1 -1
  27. package/stream-processing/src/main/scala/scada/processing/runtime/HistoryBus.scala +1 -0
  28. package/stream-processing/src/main/scala/scada/processing/runtime/LocalHistory.scala +13 -61
  29. package/stream-processing/src/main/scala/scada/processing/runtime/PendingIsland.scala +2 -1
  30. package/stream-processing/src/main/scala/scada/processing/runtime/ProcessingApplication.scala +2 -12
  31. package/stream-processing/src/main/scala/scada/processing/runtime/RuntimeProfile.scala +2 -1
  32. package/stream-processing/src/main/scala/scada/processing/runtime/Seeding.scala +2 -1
  33. package/stream-processing/timeline-segmentation.lock +2 -0
  34. package/stream-processing/src/main/scala/scada/processing/core/Condition.scala +0 -33
  35. package/stream-processing/src/main/scala/scada/processing/core/CyclePhases.scala +0 -65
  36. package/stream-processing/src/main/scala/scada/processing/core/Emission.scala +0 -19
  37. package/stream-processing/src/main/scala/scada/processing/core/Params.scala +0 -15
  38. package/stream-processing/src/main/scala/scada/processing/core/Reading.scala +0 -11
  39. package/stream-processing/src/main/scala/scada/processing/core/Segment.scala +0 -28
  40. package/stream-processing/src/main/scala/scada/processing/core/SegmentDef.scala +0 -14
  41. package/stream-processing/src/main/scala/scada/processing/core/Segmentation.scala +0 -47
  42. package/stream-processing/src/main/scala/scada/processing/core/SplitFollow.scala +0 -50
  43. package/stream-processing/src/main/scala/scada/processing/core/SplitPieces.scala +0 -102
  44. package/stream-processing/src/main/scala/scada/processing/core/TagDef.scala +0 -12
  45. package/stream-processing/src/main/scala/scada/processing/core/TaggedSegment.scala +0 -19
  46. package/stream-processing/src/main/scala/scada/processing/core/Tagging.scala +0 -42
  47. package/stream-processing/src/main/scala/scada/processing/core/Timestamp.scala +0 -26
  48. package/stream-processing/src/main/scala/scada/processing/core/segmentation/Timeline.scala +0 -43
  49. package/stream-processing/vendor/gaps-and-islands/LICENSE +0 -21
  50. package/stream-processing/vendor/gaps-and-islands/UPSTREAM +0 -4
  51. package/stream-processing/vendor/gaps-and-islands/src/main/scala/yarkivaev/gapsandislands/api/Island.scala +0 -40
  52. package/stream-processing/vendor/gaps-and-islands/src/main/scala/yarkivaev/gapsandislands/api/IslandEvent.scala +0 -55
  53. package/stream-processing/vendor/gaps-and-islands/src/main/scala/yarkivaev/gapsandislands/api/IslandsFlow.scala +0 -127
  54. package/stream-processing/vendor/gaps-and-islands/src/main/scala/yarkivaev/gapsandislands/api/IslandsPolicy.scala +0 -105
@@ -1,127 +0,0 @@
1
- package yarkivaev.gapsandislands.api
2
-
3
- import fs2.{Chunk, Pipe, Pull, Stream}
4
-
5
- /**
6
- * Pure stream transformation that turns a stream of observations into
7
- * a stream of [[IslandEvent]]s.
8
- *
9
- * The library offers no stateful "flow object". State is threaded
10
- * internally through the pipe's fold over the input; the caller never
11
- * sees the intermediate cursor. Every input observation produces one
12
- * or two events, so the emitted stream is a lossless record of the
13
- * open island over time — any snapshot or derived view is a plain
14
- * stream operation over that output.
15
- *
16
- * The pipe leaves the trailing island open when the input terminates.
17
- * Callers that need a final [[IslandEvent.IslandClosed]] (finite
18
- * batches, explicit end-of-run markers) compose their own terminator;
19
- * doing so is intentionally the caller's concern because the semantics
20
- * of "the input ended" vary by domain.
21
- *
22
- * ==Effect polymorphism==
23
- * The pipe is parametric in the effect `F[_]`. It imposes no typeclass
24
- * constraint: the only effectful step is evaluating the supplied
25
- * [[IslandsPolicy]], which is lifted into the stream via `Pull.eval`.
26
- * `F` is typically `cats.effect.IO`, but anything that the policy
27
- * speaks (`SyncIO`, a custom tagless-final algebra, etc.) works.
28
- *
29
- * ==Usage==
30
- * {{{
31
- * // `F` is inferred from the policy; with an `IslandsPolicy[IO, _, _]`
32
- * // the pipe is `Pipe[IO, A, IslandEvent[A, K]]`.
33
- * val events: Stream[F, IslandEvent[Tick, String]] =
34
- * observations.through(IslandsFlow.pipe(policy, evidence))
35
- *
36
- * // lifecycle-only view
37
- * events.collect {
38
- * case e: IslandEvent.IslandStarted[Tick, String] => e
39
- * case e: IslandEvent.IslandClosed[Tick, String] => e
40
- * }
41
- *
42
- * // open-island checkpoint at each step
43
- * events.map(_.island)
44
- * }}}
45
- */
46
- object IslandsFlow:
47
-
48
- /**
49
- * Build a gaps-and-islands transformation.
50
- *
51
- * The returned pipe consumes observations of type `A`, asks the
52
- * supplied [[IslandsPolicy]] to classify each into a kind of type
53
- * `K`, and emits [[IslandEvent]]s describing how the island
54
- * structure evolves.
55
- *
56
- * ==Recovery==
57
- * Pass `initial = Some(island)` to resume from a previously
58
- * snapshotted open island. No [[IslandEvent.IslandStarted]] is
59
- * emitted for the resumed island; the next observation will either
60
- * extend it (emitting [[IslandEvent.IslandExtended]]) or close it
61
- * (emitting [[IslandEvent.IslandClosed]] followed by
62
- * [[IslandEvent.IslandStarted]]).
63
- *
64
- * ==Snapshot==
65
- * The open island at any point is the `island` of the latest
66
- * non-`IslandClosed` event. Derive it with a plain `scan`:
67
- * {{{
68
- * events.scan(Option.empty[Island[A, K]]) {
69
- * case (_, IslandEvent.IslandClosed(_)) => None
70
- * case (_, other) => Some(other.island)
71
- * }
72
- * }}}
73
- *
74
- * ==Terminal close==
75
- * The pipe emits no event when the input terminates. Callers that
76
- * treat the input as a finite batch and want a final
77
- * [[IslandEvent.IslandClosed]] add one themselves, for example via
78
- * a post-processing pipe that tracks the open island and emits a
79
- * close on end-of-stream.
80
- *
81
- * @tparam F the effect used to evaluate the policy
82
- * @tparam A the observation payload type
83
- * @tparam K the classification kind type
84
- * @tparam E the evidence type consumed by the policy
85
- * @param policy decision rule used to classify each observation
86
- * @param evidence builds the policy's input from the currently open
87
- * island (if any) and the incoming observation
88
- * @param initial optional open island to resume from
89
- */
90
- def pipe[F[_], A, K, E](
91
- policy: IslandsPolicy[F, E, K],
92
- evidence: (Option[Island[A, K]], A) => E,
93
- initial: Option[Island[A, K]] = None
94
- ): Pipe[F, A, IslandEvent[A, K]] =
95
- input => advance(initial, input, policy, evidence).stream
96
-
97
- private def advance[F[_], A, K, E](
98
- state: Option[Island[A, K]],
99
- input: Stream[F, A],
100
- policy: IslandsPolicy[F, E, K],
101
- evidence: (Option[Island[A, K]], A) => E
102
- ): Pull[F, IslandEvent[A, K], Unit] =
103
- input.pull.uncons1.flatMap:
104
- case None => Pull.done
105
- case Some((item, rest)) =>
106
- Pull.eval(policy.decide(evidence(state, item))).flatMap: kind =>
107
- val (next, events) = step(state, item, kind)
108
- Pull.output(Chunk.from(events)) >> advance(next, rest, policy, evidence)
109
-
110
- private def step[A, K](
111
- state: Option[Island[A, K]],
112
- item: A,
113
- kind: K
114
- ): (Option[Island[A, K]], List[IslandEvent[A, K]]) =
115
- state match
116
- case None =>
117
- val fresh = Island(kind, item, item)
118
- (Some(fresh), List(IslandEvent.IslandStarted(fresh)))
119
- case Some(open) if open.kind == kind =>
120
- val extended = Island(kind, open.first, item)
121
- (Some(extended), List(IslandEvent.IslandExtended(extended)))
122
- case Some(open) =>
123
- val fresh = Island(kind, item, item)
124
- (Some(fresh), List(
125
- IslandEvent.IslandClosed(open),
126
- IslandEvent.IslandStarted(fresh)
127
- ))
@@ -1,105 +0,0 @@
1
- package yarkivaev.gapsandislands.api
2
-
3
- import cats.Monad
4
- import cats.data.Kleisli
5
-
6
- /**
7
- * Decision rule that classifies an observation into a kind.
8
- *
9
- * An `IslandsPolicy` is the only place where the caller expresses domain
10
- * meaning. Given whatever evidence it needs — the observation itself, a
11
- * rolling window, a lookup against a database, the previously open
12
- * island — it returns the kind `K` to which the current observation
13
- * belongs. The [[IslandsFlow]] then uses that kind to decide whether to
14
- * extend the current island or close it and open a new one.
15
- *
16
- * There is no privileged "boundary" or "gap" outcome: every observation
17
- * belongs to some island. If the caller wants to distinguish missing
18
- * data, idle periods, or rejected samples from useful runs, they encode
19
- * that distinction as a dedicated value of `K` (for example a
20
- * `"gap"` string or a `Gap` variant of a sealed trait).
21
- *
22
- * ==Composition==
23
- * Policies form a monad over `K` in their shared `F` and `Evidence`.
24
- * `flatMap` runs every stage on every observation, which lets callers
25
- * build refined decisions pipeline-style, for example "first tag as
26
- * live-or-stale, then classify live samples as on-or-off":
27
- *
28
- * {{{
29
- * val tagFreshness: IslandsPolicy[IO, Tick, String] =
30
- * IslandsPolicy(t => IO.pure(if t.ageMs > 30000 then "stale" else "live"))
31
- *
32
- * val refine: String => IslandsPolicy[IO, Tick, String] =
33
- * case "live" => IslandsPolicy(t => IO.pure(if t.power >= 5.0 then "on" else "off"))
34
- * case other => IslandsPolicy(_ => IO.pure(other))
35
- *
36
- * val policy = tagFreshness.flatMap(refine)
37
- * }}}
38
- *
39
- * @tparam F the effect type used to evaluate the decision
40
- * @tparam Evidence the contextual input the policy needs to decide;
41
- * contravariant so narrower evidence types can be
42
- * supplied than declared
43
- * @tparam K the classification kind returned by this policy
44
- */
45
- trait IslandsPolicy[F[_], -Evidence, K]:
46
- /**
47
- * Classify the observation described by `evidence`.
48
- *
49
- * Implementations should be referentially transparent with respect to
50
- * the supplied evidence; any mutable state they need must live inside
51
- * `F`.
52
- *
53
- * @param evidence everything the caller has decided the policy needs
54
- * @return the kind of island the current observation belongs to
55
- */
56
- def decide(evidence: Evidence): F[K]
57
-
58
- object IslandsPolicy:
59
- /**
60
- * Build a policy from a plain decision function.
61
- *
62
- * @param fn function mapping evidence to an effectful kind
63
- */
64
- def apply[F[_], E, K](fn: E => F[K]): IslandsPolicy[F, E, K] =
65
- new IslandsPolicy[F, E, K]:
66
- def decide(evidence: E): F[K] =
67
- fn(evidence)
68
-
69
- /**
70
- * Lift a `cats.data.Kleisli` into an `IslandsPolicy`.
71
- *
72
- * Useful when callers already express their decision logic as a
73
- * `Kleisli[F, E, K]` and want to reuse its combinators before handing
74
- * the rule to a flow.
75
- */
76
- def liftKleisli[F[_], E, K](rule: Kleisli[F, E, K]): IslandsPolicy[F, E, K] =
77
- apply(rule.run)
78
-
79
- extension [F[_], E, K](policy: IslandsPolicy[F, E, K])
80
- /**
81
- * Post-process the kind produced by this policy.
82
- *
83
- * `map` is a pure relabelling: it never changes whether an
84
- * observation is classified, only how the resulting kind is named.
85
- *
86
- * @param fn transformation applied to the classified kind
87
- * @param monad monad instance for the policy's effect
88
- */
89
- def map[L](fn: K => L)(using monad: Monad[F]): IslandsPolicy[F, E, L] =
90
- IslandsPolicy(evidence => monad.map(policy.decide(evidence))(fn))
91
-
92
- /**
93
- * Chain a second decision stage onto this policy.
94
- *
95
- * Both stages are evaluated on every observation; the kind produced
96
- * by the first stage is fed into the function that chooses the next
97
- * policy. This models refinement pipelines where later stages
98
- * specialise the classification of earlier stages.
99
- *
100
- * @param next function producing the next policy from the previous kind
101
- * @param monad monad instance for the policy's effect
102
- */
103
- def flatMap[L](next: K => IslandsPolicy[F, E, L])(using monad: Monad[F]): IslandsPolicy[F, E, L] =
104
- IslandsPolicy: evidence =>
105
- monad.flatMap(policy.decide(evidence))(kind => next(kind).decide(evidence))