履歴データ
履歴データの検証
alias Bright.Accounts
alias Bright.Repo
alias Bright.SkillPanels.SkillPanel
defmodule Test do
import Ecto.Query, warn: false
alias Bright.HistoricalSkillPanels.HistoricalSkillClass
alias Bright.Batches.UpdateSkillPanels
alias Bright.HistoricalSkillScores.HistoricalSkillClassScore
alias Bright.HistoricalSkillScores.HistoricalSkillUnitScore
def all do
Repo.all(HistoricalSkillClass)
|> Repo.preload([:skill_panel, :historical_skill_class_scores])
end
def get_historical_skill_class_scores(skill_panel_id, class, user_id, from_date, to_date) do
from(
historical_skill_class in HistoricalSkillClass,
join:
historical_skill_class_scores in assoc(
historical_skill_class,
:historical_skill_class_scores
),
on:
historical_skill_class_scores.user_id == ^user_id and
historical_skill_class_scores.locked_date >= ^from_date and
historical_skill_class_scores.locked_date <= ^to_date,
where:
historical_skill_class.skill_panel_id == ^skill_panel_id and
historical_skill_class.class == ^class,
select: %{
locked_date: historical_skill_class_scores.locked_date,
percentage: historical_skill_class_scores.percentage
}
)
|> Repo.all()
# |> Repo.preload([:skill_panel, :historical_skill_class_scores])
end
def update(year, month) do
locked_date =
{year, month, 1}
|> Date.from_erl!()
UpdateSkillPanels.call(locked_date)
end
def get_historical_skill_gem(user_id, skill_panel_id, class, locked_date) do
from_date = {locked_date.year, locked_date.month, 1} |> Date.from_erl!()
to_date = from_date |> Timex.shift(months: 1) |> Timex.shift(days: -1)
IO.inspect(to_date)
from(historical_skill_unit_score in HistoricalSkillUnitScore,
join: historical_skill_unit in assoc(historical_skill_unit_score, :historical_skill_unit),
join: historical_skill_classes in assoc(historical_skill_unit, :historical_skill_classes),
join:
historical_skill_class_units in assoc(
historical_skill_unit,
:historical_skill_class_units
),
on: historical_skill_classes.class == ^class,
on: historical_skill_classes.skill_panel_id == ^skill_panel_id,
order_by: historical_skill_class_units.position,
where:
historical_skill_unit_score.user_id == ^user_id and
historical_skill_unit_score.locked_date >= ^from_date and
historical_skill_unit_score.locked_date <= ^to_date,
select: %{
name: historical_skill_unit.name,
percentage: historical_skill_unit_score.percentage
}
)
|> Repo.all()
end
end
locked_date = {2022, 10, 1} |> Date.from_erl!()
from_date = {2020, 4, 1} |> Date.from_erl!()
to_date = {2025, 7, 2} |> Date.from_erl!()
# Test.update(locked_date.year, locked_date.month)
# skill_panel = Repo.all(SkillPanel) |> List.first()
user = Accounts.get_user_by_name_or_email("ymn")
Test.get_historical_skill_gem(user.id, "01H7RYBX11WFHVPHQXARFTKRV2", 1, locked_date)
# Test.get_historical_skill_class_scores(
# skill_panel.id,
# 1,
# user.id,
# from_date,
# to_date
# )
# Test.test_get_skillpanels()
# Test.all()