Commit d6d237c1 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[ngrams docs] score improvements

parent 0e9526b1
...@@ -14,6 +14,7 @@ import Gargantext.Prelude ...@@ -14,6 +14,7 @@ import Gargantext.Prelude
import Gargantext.Routes (SessionRoute(NodeAPI)) import Gargantext.Routes (SessionRoute(NodeAPI))
import Gargantext.Sessions (Session, sessionId, get, delete, put) import Gargantext.Sessions (Session, sessionId, get, delete, put)
import Gargantext.Types as GT import Gargantext.Types as GT
import Gargantext.Utils.Array as GUA
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Reload as GUR import Gargantext.Utils.Reload as GUR
...@@ -56,10 +57,7 @@ scoreElCpt = R.hooksComponentWithModule thisModule "scoreEl" cpt ...@@ -56,10 +57,7 @@ scoreElCpt = R.hooksComponentWithModule thisModule "scoreEl" cpt
option :: Choice -> R.Element option :: Choice -> R.Element
option c = H.option { value: showChoice c } [ H.text $ showChoice c ] option c = H.option { value: showChoice c } [ H.text $ showChoice c ]
choices = [ Nothing choices = [ Nothing ] <> (Just <$> GUA.range 5 100 5)
, Just 5
, Just 10
, Just 15 ]
showChoice :: Choice -> String showChoice :: Choice -> String
showChoice Nothing = "-" 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.Array as A
import Data.Foldable (foldr) import Data.Foldable (foldr)
import Data.Int as DI
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Ord as Ord import Data.Ord as Ord
import Effect (Effect) import Effect (Effect)
import Effect.Uncurried (EffectFn2, runEffectFn2) import Effect.Uncurried (EffectFn2, runEffectFn2)
import Math as Math
import Gargantext.Prelude import Gargantext.Prelude
...@@ -26,3 +32,9 @@ min xs = foldr reducer (A.head xs) xs ...@@ -26,3 +32,9 @@ min xs = foldr reducer (A.head xs) xs
where where
reducer _ Nothing = Nothing reducer _ Nothing = Nothing
reducer v (Just acc) = Just $ Ord.min acc v 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) ...@@ -9,6 +9,7 @@ import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow) import Data.Generic.Rep.Show (genericShow)
import Gargantext.Utils as GU import Gargantext.Utils as GU
import Gargantext.Utils.Argonaut (genericEnumDecodeJson, genericEnumEncodeJson, genericSumDecodeJson, genericSumEncodeJson) import Gargantext.Utils.Argonaut (genericEnumDecodeJson, genericEnumEncodeJson, genericSumDecodeJson, genericSumEncodeJson)
import Gargantext.Utils.Array as GUA
import Gargantext.Utils.Crypto as Crypto import Gargantext.Utils.Crypto as Crypto
import Gargantext.Utils.Math as GUM import Gargantext.Utils.Math as GUM
import Test.Spec (Spec, describe, it) import Test.Spec (Spec, describe, it)
...@@ -132,6 +133,11 @@ spec = ...@@ -132,6 +133,11 @@ spec =
let hash2 = Crypto.hash ["b","a"] let hash2 = Crypto.hash ["b","a"]
hash1 `shouldEqual` hash2 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