ToDiscretePointSet

This commit is contained in:
Ozzie Gooen 2022-05-27 14:03:41 -04:00
parent f49697b64a
commit c2b90b7023
3 changed files with 48 additions and 21 deletions

View File

@ -33,6 +33,7 @@
"from": { "from": {
"data": "con" "data": "con"
}, },
"interpolate": "linear",
"encode": { "encode": {
"update": { "update": {
"x": { "x": {
@ -51,7 +52,7 @@
"value": "#4C78A8" "value": "#4C78A8"
}, },
"interpolate": { "interpolate": {
"value": "monotone" "value": "linear"
}, },
"fillOpacity": { "fillOpacity": {
"value": 1 "value": 1

View File

@ -64,6 +64,22 @@ module Prepare = {
values->ToValueArray.Record.twoArgs->E.R.bind(twoDistOrNumber) values->ToValueArray.Record.twoArgs->E.R.bind(twoDistOrNumber)
} }
} }
module ToArrayRecordPairs = {
let twoArgs = (input: t): result<(array<ts>), err> => {
let array = input->ToValueArray.Array.openA
let pairs =
array->E.R.bind(pairs =>
pairs
->E.A2.fmap(xyCoord =>
[xyCoord]
->ToValueArray.Record.twoArgs
)
->E.A.R.firstErrorOrOpen
)
pairs
}
}
} }
module Process = { module Process = {

View File

@ -30,6 +30,25 @@ module Declaration = {
} }
} }
let inputsTodist = (inputs: array<FunctionRegistry_Core.frValue>, makeDist) => {
let array = inputs->E.A.unsafe_get(0)->Prepare.ToValueArray.Array.openA
let xyCoords =
array->E.R.bind(xyCoords =>
xyCoords
->E.A2.fmap(xyCoord =>
[xyCoord]->Prepare.ToValueArray.Record.twoArgs->E.R.bind(Prepare.ToValueTuple.twoNumbers)
)
->E.A.R.firstErrorOrOpen
)
let expressionValue =
xyCoords
->E.R.bind(r => r->XYShape.T.makeFromZipped->E.R2.errMap(XYShape.Error.toString))
->E.R2.fmap(r => ReducerInterface_ExpressionValue.EvDistribution(
PointSet(makeDist(r)),
))
expressionValue
}
let registry = [ let registry = [
Function.make( Function.make(
~name="toContinuousPointSet", ~name="toContinuousPointSet",
@ -37,26 +56,17 @@ let registry = [
FnDefinition.make( FnDefinition.make(
~name="toContinuousPointSet", ~name="toContinuousPointSet",
~inputs=[FRTypeArray(FRTypeRecord([("x", FRTypeNumeric), ("y", FRTypeNumeric)]))], ~inputs=[FRTypeArray(FRTypeRecord([("x", FRTypeNumeric), ("y", FRTypeNumeric)]))],
~run=(inputs, _) => { ~run=(inputs, _) => inputsTodist(inputs, r => Continuous(Continuous.make(r))),
let array = inputs->E.A.unsafe_get(0)->Prepare.ToValueArray.Array.openA ),
let xyCoords = ],
array->E.R.bind(xyCoords => ),
xyCoords Function.make(
->E.A2.fmap(xyCoord => ~name="toDiscretePointSet",
[xyCoord] ~definitions=[
->Prepare.ToValueArray.Record.twoArgs FnDefinition.make(
->E.R.bind(Prepare.ToValueTuple.twoNumbers) ~name="toDiscretePointSet",
) ~inputs=[FRTypeArray(FRTypeRecord([("x", FRTypeNumeric), ("y", FRTypeNumeric)]))],
->E.A.R.firstErrorOrOpen ~run=(inputs, _) => inputsTodist(inputs, r => Discrete(Discrete.make(r))),
)
let expressionValue =
xyCoords
->E.R.bind(r => r->XYShape.T.makeFromZipped->E.R2.errMap(XYShape.Error.toString))
->E.R2.fmap(r => ReducerInterface_ExpressionValue.EvDistribution(
PointSet(Continuous(Continuous.make(r))),
))
expressionValue
},
), ),
], ],
), ),