Skip to content

Commit

Permalink
added performance indicators
Browse files Browse the repository at this point in the history
  • Loading branch information
Cufee committed Jan 20, 2025
1 parent 8a62566 commit cd0d694
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 65 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/bwmarrin/discordgo v0.28.1
github.com/cufee/aftermath-assets v0.1.0
github.com/cufee/am-wg-proxy-next/v2 v2.2.6
github.com/cufee/facepaint v0.0.7
github.com/cufee/facepaint v0.0.8
github.com/fogleman/gg v1.3.0
github.com/go-co-op/gocron v1.37.0
github.com/goccy/go-json v0.10.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ github.com/cufee/aftermath-assets v0.1.0 h1:r8p2mUN+h/cw1T6/oEX7bntD+lrL9Nz27GXO
github.com/cufee/aftermath-assets v0.1.0/go.mod h1:6yCITCiz7POJnUMn1oohvadLA4z5YrFNo3p9EKgRdGU=
github.com/cufee/am-wg-proxy-next/v2 v2.2.6 h1:6RAnPuYbPGtaLzOPhTk/N2Hx4KJx14x/c/cIik668xA=
github.com/cufee/am-wg-proxy-next/v2 v2.2.6/go.mod h1:x6fkRfYry3l4Ykxl+v6pJAw5ISw+CuGzJzSkc5y5SYs=
github.com/cufee/facepaint v0.0.7 h1:X8ihx5t8Zmwr9Qhx9AdmhiV+fC2qajf1mWEoMB1oo7w=
github.com/cufee/facepaint v0.0.7/go.mod h1:7zR5lQMN3EO3qNtff0J8nzIhDb258UoYbRzhRToLQdg=
github.com/cufee/facepaint v0.0.8 h1:Kn40xClh1662H4IJMyZxipDnwsaEaGfe9v3TrJOJcGI=
github.com/cufee/facepaint v0.0.8/go.mod h1:7zR5lQMN3EO3qNtff0J8nzIhDb258UoYbRzhRToLQdg=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
36 changes: 18 additions & 18 deletions internal/stats/render/session/v2/cards.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ import (
"github.com/cufee/facepaint"
)

