Skip to content

Commit e1b6b93

Browse files
committed
feat: add Blueprinter serializers for all API resources
- Add PlayerSerializer with computed fields (age, win_rate, etc) - Add MatchSerializer with game statistics - Add PlayerMatchStatSerializer with KDA calculations - Add ScoutingTargetSerializer with interest level - Add ScheduleSerializer with duration calculations - Add VodReviewSerializer and VodTimestampSerializer - Add TeamGoalSerializer with progress tracking - Add ChampionPoolSerializer with win rate
1 parent e4b5800 commit e1b6b93

9 files changed

+247
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class ChampionPoolSerializer < Blueprinter::Base
2+
identifier :id
3+
4+
fields :champion, :games_played, :wins, :losses,
5+
:average_kda, :average_cs, :mastery_level, :mastery_points,
6+
:last_played_at, :created_at, :updated_at
7+
8+
field :win_rate do |pool|
9+
return 0 if pool.games_played.to_i.zero?
10+
((pool.wins.to_f / pool.games_played) * 100).round(1)
11+
end
12+
13+
association :player, blueprint: PlayerSerializer
14+
end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
class MatchSerializer < Blueprinter::Base
2+
identifier :id
3+
4+
fields :match_type, :game_start, :game_end, :game_duration,
5+
:riot_match_id, :patch_version, :tournament_name, :stage,
6+
:opponent_name, :opponent_tag, :victory,
7+
:our_side, :our_score, :opponent_score,
8+
:first_blood, :first_tower, :first_baron, :first_dragon,
9+
:total_kills, :total_deaths, :total_assists, :total_gold,
10+
:vod_url, :replay_file_url, :notes,
11+
:created_at, :updated_at
12+
13+
field :result do |match|
14+
match.result_text
15+
end
16+
17+
field :duration_formatted do |match|
18+
match.duration_formatted
19+
end
20+
21+
field :score_display do |match|
22+
match.score_display
23+
end
24+
25+
field :kda_summary do |match|
26+
match.kda_summary
27+
end
28+
29+
field :has_replay do |match|
30+
match.has_replay?
31+
end
32+
33+
field :has_vod do |match|
34+
match.has_vod?
35+
end
36+
37+
association :organization, blueprint: OrganizationSerializer
38+
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class PlayerMatchStatSerializer < Blueprinter::Base
2+
identifier :id
3+
4+
fields :role, :champion, :kills, :deaths, :assists,
5+
:gold_earned, :total_damage_dealt, :total_damage_taken,
6+
:minions_killed, :jungle_minions_killed,
7+
:vision_score, :wards_placed, :wards_killed,
8+
:champion_level, :first_blood_kill, :double_kills,
9+
:triple_kills, :quadra_kills, :penta_kills,
10+
:performance_score, :created_at, :updated_at
11+
12+
field :kda do |stat|
13+
deaths = stat.deaths.zero? ? 1 : stat.deaths
14+
((stat.kills + stat.assists).to_f / deaths).round(2)
15+
end
16+
17+
field :cs_total do |stat|
18+
(stat.minions_killed || 0) + (stat.jungle_minions_killed || 0)
19+
end
20+
21+
association :player, blueprint: PlayerSerializer
22+
association :match, blueprint: MatchSerializer
23+
end
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
class PlayerSerializer < Blueprinter::Base
2+
identifier :id
3+
4+
fields :summoner_name, :real_name, :role, :status,
5+
:jersey_number, :birth_date, :country, :nationality,
6+
:contract_start_date, :contract_end_date,
7+
:solo_queue_tier, :solo_queue_rank, :solo_queue_lp,
8+
:solo_queue_wins, :solo_queue_losses,
9+
:flex_queue_tier, :flex_queue_rank, :flex_queue_lp,
10+
:peak_tier, :peak_rank, :peak_season,
11+
:riot_puuid, :riot_summoner_id,
12+
:twitter_handle, :twitch_channel, :instagram_handle,
13+
:notes, :last_sync_at, :created_at, :updated_at
14+
15+
field :age do |player|
16+
player.age
17+
end
18+
19+
field :win_rate do |player|
20+
player.win_rate
21+
end
22+
23+
field :current_rank do |player|
24+
player.current_rank_display
25+
end
26+
27+
field :peak_rank do |player|
28+
player.peak_rank_display
29+
end
30+
31+
field :contract_status do |player|
32+
player.contract_status
33+
end
34+
35+
field :main_champions do |player|
36+
player.main_champions
37+
end
38+
39+
field :social_links do |player|
40+
player.social_links
41+
end
42+
43+
field :needs_sync do |player|
44+
player.needs_sync?
45+
end
46+
47+
association :organization, blueprint: OrganizationSerializer
48+
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class ScheduleSerializer < Blueprinter::Base
2+
identifier :id
3+
4+
fields :event_type, :title, :description, :start_time, :end_time,
5+
:location, :is_online, :opponent_name,
6+
:tournament_name, :stage, :status,
7+
:notes, :created_at, :updated_at
8+
9+
field :duration_hours do |schedule|
10+
return nil unless schedule.start_time && schedule.end_time
11+
((schedule.end_time - schedule.start_time) / 3600).round(1)
12+
end
13+
14+
association :organization, blueprint: OrganizationSerializer
15+
association :match, blueprint: MatchSerializer
16+
end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class ScoutingTargetSerializer < Blueprinter::Base
2+
identifier :id
3+
4+
fields :summoner_name, :real_name, :role, :current_team,
5+
:region, :nationality, :age, :status,
6+
:solo_queue_tier, :solo_queue_rank, :solo_queue_lp,
7+
:peak_tier, :peak_rank,
8+
:riot_puuid, :riot_summoner_id,
9+
:scouting_notes, :interest_level, :contacted,
10+
:contact_notes, :availability, :salary_expectations,
11+
:twitter_handle, :twitch_channel,
12+
:last_sync_at, :created_at, :updated_at
13+
14+
field :interest_level_text do |target|
15+
case target.interest_level
16+
when 1 then 'Low'
17+
when 2 then 'Medium'
18+
when 3 then 'High'
19+
when 4 then 'Very High'
20+
when 5 then 'Priority'
21+
else 'Not Rated'
22+
end
23+
end
24+
25+
association :organization, blueprint: OrganizationSerializer
26+
association :added_by, blueprint: UserSerializer
27+
end
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
class TeamGoalSerializer < Blueprinter::Base
2+
identifier :id
3+
4+
fields :title, :description, :category, :metric_type,
5+
:target_value, :current_value, :start_date, :end_date,
6+
:status, :progress, :notes, :created_at, :updated_at
7+
8+
field :is_team_goal do |goal|
9+
goal.is_team_goal?
10+
end
11+
12+
field :days_remaining do |goal|
13+
goal.days_remaining
14+
end
15+
16+
field :days_total do |goal|
17+
goal.days_total
18+
end
19+
20+
field :time_progress_percentage do |goal|
21+
goal.time_progress_percentage
22+
end
23+
24+
field :is_overdue do |goal|
25+
goal.is_overdue?
26+
end
27+
28+
field :target_display do |goal|
29+
goal.target_display
30+
end
31+
32+
field :current_display do |goal|
33+
goal.current_display
34+
end
35+
36+
field :completion_percentage do |goal|
37+
goal.completion_percentage
38+
end
39+
40+
association :organization, blueprint: OrganizationSerializer
41+
association :player, blueprint: PlayerSerializer
42+
association :assigned_to, blueprint: UserSerializer
43+
association :created_by, blueprint: UserSerializer
44+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class VodReviewSerializer < Blueprinter::Base
2+
identifier :id
3+
4+
fields :title, :vod_url, :vod_platform, :game_start_timestamp,
5+
:status, :notes, :created_at, :updated_at
6+
7+
field :timestamps_count do |vod_review, options|
8+
options[:include_timestamps_count] ? vod_review.vod_timestamps.count : nil
9+
end
10+
11+
association :organization, blueprint: OrganizationSerializer
12+
association :match, blueprint: MatchSerializer
13+
association :reviewed_by, blueprint: UserSerializer
14+
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class VodTimestampSerializer < Blueprinter::Base
2+
identifier :id
3+
4+
fields :timestamp_seconds, :category, :importance, :title,
5+
:description, :created_at, :updated_at
6+
7+
field :formatted_timestamp do |timestamp|
8+
seconds = timestamp.timestamp_seconds
9+
hours = seconds / 3600
10+
minutes = (seconds % 3600) / 60
11+
secs = seconds % 60
12+
13+
if hours > 0
14+
format('%02d:%02d:%02d', hours, minutes, secs)
15+
else
16+
format('%02d:%02d', minutes, secs)
17+
end
18+
end
19+
20+
association :vod_review, blueprint: VodReviewSerializer
21+
association :target_player, blueprint: PlayerSerializer
22+
association :created_by, blueprint: UserSerializer
23+
end

0 commit comments

Comments
 (0)