Added sparkline and toString to ReducerInterface
This commit is contained in:
		
							parent
							
								
									837088a9c6
								
							
						
					
					
						commit
						937a8482fd
					
				| 
						 | 
				
			
			@ -59,7 +59,7 @@ describe("sparkline", () => {
 | 
			
		|||
    expected: DistributionOperation.outputType,
 | 
			
		||||
  ) => {
 | 
			
		||||
    test(name, () => {
 | 
			
		||||
      let result = DistributionOperation.run(~env, FromDist(ToSparkline(20), dist))
 | 
			
		||||
      let result = DistributionOperation.run(~env, FromDist(ToString(ToSparkline(20)), dist))
 | 
			
		||||
      expect(result)->toEqual(expected)
 | 
			
		||||
    })
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -30,6 +30,9 @@ describe("eval on distribution functions", () => {
 | 
			
		|||
    testEval("mean(normal(5,2))", "Ok(5)")
 | 
			
		||||
    testEval("mean(lognormal(1,2))", "Ok(20.085536923187668)")
 | 
			
		||||
  })
 | 
			
		||||
  describe("toString", () => {
 | 
			
		||||
    testEval("toString(normal(5,2))", "Ok('Normal(5,2)')")
 | 
			
		||||
  })
 | 
			
		||||
  describe("normalize", () => {
 | 
			
		||||
    testEval("normalize(normal(5,2))", "Ok(Normal(5,2))")
 | 
			
		||||
  })
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -113,8 +113,8 @@ let rec run = (~env, functionCallInfo: functionCallInfo): outputType => {
 | 
			
		|||
      GenericDist.toFloatOperation(dist, ~toPointSetFn, ~distToFloatOperation)
 | 
			
		||||
      ->E.R2.fmap(r => Float(r))
 | 
			
		||||
      ->OutputLocal.fromResult
 | 
			
		||||
    | ToString => dist->GenericDist.toString->String
 | 
			
		||||
    | ToSparkline(buckets) =>
 | 
			
		||||
    | ToString(ToString) => dist->GenericDist.toString->String
 | 
			
		||||
    | ToString(ToSparkline(buckets)) =>
 | 
			
		||||
      GenericDist.toSparkline(dist, ~sampleCount, ~buckets, ())
 | 
			
		||||
      ->E.R2.fmap(r => String(r))
 | 
			
		||||
      ->OutputLocal.fromResult
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -52,12 +52,15 @@ module Operation = {
 | 
			
		|||
 | 
			
		||||
  type toFloatArray = Sample(int)
 | 
			
		||||
 | 
			
		||||
  type toString = 
 | 
			
		||||
  | ToString
 | 
			
		||||
  | ToSparkline(int)
 | 
			
		||||
 | 
			
		||||
  type fromDist =
 | 
			
		||||
    | ToFloat(toFloat)
 | 
			
		||||
    | ToDist(toDist)
 | 
			
		||||
    | ToDistCombination(direction, arithmeticOperation, [#Dist(genericDist) | #Float(float)])
 | 
			
		||||
    | ToString
 | 
			
		||||
    | ToSparkline(int)
 | 
			
		||||
    | ToString(toString)
 | 
			
		||||
 | 
			
		||||
  type singleParamaterFunction =
 | 
			
		||||
    | FromDist(fromDist)
 | 
			
		||||
| 
						 | 
				
			
			@ -80,8 +83,8 @@ module Operation = {
 | 
			
		|||
    | ToDist(ToSampleSet(r)) => `toSampleSet(${E.I.toString(r)})`
 | 
			
		||||
    | ToDist(Truncate(_, _)) => `truncate`
 | 
			
		||||
    | ToDist(Inspect) => `inspect`
 | 
			
		||||
    | ToString => `toString`
 | 
			
		||||
    | ToSparkline(n) => `toSparkline(${E.I.toString(n)})`
 | 
			
		||||
    | ToString(ToString) => `toString`
 | 
			
		||||
    | ToString(ToSparkline(n)) => `toSparkline(${E.I.toString(n)})`
 | 
			
		||||
    | ToDistCombination(Algebraic, _, _) => `algebraic`
 | 
			
		||||
    | ToDistCombination(Pointwise, _, _) => `pointwise`
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -45,6 +45,13 @@ module Helpers = {
 | 
			
		|||
    FromDist(GenericDist_Types.Operation.ToFloat(fnCall), dist)->runGenericOperation->Some
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  let toStringFn = (
 | 
			
		||||
    fnCall: GenericDist_Types.Operation.toString,
 | 
			
		||||
    dist: GenericDist_Types.genericDist,
 | 
			
		||||
  ) => {
 | 
			
		||||
    FromDist(GenericDist_Types.Operation.ToString(fnCall), dist)->runGenericOperation->Some
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  let toDistFn = (fnCall: GenericDist_Types.Operation.toDist, dist) => {
 | 
			
		||||
    FromDist(GenericDist_Types.Operation.ToDist(fnCall), dist)->runGenericOperation->Some
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -119,6 +126,9 @@ let dispatchToGenericOutput = (call: ExpressionValue.functionCall): option<
 | 
			
		|||
    ->SymbolicConstructors.symbolicResultToOutput
 | 
			
		||||
  | ("sample", [EvDistribution(dist)]) => Helpers.toFloatFn(#Sample, dist)
 | 
			
		||||
  | ("mean", [EvDistribution(dist)]) => Helpers.toFloatFn(#Mean, dist)
 | 
			
		||||
  | ("toString", [EvDistribution(dist)]) => Helpers.toStringFn(ToString, dist)
 | 
			
		||||
  | ("toSparkline", [EvDistribution(dist)]) => Helpers.toStringFn(ToSparkline(20), dist)
 | 
			
		||||
  | ("toSparkline", [EvDistribution(dist), EvNumber(n)]) => Helpers.toStringFn(ToSparkline(Belt.Float.toInt(n)), dist)
 | 
			
		||||
  | ("exp", [EvDistribution(a)]) =>
 | 
			
		||||
    // https://mathjs.org/docs/reference/functions/exp.html
 | 
			
		||||
    Helpers.twoDiststoDistFn(Algebraic, "pow", GenericDist.fromFloat(Math.e), a)->Some
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user