Commit 1e515576 authored by Valentin Reis's avatar Valentin Reis
Browse files

[fix] Fixing sensor area computation, pretty printing of CPD, MeasurementState instance.

parent fb994e16
Pipeline #11406 passed with stages
in 3 minutes and 1 second
......@@ -239,10 +239,14 @@ showExpr = prettyExpr . simplify
prettyCPD :: Problem -> Text
prettyCPD p =
[text| Actuators: $a
Sensors: $s
Objectives: $objs
Constraints: $csts |]
[text| Actuators:
$a
Sensors:
$s
Objectives:
$objs
Constraints:
$csts |]
where
s = mcUnlines $ p ^@.. #sensors . itraversed <&> ((sensorID *** show) >>> desc)
a = mcUnlines $ p ^@.. #actuators . itraversed <&> ((actuatorID *** show) >>> desc)
......
......@@ -14,6 +14,7 @@ module CPD.Integrated
M (..),
trapezoidArea,
initIntegrator,
throughTuple,
measureValue,
squeeze,
averageArea,
......@@ -50,7 +51,7 @@ data MeasurementState a
instance Applicative MeasurementState where
pure = Running
pure = Done
Never <*> _ = Never
Discarded <*> _ = Discarded
......@@ -108,7 +109,10 @@ measureM newTime newValue M {firstTime, lastTime, lastValue, area} =
}
averageArea :: M -> Double
averageArea M {firstTime, lastTime, area} = area / fromuS (lastTime - firstTime)
averageArea M {firstTime, lastTime, lastValue, area} =
if deltaT <= 0 then lastValue else area / deltaT
where
deltaT = fromuS (lastTime - firstTime)
squeeze ::
Time ->
......@@ -116,20 +120,11 @@ squeeze ::
Maybe (Map SensorID Double, Map SensorID (MeasurementState M))
squeeze _t mstM =
case traverse throughTuple (M.toList mstM) of
Done (M.fromList -> m) -> Just (m <&> averageArea, m <&> newround)
Done (M.fromList -> m) -> Just (m <&> averageArea, m <&> const Never)
_ -> Nothing
where
throughTuple :: Functor f => (a, f b) -> f (a, b)
throughTuple (id, m) = (id,) <$> m
newround :: M -> MeasurementState M
newround M {lastTime, lastValue} =
Running $
M
{ firstTime = lastTime,
lastTime = lastTime,
lastValue = lastValue,
area = lastValue
}
throughTuple :: Functor f => (a, f b) -> f (a, b)
throughTuple (id, m) = (id,) <$> m
initIntegrator ::
Time ->
......
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