All Projects → shikimori → neko-achievements

shikimori / neko-achievements

Licence: MIT License
No description or website provided.

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to neko-achievements

rodeo
Test your API consuming Elixir app against a real (one-off) webserver
Stars: ✭ 15 (-6.25%)
Mutual labels:  cowboy
erws
Erlang Websockets example using Cowboy
Stars: ✭ 43 (+168.75%)
Mutual labels:  cowboy
kastle
Kafka REST proxy
Stars: ✭ 27 (+68.75%)
Mutual labels:  cowboy
prometheus-cowboy
Expose Prometheus metrics using cowboy/cowboy2
Stars: ✭ 19 (+18.75%)
Mutual labels:  cowboy
swagger routerl
Routing library that generate the routing table from swagger.yaml.
Stars: ✭ 14 (-12.5%)
Mutual labels:  cowboy
lasse
SSE handler for Cowboy
Stars: ✭ 44 (+175%)
Mutual labels:  cowboy
Cowboy
Small, fast, modern HTTP server for Erlang/OTP.
Stars: ✭ 6,533 (+40731.25%)
Mutual labels:  cowboy
sgi
Socket Gateway Interface
Stars: ✭ 16 (+0%)
Mutual labels:  cowboy

neko

CircleCI

installation

Install asfg in your system.

Install dependencies.

asdf install elixir
asdf install erlang

local run

# with REPL
$ iex -S mix
# without REPL
$ mix run -—no-halt

deploy

$ mix deploy

elixir samples

# get neko_id rules
Neko.Rule.CountRule.Store.all |> Enum.filter(&(&1.neko_id == "longshounen"))

# get animes
Neko.Anime.all()
Neko.Anime.all_by_id()


# get animes matched by rule
user_id = 1
Neko.UserRate.load(user_id)

rule = Neko.Rule.CountRule.Store.all |> Enum.filter(&(&1.neko_id == "longshounen" && &1.level == 1)) |> Enum.at(0)
rule = Neko.Rule.DurationRule.Store.all |> Enum.filter(&(&1.neko_id == "darker_than_black" && &1.level == 1)) |> Enum.at(0)

user_anime_ids = user_id |> Neko.UserRate.all() |> Map.values() |> Enum.map(& &1.target_id) |> MapSet.new()
user_animes_by_id = Neko.Anime.all_by_id() |> Map.take(user_anime_ids)
user_anime_ids |> MapSet.intersection(rule.anime_ids)

elixir logging

  require IEx; IEx.pry

  # /lib/neko/rule/rule.ex
  defp rule_applies?({rule, value}) do
    if rule.neko_id == "teekyuu" && rule.level == 0 do
      IO.puts("Neko.Rule: applies?: #{value >= rule.threshold} value: #{value} rule.threshold: #{rule.threshold}")
    end
    value >= rule.threshold
  end

  # /lib/neko/rule/duration_rule/duration_rule.ex
  def value(rule, _user_anime_ids, by_anime_id) do
    if rule.neko_id == "sword_art_online" && rule.level == 1 do
      value = by_anime_id
        |> Map.take(rule.anime_ids)
        |> Enum.map(fn {_, %{user_rate: user_rate, anime: anime}} ->
          if user_rate.status == "watching" || user_rate.status == "on_hold" do
            anime.duration * user_rate.episodes
          else
            anime.total_duration
          end
        end)
        |> Enum.sum()

      IO.inspect rule
      IO.puts("Neko.Rule.DurationRule: value: #{value} rule.threshold: #{rule.threshold}")
    end

    by_anime_id
    |> Map.take(rule.anime_ids)
    |> Enum.map(fn {_, %{user_rate: user_rate, anime: anime}} ->
      if user_rate.status == "watching" || user_rate.status == "on_hold" do
        anime.duration * user_rate.episodes
      else
        anime.total_duration
      end
    end)
    |> Enum.sum()
  end

parse achievements extracted from google docs

File.open('/tmp/achievements.yml', 'w') { |f| f.write SmarterCSV.process(open('/tmp/achievements.csv')).to_yaml }
anime_id_regexp = %r{/animes/[A-z]*(?<id>\d+)}
data = YAML.load_file('/tmp/achievements.yml').
  map do |entry|
    franchise = Anime.find(entry[:url].match(anime_id_regexp)[:id]).franchise

    if entry[:except_titles].present?
      not_anime_ids = {
        'not_anime_ids' => [
          entry[:except_titles]
        ] + entry[:except_titles].scan(anime_id_regexp).map(&:first).map(&:to_i)
      }
    end

    {
      'neko_id' => franchise,
      'level' => 1,
      'algo' => 'count',
      'filters' => {
        'franchise' => franchise,
      }.merge(not_anime_ids || {}),
      'threshold' => entry[:threshold],
      'metadata' => {
        'image' => [entry[:image_url], entry[:image_2_url], entry[:image_3_url], entry[:image_4_url]].compact
      }
    }
  end.
  sort_by { |v| Anime.where(franchise: v['filters']['franchise'], status: 'released').where.not(ranked: 0).map(&:ranked).min }

File.open("#{ENV['HOME']}/develop/neko-achievements/priv/rules/_franchises.yml", 'w') { |f| f.write data.to_yaml }

puts data.map { |v| v['filters']['franchise'] }.join(' ')
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].