func generateCards(session, career fetch.AccountStatsOverPeriod, cards session.Cards, _ []models.UserSubscription, opts common.Options) (*facepaint.Block, error) {
func generateCards(sessionData, careerData fetch.AccountStatsOverPeriod, cards session.Cards, _ []models.UserSubscription, opts common.Options) (*facepaint.Block, error) {
var (
renderUnratedVehiclesCount = 3 // minimum number of vehicle cards
// primary cards
// when there are some unrated battles or no battles at all
shouldRenderUnratedOverview = session.RegularBattles.Battles > 0 || session.RatingBattles.Battles < 1
shouldRenderUnratedOverview = sessionData.RegularBattles.Battles > 0 || sessionData.RatingBattles.Battles < 1
// when there are 3 vehicle cards and no rating overview cards or there are 6 vehicle cards and some rating battles
shouldRenderUnratedHighlights = (session.RegularBattles.Battles > 0 && session.RatingBattles.Battles < 1 && len(cards.Unrated.Vehicles) > renderUnratedVehiclesCount) ||
(session.RegularBattles.Battles > 0 && len(cards.Unrated.Vehicles) > 3)
shouldRenderRatingOverview = session.RatingBattles.Battles > 0 && opts.VehicleID == ""
shouldRenderUnratedHighlights = (sessionData.RegularBattles.Battles > 0 && sessionData.RatingBattles.Battles < 1 && len(cards.Unrated.Vehicles) > renderUnratedVehiclesCount) ||
(sessionData.RegularBattles.Battles > 0 && len(cards.Unrated.Vehicles) > 3)
shouldRenderRatingOverview = sessionData.RatingBattles.Battles > 0 && opts.VehicleID == ""
// secondary cards
shouldRenderUnratedVehicles = session.RegularBattles.Battles > 0 && len(cards.Unrated.Vehicles) > 0
shouldRenderUnratedVehicles = sessionData.RegularBattles.Battles > 0 && len(cards.Unrated.Vehicles) > 0
)

// try to make the columns height roughly similar to primary column
Expand All @@ -37,27 +37,27 @@ func generateCards(session, career fetch.AccountStatsOverPeriod, cards session.C
}

// calculate max overview block width to make all blocks the same size
var maxWidthOverviewColumn = make(map[string]float64)
var maxWidthOverviewColumn = make(map[bool]float64)
for _, column := range cards.Unrated.Overview.Blocks {
for _, block := range column.Blocks {
switch block.Tag {
case prepare.TagWN8:
block.Label = common.GetWN8TierName(block.Value().Float())
maxWidthOverviewColumn[string(column.Flavor)] = max(maxWidthOverviewColumn[string(column.Flavor)], iconSizeWN8)
maxWidthOverviewColumn[column.Flavor == session.BlockFlavorDefault] = max(maxWidthOverviewColumn[column.Flavor == session.BlockFlavorDefault], iconSizeWN8)
}
maxWidthOverviewColumn[string(column.Flavor)] = max(maxWidthOverviewColumn[string(column.Flavor)], facepaint.MeasureString(block.Label, styledOverviewCard.styleBlock(block).label.Font).TotalWidth)
maxWidthOverviewColumn[string(column.Flavor)] = max(maxWidthOverviewColumn[string(column.Flavor)], facepaint.MeasureString(block.Value().String(), styledOverviewCard.styleBlock(block).value.Font).TotalWidth)
maxWidthOverviewColumn[column.Flavor == session.BlockFlavorDefault] = max(maxWidthOverviewColumn[column.Flavor == session.BlockFlavorDefault], facepaint.MeasureString(block.Label, styledOverviewCard.styleBlock(block).label.Font).TotalWidth)
maxWidthOverviewColumn[column.Flavor == session.BlockFlavorDefault] = max(maxWidthOverviewColumn[column.Flavor == session.BlockFlavorDefault], facepaint.MeasureString(block.Value().String(), styledOverviewCard.styleBlock(block).value.Font).TotalWidth)
}
}
for _, column := range cards.Rating.Overview.Blocks {
for _, block := range column.Blocks {
switch block.Tag {
case prepare.TagRankedRating:
block.Label = common.GetRatingTierName(block.Value().Float())
maxWidthOverviewColumn[string(column.Flavor)] = max(maxWidthOverviewColumn[string(column.Flavor)], iconSizeRating)
maxWidthOverviewColumn[column.Flavor == session.BlockFlavorDefault] = max(maxWidthOverviewColumn[column.Flavor == session.BlockFlavorDefault], iconSizeRating)
}
maxWidthOverviewColumn[string(column.Flavor)] = max(maxWidthOverviewColumn[string(column.Flavor)], facepaint.MeasureString(block.Label, styledOverviewCard.styleBlock(block).label.Font).TotalWidth)
maxWidthOverviewColumn[string(column.Flavor)] = max(maxWidthOverviewColumn[string(column.Flavor)], facepaint.MeasureString(block.Value().String(), styledOverviewCard.styleBlock(block).value.Font).TotalWidth)
maxWidthOverviewColumn[column.Flavor == session.BlockFlavorDefault] = max(maxWidthOverviewColumn[column.Flavor == session.BlockFlavorDefault], facepaint.MeasureString(block.Label, styledOverviewCard.styleBlock(block).label.Font).TotalWidth)
maxWidthOverviewColumn[column.Flavor == session.BlockFlavorDefault] = max(maxWidthOverviewColumn[column.Flavor == session.BlockFlavorDefault], facepaint.MeasureString(block.Value().String(), styledOverviewCard.styleBlock(block).value.Font).TotalWidth)
}
}

Expand All @@ -77,12 +77,12 @@ func generateCards(session, career fetch.AccountStatsOverPeriod, cards session.C
for _, block := range card.Blocks {
labelStyle := styledVehicleLegendPillText()
label := facepaint.MeasureString(block.Label, labelStyle.Font).TotalWidth + labelStyle.PaddingLeft + labelStyle.PaddingRight
value := facepaint.MeasureString(block.Value().String(), styledVehicleCard.value(0).Font).TotalWidth
value := facepaint.MeasureString(block.Value().String(), styledVehicleCard.value().Font).TotalWidth
vehicleBlockWidth[block.Tag] = max(vehicleBlockWidth[block.Tag], label, value)
}
}

var overviewCards = []*facepaint.Block{newPlayerNameCard(career.Account)}
var overviewCards = []*facepaint.Block{newPlayerNameCard(careerData.Account)}
// unrated overview
if shouldRenderUnratedOverview {
if card := newUnratedOverviewCard(cards.Unrated.Overview, maxWidthOverviewColumn); card != nil {
Expand Down Expand Up @@ -128,8 +128,8 @@ func generateCards(session, career fetch.AccountStatsOverPeriod, cards session.C
cardsFrameSize := cardsFrame.Dimensions()
opts.Background = imaging.Fill(opts.Background, cardsFrameSize.Width, cardsFrameSize.Height, imaging.Center, imaging.Lanczos)
if !opts.BackgroundIsCustom {
seed, _ := strconv.Atoi(career.Account.ID)
opts.Background = addBackgroundBranding(opts.Background, session.RegularBattles.Vehicles, seed)
seed, _ := strconv.Atoi(careerData.Account.ID)
opts.Background = addBackgroundBranding(opts.Background, sessionData.RegularBattles.Vehicles, seed)
}
cardsFrame = facepaint.NewBlocksContent(style.NewStyle(),
facepaint.MustNewImageContent(styledCardsBackground, opts.Background), cardsFrame,
Expand All @@ -138,7 +138,7 @@ func generateCards(session, career fetch.AccountStatsOverPeriod, cards session.C

var frameCards []*facepaint.Block
frameCards = append(frameCards, cardsFrame)
frameCards = append(frameCards, newFooterCard(session, cards, opts))
frameCards = append(frameCards, newFooterCard(sessionData, cards, opts))

return facepaint.NewBlocksContent(style.NewStyle(style.Parent(styledFinalFrame)), frameCards...), nil
}
68 changes: 54 additions & 14 deletions internal/stats/render/session/v2/overview-style.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package session

import (
"image/color"

"github.com/cufee/aftermath/internal/render/common"
prepare "github.com/cufee/aftermath/internal/stats/prepare/common/v1"
"github.com/cufee/aftermath/internal/stats/prepare/session/v1"
Expand All @@ -14,16 +16,20 @@ const (
iconSizeRating = 60.0
)

var (
iconBackgroundColorOverview = color.NRGBA{40, 40, 40, 120}
)

type blockStyle struct {
wrapper style.Style
iconWrapper style.Style
valueContainer style.Style
value style.Style
label style.Style
}

type overviewCardStyle struct {
card style.Style
column style.Style
styleBlock func(block prepare.StatsBlock[session.BlockData, string]) blockStyle
}

Expand All @@ -46,25 +52,57 @@ var styledOverviewCard = overviewCardStyle{
BorderRadiusBottomLeft: common.BorderRadiusLG,
BorderRadiusBottomRight: common.BorderRadiusLG,

GrowHorizontal: true,
Gap: 15,

PaddingLeft: cardPaddingX,
PaddingRight: cardPaddingX,
PaddingTop: cardPaddingY,
PaddingBottom: cardPaddingY,
},
column: style.Style{
Debug: debugOverviewCards,
PaddingTop: cardPaddingY / 2,
PaddingBottom: cardPaddingY / 2,

Direction: style.DirectionVertical,
AlignItems: style.AlignItemsCenter,
JustifyContent: style.JustifyContentSpaceAround,
GrowVertical: true,
GrowHorizontal: true,
Gap: 10,
},
}

func (overviewCardStyle) column(column session.OverviewColumn) style.Style {
switch column.Flavor {
case session.BlockFlavorRating, session.BlockFlavorWN8:
return style.Style{
Debug: debugOverviewCards,

Direction: style.DirectionVertical,
AlignItems: style.AlignItemsCenter,
JustifyContent: style.JustifyContentCenter,
// GrowVertical: true,
GrowHorizontal: true,

BorderRadiusTopLeft: common.BorderRadiusSM,
BorderRadiusTopRight: common.BorderRadiusSM,
BorderRadiusBottomLeft: common.BorderRadiusSM,
BorderRadiusBottomRight: common.BorderRadiusSM,

BackgroundColor: iconBackgroundColorOverview,

PaddingLeft: 10,
PaddingRight: 10,
PaddingTop: cardPaddingY / 2,
PaddingBottom: cardPaddingY / 2,

Gap: 15,
}
default:
return style.Style{
Debug: debugOverviewCards,

Direction: style.DirectionVertical,
AlignItems: style.AlignItemsCenter,
JustifyContent: style.JustifyContentCenter,
Gap: 15,

PaddingTop: cardPaddingY / 2,
PaddingBottom: cardPaddingY / 2,
}
}
}

func styleOverviewBlock(block prepare.StatsBlock[session.BlockData, string]) blockStyle {
switch block.Tag {
case prepare.TagWN8, prepare.TagRankedRating:
Expand All @@ -75,7 +113,9 @@ func styleOverviewBlock(block prepare.StatsBlock[session.BlockData, string]) blo
Direction: style.DirectionVertical,
AlignItems: style.AlignItemsCenter,
JustifyContent: style.JustifyContentCenter,
Gap: 15,
Gap: 10,

GrowVertical: true,
},
valueContainer: style.Style{
Debug: debugOverviewCards,
Expand Down
26 changes: 14 additions & 12 deletions internal/stats/render/session/v2/overview.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ import (
"github.com/cufee/facepaint/style"
)

func newRatingOverviewCard(data session.RatingCards, columnWidth map[string]float64) *facepaint.Block {
func newRatingOverviewCard(data session.RatingCards, columnWidth map[bool]float64) *facepaint.Block {
if len(data.Overview.Blocks) == 0 {
return nil
}

var columns []*facepaint.Block
for _, column := range data.Overview.Blocks {
columns = append(columns, newOverviewColumn(styledOverviewCard, column, columnWidth[string(column.Flavor)]))
columns = append(columns, newOverviewColumn(styledOverviewCard, column, columnWidth[column.Flavor == session.BlockFlavorDefault]))
}
// card
return facepaint.NewBlocksContent(styledOverviewCard.card.Options(), columns...)
}

func newUnratedOverviewCard(data session.OverviewCard, columnWidth map[string]float64) *facepaint.Block {
func newUnratedOverviewCard(data session.OverviewCard, columnWidth map[bool]float64) *facepaint.Block {
if len(data.Blocks) == 0 {
return nil
}

var columns []*facepaint.Block
for _, column := range data.Blocks {
columns = append(columns, newOverviewColumn(styledOverviewCard, column, columnWidth[string(column.Flavor)]))
columns = append(columns, newOverviewColumn(styledOverviewCard, column, columnWidth[column.Flavor == session.BlockFlavorDefault]))
}
// card
return facepaint.NewBlocksContent(styledOverviewCard.card.Options(), columns...)
Expand All @@ -48,25 +48,27 @@ func newOverviewColumn(stl overviewCardStyle, data session.OverviewColumn, colum
}
// column
return facepaint.NewBlocksContent(style.NewStyle(
style.Parent(stl.column),
style.SetWidth(columnWidth),
style.Parent(stl.column(data)),
style.SetMinWidth(columnWidth),
), columnBlocks...)
}

func newOverviewBlockWithIcon(blockStyle blockStyle, block prepare.StatsBlock[session.BlockData, string], icon *facepaint.Block) *facepaint.Block {
if icon == nil {
// block
return facepaint.NewBlocksContent(blockStyle.valueContainer.Options(),
// value
facepaint.MustNewTextContent(blockStyle.value.Options(), block.V.String()),
// label
facepaint.MustNewTextContent(blockStyle.label.Options(), block.Label),
return facepaint.NewBlocksContent(blockStyle.wrapper.Options(),
facepaint.NewBlocksContent(blockStyle.valueContainer.Options(),
// value
facepaint.MustNewTextContent(blockStyle.value.Options(), block.V.String()),
// label
facepaint.MustNewTextContent(blockStyle.label.Options(), block.Label),
),
)
}
// wrapper
return facepaint.NewBlocksContent(blockStyle.wrapper.Options(),
// icon
icon,
facepaint.NewBlocksContent(blockStyle.iconWrapper.Options(), icon),
// block
facepaint.NewBlocksContent(blockStyle.valueContainer.Options(),
// value
Expand Down
52 changes: 39 additions & 13 deletions internal/stats/render/session/v2/vehicle-style.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
package session

import (
"image/color"

"github.com/cufee/aftermath/internal/render/common"
"github.com/cufee/facepaint/style"
)

const (
debugVehicleCards = false

vehicleIconSizeWN8 = 20.0
vehicleIconSizeWN8 = 14.0
)

type vehicleCardStyle struct {
card style.StyleOptions
titleWrapper style.StyleOptions
titleText func() style.StyleOptions
var (
iconBackgroundColorVehicle = color.NRGBA{40, 40, 40, 100}
)

stats style.StyleOptions
value func(float64) *style.Style
type vehicleCardStyle struct {
card style.StyleOptions
titleIconWrapper style.StyleOptions
titleWrapper style.StyleOptions
titleText func() style.StyleOptions

stats style.StyleOptions
value func() *style.Style
valueWrapper func(float64) *style.Style
}

var styledVehicleLegendPillWrapper = style.NewStyle(style.Parent(style.Style{
Expand Down Expand Up @@ -77,17 +85,30 @@ var styledVehicleCard = vehicleCardStyle{
PaddingBottom: cardPaddingY / 2,
})),

titleIconWrapper: style.NewStyle(style.Parent(style.Style{
BorderRadiusTopLeft: common.BorderRadiusXS,
BorderRadiusTopRight: common.BorderRadiusXS,
BorderRadiusBottomLeft: common.BorderRadiusXS,
BorderRadiusBottomRight: common.BorderRadiusXS,

BackgroundColor: iconBackgroundColorVehicle,

PaddingLeft: 7,
PaddingRight: 7,
PaddingTop: 7,
PaddingBottom: 7,
})),
titleWrapper: style.NewStyle(style.Parent(style.Style{
Debug: debugVehicleCards,

GrowHorizontal: true,
Gap: 10,
JustifyContent: style.JustifyContentSpaceBetween,
})),
titleText: func() style.StyleOptions {
return style.NewStyle(style.Parent(style.Style{
Color: common.TextSecondary,
Font: common.FontMedium(),
Color: common.TextSecondary,
Font: common.FontMedium(),
GrowHorizontal: true,
}))
},

Expand All @@ -99,13 +120,18 @@ var styledVehicleCard = vehicleCardStyle{
GrowHorizontal: true,
Gap: 10,
})),
value: func(width float64) *style.Style {
value: func() *style.Style {
return &style.Style{
Width: width,
Color: common.TextPrimary,
Font: common.FontLarge(),
GrowHorizontal: true,
JustifyContent: style.JustifyContentCenter,
}
},
valueWrapper: func(width float64) *style.Style {
return &style.Style{
Width: width,
JustifyContent: style.JustifyContentCenter,
AlignItems: style.AlignItemsCenter,
}
},
}
Loading

0 comments on commit cd0d694

Please sign in to comment.