@@ -37,31 +37,31 @@ import Data.Maybe ( isNothing )
37
37
import Data.Ord ( comparing )
38
38
import qualified Data.TarIndex as T
39
39
import qualified Data.Time.Clock as CL
40
- import GHC.Float ( int2Double )
40
+ import GHC.Float ( int2Float )
41
41
import System.FilePath ( isExtensionOf )
42
42
import qualified System.IO as SIO
43
43
44
44
data Scorer = Scorer
45
- { maximum :: Double
46
- , score :: Double
45
+ { maximum :: Float
46
+ , score :: Float
47
47
}
48
48
deriving Show
49
49
50
50
instance Semigroup Scorer where
51
51
(Scorer a b) <> (Scorer c d) = Scorer (a + b) (c + d)
52
52
53
- scorer :: Double -> Double -> Scorer
53
+ scorer :: Float -> Float -> Scorer
54
54
scorer maxim scr =
55
55
if maxim >= scr then Scorer maxim scr else Scorer maxim maxim
56
56
57
- fracScor :: Double -> Double -> Scorer
57
+ fracScor :: Float -> Float -> Scorer
58
58
fracScor maxim frac = scorer maxim (maxim * frac)
59
59
60
- boolScor :: Double -> Bool -> Scorer
60
+ boolScor :: Float -> Bool -> Scorer
61
61
boolScor k True = Scorer k k
62
62
boolScor k False = Scorer k 0
63
63
64
- total :: Scorer -> Double
64
+ total :: Scorer -> Float
65
65
total (Scorer a b) = a / b
66
66
67
67
major :: Num a => [a ] -> a
@@ -74,13 +74,13 @@ patches :: Num a => [a] -> a
74
74
patches (_ : _ : xs) = sum xs
75
75
patches _ = 0
76
76
77
- numDays :: Maybe CL. UTCTime -> Maybe CL. UTCTime -> Double
77
+ numDays :: Maybe CL. UTCTime -> Maybe CL. UTCTime -> Float
78
78
numDays (Just first) (Just end) =
79
79
fromRational $ toRational $ CL. diffUTCTime first end / fromRational
80
80
(toRational CL. nominalDay)
81
81
numDays _ _ = 0
82
82
83
- freshness :: [Version ] -> CL. UTCTime -> Bool -> IO Double
83
+ freshness :: [Version ] -> CL. UTCTime -> Bool -> IO Float
84
84
freshness [] _ _ = return 0
85
85
freshness (x : xs) lastUpd app =
86
86
daysPastExpiration
@@ -89,7 +89,7 @@ freshness (x : xs) lastUpd app =
89
89
versionLatest = versionNumbers x
90
90
daysPastExpiration =
91
91
age >>= (\ a -> return $ max 0 a - expectedUpdateInterval)
92
- expectedUpdateInterval = int2Double
92
+ expectedUpdateInterval = int2Float
93
93
(min (versionStabilityInterval versionLatest) $ length (x : xs))
94
94
versionStabilityInterval v | patches v > 3 && major v > 0 = 700
95
95
| patches v > 3 = 450
@@ -145,13 +145,13 @@ rankIO vers recentDownloads maintainers docs env tarCache pkgs = do
145
145
index <- documentIndex
146
146
path <- documentPath
147
147
return $ liftM2 (,) path (join $ liftM2 T. lookup index path)
148
- documentLines :: IO Double
148
+ documentLines :: IO Float
149
149
documentLines = documentationEntr >>= filterLinesTar (const True )
150
- srcLines :: IO Double
150
+ srcLines :: IO Float
151
151
srcLines = packageEntr >>= filterLinesTar (isExtensionOf " .hs" )
152
152
153
153
filterLinesTar
154
- :: (FilePath -> Bool ) -> Maybe (FilePath , T. TarIndexEntry ) -> IO Double
154
+ :: (FilePath -> Bool ) -> Maybe (FilePath , T. TarIndexEntry ) -> IO Float
155
155
filterLinesTar f (Just (path, T. TarFileEntry offset)) =
156
156
if f path then getLines path offset else return 0
157
157
filterLinesTar f (Just (_, T. TarDir dir)) =
@@ -166,7 +166,7 @@ rankIO vers recentDownloads maintainers docs env tarCache pkgs = do
166
166
case Tar. read header of
167
167
(Tar. Next Tar. Entry { Tar. entryContent = Tar. NormalFile _ siz } _) -> do
168
168
body <- BSL. hGet handle (fromIntegral siz)
169
- return $ int2Double . length . BSL. split 10 $ body
169
+ return $ int2Float . length . BSL. split 10 $ body
170
170
_ -> return 0
171
171
172
172
documentPath = do
@@ -178,9 +178,9 @@ authorScore maintainers desc =
178
178
boolScor 1 (not $ S. null $ author desc) <> maintScore
179
179
where
180
180
maintScore =
181
- boolScor 3 (maintainers > 1 ) <> scorer 5 (int2Double maintainers)
181
+ boolScor 3 (maintainers > 1 ) <> scorer 5 (int2Float maintainers)
182
182
183
- codeScore :: IO Double -> IO Double -> IO Scorer
183
+ codeScore :: IO Float -> IO Float -> IO Scorer
184
184
codeScore documentL haskellL = do
185
185
docum <- documentL
186
186
haskell <- haskellL
@@ -217,15 +217,15 @@ versionScore versionList versions lastUploads desc = do
217
217
<> scorer 40 (numDays (safeHead lUps) (safeLast lUps))
218
218
<> scorer
219
219
15
220
- (int2Double $ length $ filter (\ x -> major x > 0 || minor x > 0 )
220
+ (int2Float $ length $ filter (\ x -> major x > 0 || minor x > 0 )
221
221
intUse
222
222
)
223
223
<> scorer
224
224
20
225
- (int2Double $ 4 * length
225
+ (int2Float $ 4 * length
226
226
(filter (\ x -> major x > 0 && patches x > 0 ) intUse)
227
227
)
228
- <> scorer 10 (int2Double $ patches $ maximumBy (comparing patches) intUse)
228
+ <> scorer 10 (int2Float $ patches $ maximumBy (comparing patches) intUse)
229
229
<> boolScor 8 (any (\ x -> major x == 0 && patches x > 0 ) intUse)
230
230
<> boolScor 10 (any (\ x -> major x > 0 && major x < 20 ) intUse)
231
231
<> boolScor 5 (not $ null depre)
@@ -240,7 +240,7 @@ temporalScore p lastUploads versionList recentDownloads = do
240
240
isApp = (isNothing . library) p && (not . null . executables) p
241
241
downloadScore = calcDownScore recentDownloads
242
242
calcDownScore i = Scorer 5 $ min
243
- ( (logBase 2 (int2Double $ max 0 (i - 100 ) + 100 ) - 6.6 )
243
+ ( (logBase 2 (int2Float $ max 0 (i - 100 ) + 100 ) - 6.6 )
244
244
/ (if isApp then 5 else 6 )
245
245
)
246
246
5
@@ -251,14 +251,14 @@ temporalScore p lastUploads versionList recentDownloads = do
251
251
-- Missing dependencyFreshnessScore for reasonable effectivity needs caching
252
252
tractionScore = do
253
253
fresh <- packageFreshness
254
- return $ boolScor 1 (fresh * int2Double recentDownloads > 1000 )
254
+ return $ boolScor 1 (fresh * int2Float recentDownloads > 1000 )
255
255
256
256
rankPackagePage :: PackageDescription -> Scorer
257
257
rankPackagePage p = tests <> benchs <> desc <> homeP <> sourceRp <> cats
258
258
where
259
259
tests = boolScor 50 (hasTests p)
260
260
benchs = boolScor 10 (hasBenchmarks p)
261
- desc = Scorer 30 (min 1 (int2Double (S. length $ description p) / 300 ))
261
+ desc = Scorer 30 (min 1 (int2Float (S. length $ description p) / 300 ))
262
262
-- documentation = boolScor 30 ()
263
263
homeP = boolScor 30 (not $ S. null $ homepage p)
264
264
sourceRp = boolScor 8 (not $ null $ sourceRepos p)
@@ -274,7 +274,7 @@ rankPackage
274
274
-> TarIndexCacheFeature
275
275
-> ServerEnv
276
276
-> [PkgInfo ]
277
- -> IO Double
277
+ -> IO Float
278
278
rankPackage versions recentDownloads maintainers docs tarCache env pkgs =
279
279
total
280
280
. (<>) (rankPackagePage pkgD)
0 commit comments