This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chunkChan :: Int -> Int -> TChan a -> IO [a] | |
chunkChan numItems timeoutSeconds chan = do | |
maybeRead <- timeout (timeoutSeconds * 60 * 1000) . atomically $ replicateM numItems (readTChan chan) | |
case maybeRead of | |
Just as -> return as | |
Nothing -> do | |
as <- emptyChannel chan | |
if null as | |
then chunkChan numItems timeoutSeconds chan | |
else return as |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
instance (Ord a) => Ord [a] where | |
compare [] [] = EQ | |
compare [] (_:_) = LT | |
compare (_:_) [] = GT | |
compare (x:xs) (y:ys) = case compare x y of | |
EQ -> compare xs ys | |
other -> other |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- This is part of a pipeline that continously produces `ev`s | |
-- Essentially this is a fold or scan. I call `a` a "projection" of a series of `ev`s | |
projectionConsumer :: IORef a -> (ev -> a -> a) -> Consumer ev IO () | |
projectionConsumer ref f = for cat $ modifyIORef' ref . f | |
-- projectionBConsumer :: IORef b -> (ev -> b -> b) ... | |
-- I now have this issue of composing multiple of these folds | |
-- What I resorted to is something like this | |
someOtherProjection :: IORef a -> IORef x -> IO () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
itemView : Item -> Html Msg | |
itemView item = | |
tr [] | |
[ td [ class "item-id" ] [ text ("#" ++ item.id) ] | |
, td [ class "item-name" ] [ text item.name ] | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module IQR | |
( Sample | |
, mkSample | |
, singletonSample | |
, insertSample | |
, insertSample' | |
, restrictSampleSize | |
, withoutDuplicates | |
, median | |
, lowerQuartile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE ConstraintKinds #-} | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE TypeApplications #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE UndecidableInstances #-} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type family All (c :: Type -> Constraint) | |
(ts :: [Type]) :: Constraint where | |
All c '[] = () | |
All c (x ': xs) = (c x, All c xs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
newtype NT = NT String | |
foo :: Maybe NT | |
foo = Just (NT "test") | |
bar :: Maybe NT -> Maybe String | |
bar = undefined -- ??? how to do this? | |
-- this would work but it verbose for multiple data constructors | |
bar (Just $ NT s) = Just s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
title: Elescore;DB FaSta API;Compensation;Outage | |
author: Philipp Maier | |
summary: " | |
<p>Elescore (elevator + scoring), a platform that tracks elevator disruptions, integrates multiple external data sources. | |
One of these sources is the DB FaSta API: Elevator status for all stations operated by Deutsche Bahn.</p> | |
<p> | |
In the past, this API has had several major outages resulting in corruption of data. | |
Using event sourcing and statistics, I was able to detect outages and compensate them.</p>" | |
tags: Haskell, Statistics, 1.5 x IQR, Event-Sourcing, Stream Processing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Starting Elescore v3 | |
2018-08-05T01:44:39 Residual detected: 351 -> 785.0 | |
2018-08-05T12:48:12 Back to normal: 351 -> 397.0 | |
2018-08-05T13:18:43 Residual detected: 361 -> 435.0 | |
2018-08-05T13:24:29 Back to normal: 361 -> 367.0 | |
2018-09-28T04:51:40 Residual detected: 466 -> 508.0 | |
2018-09-28T08:15:36 Back to normal: 466 -> 439.0 | |
2018-09-28T09:00:06 Residual detected: 458 -> 822.0 | |
2018-09-28T10:51:00 Back to normal: 458 -> 476.0 | |
2018-09-29T12:35:30 Residual detected: 165 -> 66.0 |