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": {
"data": "con"
},
"interpolate": "linear",
"encode": {
"update": {
"x": {
@ -51,7 +52,7 @@
"value": "#4C78A8"
},
"interpolate": {
"value": "monotone"
"value": "linear"
},
"fillOpacity": {
"value": 1

View File

@ -64,6 +64,22 @@ module Prepare = {
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 = {

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 = [
Function.make(
~name="toContinuousPointSet",
@ -37,26 +56,17 @@ let registry = [
FnDefinition.make(
~name="toContinuousPointSet",
~inputs=[FRTypeArray(FRTypeRecord([("x", FRTypeNumeric), ("y", FRTypeNumeric)]))],
~run=(inputs, _) => {
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(Continuous(Continuous.make(r))),
))
expressionValue
},
~run=(inputs, _) => inputsTodist(inputs, r => Continuous(Continuous.make(r))),
),
],
),
Function.make(
~name="toDiscretePointSet",
~definitions=[
FnDefinition.make(
~name="toDiscretePointSet",
~inputs=[FRTypeArray(FRTypeRecord([("x", FRTypeNumeric), ("y", FRTypeNumeric)]))],
~run=(inputs, _) => inputsTodist(inputs, r => Discrete(Discrete.make(r))),
),
],
),