#!/usr/bin/env ruby
require File.expand_path('../../../config/environment', __FILE__)

Swars::Battle.destroy_all
Swars::Importer::FullHistoryImporter.new(user_key: "itoshinTV", verbose: false).call
tp Swars::MembershipExtra
tp Swars.info

# # remakeで回復する
# Swars::MembershipExtra.first.update!(used_piece_counts: {})
# Swars::Battle.all.each(&:rebuild)
# tp Swars::MembershipExtra
#
# # MembershipExtra が欠けてる場合に修復
# Swars::MembershipExtra.delete_all
# Swars::Battle.find_each(&:membership_extra_create_if_nothing)
# tp Swars::MembershipExtra

# production 更新
# r = t.advance(days: 0)...t.advance(days: 1)
Swars::MembershipExtra.delete_all
Swars::MembershipExtra.create_if_nothing
# # ActiveRecord::Base.logger = ActiveSupport::Logger.new(STDOUT)
# t = Time.current.beginning_of_day
# r = "2000-11-01".to_time..."2021-12-01".to_time
# m = Swars::Membership.membership_extra_missing
# b = Swars::Battle.where(battled_at: r).where(memberships: m)
# b.count # => 3
# b.find_each(&:membership_extra_create_if_nothing)
tp Swars::MembershipExtra

# >> |-----+---------------+-------------------------------------------------------------------------------------+---------------------------+---------------------------|
# >> | id  | membership_id | used_piece_counts                                                                   | created_at                | updated_at                |
# >> |-----+---------------+-------------------------------------------------------------------------------------+---------------------------+---------------------------|
# >> | 313 |           193 | {"B0"=>5, "G0"=>4, "K0"=>4, "L0"=>7, "N0"=>1, "P0"=>17, "P1"=>2, "R0"=>4, "S0"=>11} | 2021-11-08 10:51:27 +0900 | 2021-11-08 10:51:27 +0900 |
# >> | 314 |           194 | {"B0"=>7, "G0"=>4, "K0"=>6, "L0"=>6, "N0"=>1, "P0"=>18, "P1"=>1, "R0"=>2, "S0"=>9}  | 2021-11-08 10:51:27 +0900 | 2021-11-08 10:51:27 +0900 |
# >> | 315 |           195 | {"B0"=>5, "G0"=>4, "K0"=>4, "L0"=>7, "N0"=>1, "P0"=>17, "P1"=>2, "R0"=>4, "S0"=>11} | 2021-11-08 10:51:27 +0900 | 2021-11-08 10:51:27 +0900 |
# >> | 316 |           196 | {"B0"=>7, "G0"=>4, "K0"=>6, "L0"=>6, "N0"=>1, "P0"=>18, "P1"=>1, "R0"=>2, "S0"=>9}  | 2021-11-08 10:51:27 +0900 | 2021-11-08 10:51:27 +0900 |
# >> | 317 |           197 | {"B0"=>5, "G0"=>4, "K0"=>4, "L0"=>7, "N0"=>1, "P0"=>17, "P1"=>2, "R0"=>4, "S0"=>11} | 2021-11-08 10:51:28 +0900 | 2021-11-08 10:51:28 +0900 |
# >> | 318 |           198 | {"B0"=>7, "G0"=>4, "K0"=>6, "L0"=>6, "N0"=>1, "P0"=>18, "P1"=>1, "R0"=>2, "S0"=>9}  | 2021-11-08 10:51:28 +0900 | 2021-11-08 10:51:28 +0900 |
# >> |-----+---------------+-------------------------------------------------------------------------------------+---------------------------+---------------------------|
# >> |------------------------+-------+--------|
# >> | model                  | count | 最終ID |
# >> |------------------------+-------+--------|
# >> | Swars::Battle          |     3 |     99 |
# >> | Swars::Membership      |     6 |    198 |
# >> | Swars::MembershipExtra |     6 |    318 |
# >> | Swars::Grade           |    40 |     40 |
# >> | Swars::User            |    28 |     28 |
# >> |------------------------+-------+--------|
# >> |-----+---------------+-------------------------------------------------------------------------------------+---------------------------+---------------------------|
# >> | id  | membership_id | used_piece_counts                                                                   | created_at                | updated_at                |
# >> |-----+---------------+-------------------------------------------------------------------------------------+---------------------------+---------------------------|
# >> | 319 |           193 | {"B0"=>5, "G0"=>4, "K0"=>4, "L0"=>7, "N0"=>1, "P0"=>17, "P1"=>2, "R0"=>4, "S0"=>11} | 2021-11-08 10:51:28 +0900 | 2021-11-08 10:51:28 +0900 |
# >> | 320 |           194 | {"B0"=>7, "G0"=>4, "K0"=>6, "L0"=>6, "N0"=>1, "P0"=>18, "P1"=>1, "R0"=>2, "S0"=>9}  | 2021-11-08 10:51:28 +0900 | 2021-11-08 10:51:28 +0900 |
# >> | 321 |           195 | {"B0"=>5, "G0"=>4, "K0"=>4, "L0"=>7, "N0"=>1, "P0"=>17, "P1"=>2, "R0"=>4, "S0"=>11} | 2021-11-08 10:51:28 +0900 | 2021-11-08 10:51:28 +0900 |
# >> | 322 |           196 | {"B0"=>7, "G0"=>4, "K0"=>6, "L0"=>6, "N0"=>1, "P0"=>18, "P1"=>1, "R0"=>2, "S0"=>9}  | 2021-11-08 10:51:28 +0900 | 2021-11-08 10:51:28 +0900 |
# >> | 323 |           197 | {"B0"=>5, "G0"=>4, "K0"=>4, "L0"=>7, "N0"=>1, "P0"=>17, "P1"=>2, "R0"=>4, "S0"=>11} | 2021-11-08 10:51:28 +0900 | 2021-11-08 10:51:28 +0900 |
# >> | 324 |           198 | {"B0"=>7, "G0"=>4, "K0"=>6, "L0"=>6, "N0"=>1, "P0"=>18, "P1"=>1, "R0"=>2, "S0"=>9}  | 2021-11-08 10:51:28 +0900 | 2021-11-08 10:51:28 +0900 |
# >> |-----+---------------+-------------------------------------------------------------------------------------+---------------------------+---------------------------|
