Vela β†’ smart cache for time series and not only

In fintech, we often have to process quite massive amounts of currency exchange rate data. We get data from different sources, and each of them has its own idea of ​​how to extrapolate the rates for tomorrow, the day after tomorrow, the next month, and even the next three years. If someone knew how to predict courses correctly, it would be just right to close the business and just stupidly change money back and forth. Some sources are more trustworthy, some supply completely garbage, with rare inclusions of almost correct values, but for exotic couples. Our job is to sift through these tens of thousands of values ​​per second and determine what to show to customers. We need to filter out the only correct value from a ton of dirt and silt, like flamingos do at dinner.



Flamingo



A special distinguishing feature of flamingos is their massive, curved beak, with the help of which they filter food from water or silt.

 -  wiki

Vela, . , N ( , ).



, . Vela - :



defmodule Pairs do
  use Vela,
    eurusd: [sorter: &Kernel.<=/2],
    eurgbp: [limit: 3, errors: 1],
    eurcad: [validator: Pairs]

  @behaviour Vela.Validator

  @impl Vela.Validator
  def valid?(:eurcad, rate), do: rate > 0
end




Vela.put/3 :



  • validator , (. );
  • , , :__errors__ ;
  • sorter , (LIFO, . );
  • :limit ;
  • Vela.


iex|1 > pairs = %Pairs{}
iex|2 > Vela.put(pairs, :eurcad, 1.0)
#β‡’ %Pairs{..., eurcad: [1.0], ...}
iex|3 > Vela.put(pairs, :eurcad, -1.0)
#β‡’ %Pairs{__errors__: [eurcad: -1.0], ...}
iex|4 > pairs |> Vela.put(:eurusd, 2.0) |> Vela.put(:eurusd, 1.0)
#β‡’ %Pairs{... eurusd: [1.0, 2.0]}


Vela Access, Kernel: Kernel.get_in/2, Kernel.put_in/3, Kernel.update_in/3, Kernel.pop_in/2, and Kernel.get_and_update_in/3.





:



  • (&MyMod.my_fun/1), ;
  • , &MyMod.my_fun/2, serie, value ;
  • , Vela.Validator;
  • threshold,  β€”  β€” compare_by, . Comparison .


, , {serie, value} :__errors_.





, , . Vela , compare_by ( Kernel.</2); (Vela.value() -> number()). & &1.



, comparator (min/max); , Date.diff/2 , .



threshold, {min, max} . , comparator, compare_by. , , compare_by: &DateTime.to_unix/1 ( ) threshold: 1, , Β±band .



, Vela.equal?/2 . equal?/2 compare/2, , ==/2.





Vela.purge/1, ( validator timestamps). Vela.slice/1, keyword , .



get_in/2/pop_in/2 .





Vela GenServer/Agent. , , Vela, , .



@impl Vela.Validator
def valid?(_key, %Rate{} = rate),
  do: Rate.age(rate) < @death_age


Vela.purge/1 , . Vela.slice/1, ( ),  β€”  β€” .








!




All Articles