<commit_before>{-# LANGUAGE OverloadedStrings #-}
module Main where


import Control.Concurrent (forkIO, threadDelay)
import Control.Monad
import Control.Monad.Trans (liftIO)
import Data.IORef
import Data.Time.Clock
import Data.Time.Format
import qualified Data.Text.Lazy as T
import Data.Text.Lazy.Encoding (decodeUtf8)
import Network.HTTP.Conduit (simpleHttp)
import System.Locale
import Web.Scotty
import Text.HTML.TagSoup

data Restaurant = Restaurant
  { name :: T.Text
  , menu :: [Menu]
  } deriving (Eq, Show)

data Menu = Menu
  { lunch :: T.Text
  , spec :: T.Text
  } deriving (Eq, Show)

main = scotty 5007 $ do
  rref <- liftIO refresh
  get "/" $ do
    rs <- liftIO $ readIORef rref
    html $ T.concat
      [ "<pre>"
      , T.intercalate "\n\n" . map ppRestaurant $ rs
      , "</pre>"
      ]

ppRestaurant :: Restaurant -> T.Text
ppRestaurant (Restaurant name menus) = T.concat
  [ T.toUpper name
  , "\n"
  , T.intercalate "\n" $ map ppMenu menus
  ]

ppMenu :: Menu -> T.Text
ppMenu (Menu lunch stuff) = T.concat
  [ lunch
  , ": "
  , stuff
  ]

-- | Refreshes menus hourly.
refresh :: IO (IORef [Restaurant])
refresh = do
  ref <- newIORef []
  update >>= writeIORef ref
  forkIO . forever $ do<commit_msg>Derive Data and Typeable<commit_after>{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveDataTypeable #-}
module Main where

import Control.Concurrent (forkIO, threadDelay)
import Control.Monad
import Control.Monad.Trans (liftIO)
import Data.Data
import Data.Typeable
import Data.IORef
import qualified Data.Text.Lazy as T
import Data.Text.Lazy.Encoding (decodeUtf8)
import Data.Time.Clock
import Data.Time.Format
import Network.HTTP.Conduit (simpleHttp)
import System.Locale
import Text.HTML.TagSoup
import Web.Scotty

data Restaurant = Restaurant
  { name :: T.Text
  , menu :: [Menu]
  } deriving (Eq, Show, Data, Typeable)

data Menu = Menu
  { lunch :: T.Text
  , spec :: T.Text
  } deriving (Eq, Show, Data, Typeable)

main = scotty 5007 $ do
  rref <- liftIO refresh
  get "/" $ do
    rs <- liftIO $ readIORef rref
    html $ T.concat
      [ "<pre>"
      , T.intercalate "\n\n" . map ppRestaurant $ rs
      , "</pre>"
      ]

ppRestaurant :: Restaurant -> T.Text
ppRestaurant (Restaurant name menus) = T.concat
  [ T.toUpper name
  , "\n"
  , T.intercalate "\n" $ map ppMenu menus
  ]

ppMenu :: Menu -> T.Text
ppMenu (Menu lunch stuff) = T.concat
  [ lunch
  , ": "
  , stuff
  ]

-- | Refreshes menus hourly.
refresh :: IO (IORef [Restaurant])
refresh = do
  ref <- newIORef []
  update >>= writeIORef ref
  forkIO . forever $ do
{'fraction_non_alphanumeric': 0.12577639751552794, 'fraction_numerical': 0.0038819875776397515, 'mean_word_length': 3.1364365971107544, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7256659', 'n_tokens_mistral': 946, 'n_tokens_neox': 891, 'n_words': 258}