From 658b5e01c9f792be73fd984664da923d3e5ce38d Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Tue, 16 Jan 2018 13:49:44 +0100 Subject: Add simple publication year histogram using bokeh --- src/Db.hs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/Db.hs') diff --git a/src/Db.hs b/src/Db.hs index caeaf77..40a05f6 100644 --- a/src/Db.hs +++ b/src/Db.hs @@ -2,7 +2,7 @@ module Db where import System.FilePath ((<.>), splitExtension) -import Data.List (nub, sort, sortBy, isPrefixOf) +import Data.List (nub, sort, sortBy, isPrefixOf, group) import Control.Monad import Data.Maybe (catMaybes) import Data.Yaml @@ -103,9 +103,17 @@ split delim s = let (a, b:bs) = span (/= delim) s in a:split delim bs getFeatureBase :: String -> String getFeatureBase feature = head $ split '.' feature +publicationYears :: Database -> [Int] +publicationYears db = map read $ catMaybes $ map (lookup "year" . E.fields) $ dpublications db + +-- |Get number of publications by year +publicationYearHist :: Database -> [(Int, Int)] +publicationYearHist db = map (\(x:xs) -> (x, length (x:xs))) $ group years + where years = sort $ publicationYears db + minMaxPublicationYears db = (firstyear, lastyear) where - pubyears = catMaybes $ map (lookup "year" . E.fields) $ dpublications db + pubyears = publicationYears db firstyear = foldr min (head pubyears) (tail pubyears) lastyear = foldr max (head pubyears) (tail pubyears) -- cgit v1.2.3