<commit_before>{-# LANGUAGE TupleSections #-}
{-# LANGUAGE ViewPatterns  #-}

module CryptoCoin.CoinMarketCap.Analytics.N00Bs where

{--
A thought:

What are the new cryptocurrencies today?

Does it make sense to invest in these new coins?
--}

import Control.Arrow ((***))
import Control.Monad (liftM, join)

import Data.Maybe (fromMaybe, mapMaybe)
import qualified Data.Map as Map
import Data.Set (Set)
import qualified Data.Set as Set
import Data.Time

import Data.Monetary.Currency
import Data.Monetary.USD
import Data.XHTML (Name)

import Data.CryptoCurrency.Types

import Data.Time.TimeSeries (yesterday, latest)

import CryptoCoin.CoinMarketCap.Types

import CryptoCoin.CoinMarketCap.State.RankMatrix

data N00B = N00B { coin :: ECoin, incept :: Day }
   deriving (Eq, Ord, Show)

noobsFor :: MetaData -> Matrix -> Day -> Set N00B
noobsFor mdata mat day =
   let mbnoobs = liftM (n00bs day mdata) (todayAndYesterday mat day)
   in  fromMaybe Set.empty mbnoobs

todayAndYesterday :: Matrix -> Day -> Maybe (RankVector, RankVector)
todayAndYesterday mat day =
   Map.lookup day mat       >>= \tday ->
   yesterday mat day        >>=
   return . (tday,) . snd

n00bs :: Day -> MetaData -> (RankVector, RankVector) -> Set N00B
n00bs day (MetaData _ coins) (join (***) Map.keysSet -> (tday, yday)) =
   let newsf = map (flip N00B day) . mapMaybe (flip Map.lookup coins)
   in  Set.fromList (newsf $ Set.toList (Set.difference tday yday))

{--
>>> latest rankMatrix 
Just 2021-03-02
>>> let (Just lat) = it
>>> noobsFor rankMatrix lat
{N00B {coin = C (Coin (CoinInfo 7843 "Asia Reserve Currency Coin" 
                                "ARCC" "asia-reserve-currency-coin" True 2864 
                                (Duration {first = 2021-02-28, 
                                           last = 2021-03-02}))), 
       incept = 2021-03-02},
 N00B {coin = C (Coin (CoinInfo 8643 "Shadows" "DOWS" "shadows" True 4219
                                (Duration {first = 2021-03-01, 
                                           last = 2021-03-02}))), 
       incept = 2021-03-02},...}
>>> length it
11
--}<commit_msg>Added TODO of the master-plan to watch new coins.<commit_after>{-# LANGUAGE TupleSections #-}
{-# LANGUAGE ViewPatterns  #-}

module CryptoCoin.CoinMarketCap.Analytics.N00Bs where

{--
A thought:

What are the new cryptocurrencies today?

Does it make sense to invest in these new coins?
--}

import Control.Arrow ((***))
import Control.Monad (liftM, join)

import Data.Maybe (fromMaybe, mapMaybe)
import qualified Data.Map as Map
import Data.Set (Set)
import qualified Data.Set as Set
import Data.Time

import Data.Monetary.Currency
import Data.Monetary.USD
import Data.XHTML (Name)

import Data.CryptoCurrency.Types

import Data.Time.TimeSeries (yesterday, latest)

import CryptoCoin.CoinMarketCap.Types

import CryptoCoin.CoinMarketCap.State.RankMatrix

data N00B = N00B { coin :: ECoin, incept :: Day }
   deriving (Eq, Ord, Show)

noobsFor :: MetaData -> Matrix -> Day -> Set N00B
noobsFor mdata mat day =
   let mbnoobs = liftM (n00bs day mdata) (todayAndYesterday mat day)
   in  fromMaybe Set.empty mbnoobs

todayAndYesterday :: Matrix -> Day -> Maybe (RankVector, RankVector)
todayAndYesterday mat day =
   Map.lookup day mat       >>= \tday ->
   yesterday mat day        >>=
   return . (tday,) . snd

n00bs :: Day -> MetaData -> (RankVector, RankVector) -> Set N00B
n00bs day (MetaData _ coins) (join (***) Map.keysSet -> (tday, yday)) =
   let newsf = map (flip N00B day) . mapMaybe (flip Map.lookup coins)
   in  Set.fromList (newsf $ Set.toList (Set.difference tday yday))

{--
>>> latest rankMatrix 
Just 2021-03-02
>>> let (Just lat) = it
>>> noobsFor rankMatrix lat
{N00B {coin = C (Coin (CoinInfo 7843 "Asia Reserve Currency Coin" 
                                "ARCC" "asia-reserve-currency-coin" True 2864 
                                (Duration {first = 2021-02-28, 
                                           last = 2021-03-02}))), 
       incept = 2021-03-02},
 N00B {coin = C (Coin (CoinInfo 8643 "Shadows" "DOWS" "shadows" True 4219
                                (Duration {first = 2021-03-01, 
                                           last = 2021-03-02}))), 
       incept = 2021-03-02},...}
>>> length it
11

... Okay, we're reporting on these coins. We need to save them with their
incept date and price then check back on them a month (?) later to see how
they've done. TODO.
--}
{'fraction_non_alphanumeric': 0.11647855530474041, 'fraction_numerical': 0.04334085778781038, 'mean_word_length': 2.5762711864406778, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5214261', 'n_tokens_mistral': 1602, 'n_tokens_neox': 1420, 'n_words': 451}