Commit d6d237c1 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[ngrams docs] score improvements

parent 0e9526b1
......@@ -14,6 +14,7 @@ import Gargantext.Prelude
import Gargantext.Routes (SessionRoute(NodeAPI))
import Gargantext.Sessions (Session, sessionId, get, delete, put)
import Gargantext.Types as GT
import Gargantext.Utils.Array as GUA
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR
......@@ -56,10 +57,7 @@ scoreElCpt = R.hooksComponentWithModule thisModule "scoreEl" cpt
option :: Choice -> R.Element
option c = H.option { value: showChoice c } [ H.text $ showChoice c ]
choices = [ Nothing
, Just 5
, Just 10
, Just 15 ]
choices = [ Nothing ] <> (Just <$> GUA.range 5 100 5)
showChoice :: Choice -> String
showChoice Nothing = "-"
......
module Gargantext.Utils.Array (max, min, push) where
module Gargantext.Utils.Array (
max
, min
, push
, range) where
import Data.Array as A
import Data.Foldable (foldr)
import Data.Int as DI
import Data.Maybe (Maybe(..))
import Data.Ord as Ord
import Effect (Effect)
import Effect.Uncurried (EffectFn2, runEffectFn2)
import Math as Math
import Gargantext.Prelude
......@@ -26,3 +32,9 @@ min xs = foldr reducer (A.head xs) xs
where
reducer _ Nothing = Nothing
reducer v (Just acc) = Just $ Ord.min acc v
-- | Create an array containing a range of integers, with given step
range :: Int -> Int -> Int -> Array Int
range start end step = map (\i -> start + i*step) $ A.range 0 end'
where
end' = DI.round $ Math.floor $ (DI.toNumber $ end - start) / (DI.toNumber step)
......@@ -9,6 +9,7 @@ import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow)
import Gargantext.Utils as GU
import Gargantext.Utils.Argonaut (genericEnumDecodeJson, genericEnumEncodeJson, genericSumDecodeJson, genericSumEncodeJson)
import Gargantext.Utils.Array as GUA
import Gargantext.Utils.Crypto as Crypto
import Gargantext.Utils.Math as GUM
import Test.Spec (Spec, describe, it)
......@@ -132,6 +133,11 @@ spec =
let hash2 = Crypto.hash ["b","a"]
hash1 `shouldEqual` hash2
------------------------------------------------------------------------
-- | Gargantext.Utils.Array tests
it "G.U.Array.range works correctly (include endpoint)" do
GUA.range 0 10 2 `shouldEqual` [0, 2, 4, 6, 8, 10]
GUA.range 0 10 5 `shouldEqual` [0, 5, 10]
it "G.U.Array.range works correctly (no endpoint)" do
GUA.range 0 11 2 `shouldEqual` [0, 2, 4, 6, 8, 10]
GUA.range 0 11 5 `shouldEqual` [0, 5, 10]
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