Commit 1bc2d523 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[docsTable] implement score from API

parent 266175af
...@@ -7,7 +7,7 @@ import Data.Lens ((^.)) ...@@ -7,7 +7,7 @@ import Data.Lens ((^.))
import Data.Lens.At (at) import Data.Lens.At (at)
import Data.Lens.Record (prop) import Data.Lens.Record (prop)
import Data.Map (Map) import Data.Map (Map)
import Data.Maybe (Maybe(..), fromMaybe, isJust) import Data.Maybe (Maybe(..), fromMaybe, isJust, maybe)
import Data.Ord.Down (Down(..)) import Data.Ord.Down (Down(..))
import Data.Set (Set) import Data.Set (Set)
import Data.Set as Set import Data.Set as Set
...@@ -216,12 +216,13 @@ convOrderBy _ = Nothing ...@@ -216,12 +216,13 @@ convOrderBy _ = Nothing
res2corpus :: Response -> DocumentsView res2corpus :: Response -> DocumentsView
res2corpus (Response r) = res2corpus (Response r) =
DocumentsView { _id : r.cid DocumentsView { _id : r.cid
, url : "" , category : r.category
, date : (\(Hyperdata hr) -> hr.pub_year) r.hyperdata , date : (\(Hyperdata hr) -> hr.pub_year) r.hyperdata
, title : (\(Hyperdata hr) -> hr.title) r.hyperdata
, source : (\(Hyperdata hr) -> hr.source) r.hyperdata
, category : r.category
, ngramCount : r.ngramCount , ngramCount : r.ngramCount
, score : r.score
, source : (\(Hyperdata hr) -> hr.source) r.hyperdata
, title : (\(Hyperdata hr) -> hr.title) r.hyperdata
, url : ""
} }
filterDocs :: Query -> Array Response -> Array Response filterDocs :: Query -> Array Response -> Array Response
...@@ -396,7 +397,7 @@ pagePaintRawCpt = R.hooksComponentWithModule thisModule "pagePaintRawCpt" cpt wh ...@@ -396,7 +397,7 @@ pagePaintRawCpt = R.hooksComponentWithModule thisModule "pagePaintRawCpt" cpt wh
H.a { href: url frontends $ corpusDocument r._id, target: "_blank"} [ H.text r.title ] H.a { href: url frontends $ corpusDocument r._id, target: "_blank"} [ H.text r.title ]
] ]
, H.div { className: tClassName } [ H.text $ if r.source == "" then "Source" else r.source ] , H.div { className: tClassName } [ H.text $ if r.source == "" then "Source" else r.source ]
, H.div {} [ H.text $ show r.ngramCount ] , H.div {} [ H.text $ maybe "-" show r.ngramCount ]
] ]
, delete: true } , delete: true }
where where
......
...@@ -3,6 +3,7 @@ module Gargantext.Components.DocsTable.Types where ...@@ -3,6 +3,7 @@ module Gargantext.Components.DocsTable.Types where
import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, jsonEmptyObject, (.:), (:=), (~>)) import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, jsonEmptyObject, (.:), (:=), (~>))
import Data.Map (Map) import Data.Map (Map)
import Data.Map as Map import Data.Map as Map
import Data.Maybe (Maybe(..))
import Data.Tuple (Tuple(..)) import Data.Tuple (Tuple(..))
import Gargantext.Prelude import Gargantext.Prelude
...@@ -14,13 +15,14 @@ data Action ...@@ -14,13 +15,14 @@ data Action
newtype DocumentsView newtype DocumentsView
= DocumentsView = DocumentsView
{ _id :: Int { _id :: Int
, category :: Category , category :: Category
, date :: Int , date :: Int
, ngramCount :: Int , ngramCount :: Maybe Int
, source :: String , score :: Maybe Int
, title :: String , source :: String
, url :: String , title :: String
, url :: String
} }
{- {-
...@@ -36,23 +38,25 @@ instance encodeJsonSearchType :: Argonaut.EncodeJson SearchType where ...@@ -36,23 +38,25 @@ instance encodeJsonSearchType :: Argonaut.EncodeJson SearchType where
instance decodeDocumentsView :: DecodeJson DocumentsView where instance decodeDocumentsView :: DecodeJson DocumentsView where
decodeJson json = do decodeJson json = do
obj <- decodeJson json obj <- decodeJson json
_id <- obj .: "id" _id <- obj .: "id"
category <- obj .: "category" category <- obj .: "category"
date <- obj .: "date" date <- obj .: "date"
ngramCount <- obj .: "ngramCount" ngramCount <- obj .: "ngramCount"
source <- obj .: "source" score <- obj .: "score"
title <- obj .: "title" source <- obj .: "source"
url <- obj .: "url" title <- obj .: "title"
pure $ DocumentsView { _id, category, date, ngramCount, source, title, url } url <- obj .: "url"
pure $ DocumentsView { _id, category, date, ngramCount, score, source, title, url }
instance encodeDocumentsView :: EncodeJson DocumentsView where instance encodeDocumentsView :: EncodeJson DocumentsView where
encodeJson (DocumentsView dv) = encodeJson (DocumentsView dv) =
"id" := dv._id "id" := dv._id
~> "category" := dv.category ~> "category" := dv.category
~> "date" := dv.date ~> "date" := dv.date
~> "ngramCount" := dv.ngramCount ~> "ngramCount" := dv.ngramCount
~> "source" := dv.source ~> "score" := dv.score
~> "title" := dv.title ~> "source" := dv.source
~> "url" := dv.url ~> "title" := dv.title
~> "url" := dv.url
~> jsonEmptyObject ~> jsonEmptyObject
...@@ -60,24 +64,25 @@ newtype Response = Response ...@@ -60,24 +64,25 @@ newtype Response = Response
{ cid :: Int { cid :: Int
, hyperdata :: Hyperdata , hyperdata :: Hyperdata
, category :: Category , category :: Category
, ngramCount :: Int , ngramCount :: Maybe Int
, score :: Maybe Int
, title :: String , title :: String
} }
newtype Hyperdata = Hyperdata newtype Hyperdata = Hyperdata
{ title :: String { title :: String
, source :: String , source :: String
, pub_year :: Int , pub_year :: Int
} }
instance decodeHyperdata :: DecodeJson Hyperdata where instance decodeHyperdata :: DecodeJson Hyperdata where
decodeJson json = do decodeJson json = do
obj <- decodeJson json obj <- decodeJson json
title <- obj .: "title"
source <- obj .: "source"
pub_year <- obj .: "publication_year" pub_year <- obj .: "publication_year"
source <- obj .: "source"
title <- obj .: "title"
pure $ Hyperdata { title,source, pub_year} pure $ Hyperdata { title,source, pub_year}
instance decodeResponse :: DecodeJson Response where instance decodeResponse :: DecodeJson Response where
...@@ -86,9 +91,10 @@ instance decodeResponse :: DecodeJson Response where ...@@ -86,9 +91,10 @@ instance decodeResponse :: DecodeJson Response where
category <- obj .: "category" category <- obj .: "category"
cid <- obj .: "id" cid <- obj .: "id"
hyperdata <- obj .: "hyperdata" hyperdata <- obj .: "hyperdata"
ngramCount <- obj .: "id" ngramCount <- obj .: "ngramCount"
score <- obj .: "score"
title <- obj .: "title" title <- obj .: "title"
pure $ Response { cid, title, category: decodeCategory category, ngramCount, hyperdata } pure $ Response { category: decodeCategory category, cid, hyperdata, ngramCount, score, title }
type LocalCategories = Map Int Category type LocalCategories = Map Int Category
...@@ -102,7 +108,8 @@ sampleData' = DocumentsView { _id : 1 ...@@ -102,7 +108,8 @@ sampleData' = DocumentsView { _id : 1
, title : "title" , title : "title"
, source : "source" , source : "source"
, category : UnRead , category : UnRead
, ngramCount : 1} , ngramCount : Just 1
, score: Just 1 }
sampleData :: Array DocumentsView sampleData :: Array DocumentsView
--sampleData = replicate 10 sampleData' --sampleData = replicate 10 sampleData'
...@@ -112,7 +119,8 @@ sampleData = map (\(Tuple t s) -> DocumentsView { _id : 1 ...@@ -112,7 +119,8 @@ sampleData = map (\(Tuple t s) -> DocumentsView { _id : 1
, title: t , title: t
, source: s , source: s
, category : UnRead , category : UnRead
, ngramCount : 10}) sampleDocuments , ngramCount : Just 10
, score: Just 1 }) sampleDocuments
sampleDocuments :: Array (Tuple String String) sampleDocuments :: Array (Tuple String String)
sampleDocuments = [Tuple "Macroscopic dynamics of the fusion process" "Journal de Physique Lettres",Tuple "Effects of static and cyclic fatigue at high temperature upon reaction bonded silicon nitride" "Journal de Physique Colloques",Tuple "Reliability of metal/glass-ceramic junctions made by solid state bonding" "Journal de Physique Colloques",Tuple "High temperature mechanical properties and intergranular structure of sialons" "Journal de Physique Colloques",Tuple "SOLUTIONS OF THE LANDAU-VLASOV EQUATION IN NUCLEAR PHYSICS" "Journal de Physique Colloques",Tuple "A STUDY ON THE FUSION REACTION 139La + 12C AT 50 MeV/u WITH THE VUU EQUATION" "Journal de Physique Colloques",Tuple "Atomic structure of \"vitreous\" interfacial films in sialon" "Journal de Physique Colloques",Tuple "MICROSTRUCTURAL AND ANALYTICAL CHARACTERIZATION OF Al2O3/Al-Mg COMPOSITE INTERFACES" "Journal de Physique Colloques",Tuple "Development of oxidation resistant high temperature NbTiAl alloys and intermetallics" "Journal de Physique IV Colloque",Tuple "Determination of brazed joint constitutive law by inverse method" "Journal de Physique IV Colloque",Tuple "Two dimensional estimates from ocean SAR images" "Nonlinear Processes in Geophysics",Tuple "Comparison Between New Carbon Nanostructures Produced by Plasma with Industrial Carbon Black Grades" "Journal de Physique III",Tuple "<i>Letter to the Editor:</i> SCIPION, a new flexible ionospheric sounder in Senegal" "Annales Geophysicae",Tuple "Is reducibility in nuclear multifragmentation related to thermal scaling?" "Physics Letters B",Tuple "Independence of fragment charge distributions of the size of heavy multifragmenting sources" "Physics Letters B",Tuple "Hard photons and neutral pions as probes of hot and dense nuclear matter" "Nuclear Physics A",Tuple "Surveying the nuclear caloric curve" "Physics Letters B",Tuple "A hot expanding source in 50 A MeV Xe+Sn central reactions" "Physics Letters B"] sampleDocuments = [Tuple "Macroscopic dynamics of the fusion process" "Journal de Physique Lettres",Tuple "Effects of static and cyclic fatigue at high temperature upon reaction bonded silicon nitride" "Journal de Physique Colloques",Tuple "Reliability of metal/glass-ceramic junctions made by solid state bonding" "Journal de Physique Colloques",Tuple "High temperature mechanical properties and intergranular structure of sialons" "Journal de Physique Colloques",Tuple "SOLUTIONS OF THE LANDAU-VLASOV EQUATION IN NUCLEAR PHYSICS" "Journal de Physique Colloques",Tuple "A STUDY ON THE FUSION REACTION 139La + 12C AT 50 MeV/u WITH THE VUU EQUATION" "Journal de Physique Colloques",Tuple "Atomic structure of \"vitreous\" interfacial films in sialon" "Journal de Physique Colloques",Tuple "MICROSTRUCTURAL AND ANALYTICAL CHARACTERIZATION OF Al2O3/Al-Mg COMPOSITE INTERFACES" "Journal de Physique Colloques",Tuple "Development of oxidation resistant high temperature NbTiAl alloys and intermetallics" "Journal de Physique IV Colloque",Tuple "Determination of brazed joint constitutive law by inverse method" "Journal de Physique IV Colloque",Tuple "Two dimensional estimates from ocean SAR images" "Nonlinear Processes in Geophysics",Tuple "Comparison Between New Carbon Nanostructures Produced by Plasma with Industrial Carbon Black Grades" "Journal de Physique III",Tuple "<i>Letter to the Editor:</i> SCIPION, a new flexible ionospheric sounder in Senegal" "Annales Geophysicae",Tuple "Is reducibility in nuclear multifragmentation related to thermal scaling?" "Physics Letters B",Tuple "Independence of fragment charge distributions of the size of heavy multifragmenting sources" "Physics Letters B",Tuple "Hard photons and neutral pions as probes of hot and dense nuclear matter" "Nuclear Physics A",Tuple "Surveying the nuclear caloric curve" "Physics Letters B",Tuple "A hot expanding source in 50 A MeV Xe+Sn central reactions" "Physics Letters B"]
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