Skip to content

Commit

Permalink
Replace "top hosts" category with "most mouths fed"
Browse files Browse the repository at this point in the history
  • Loading branch information
ramikg committed Jun 21, 2024
1 parent ef81b99 commit 6e570d5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ FROM golang:1.22-bookworm as builder
WORKDIR /go/src/bolt
COPY . .

RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o /bolt cmd/main.go && chmod +x /bolt
# The "json1" build tag enables JSON SQL functions in go-sqlite3
RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -tags json1 -o /bolt cmd/main.go && chmod +x /bolt

FROM gcr.io/distroless/base
COPY --from=builder /bolt /bolt
Expand Down
Binary file modified docs/assets/examples/monthly_digest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions order/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ type VenueOrderCount struct {
LastCreatedAt string `db:"last_created_at"` // The driver returns this column as a string
}

type HostOrderCount struct {
HostId string `db:"host_id"`
HostName string `db:"host"`
OrderCount int `db:"order_count"`
LastCreatedAt string `db:"last_created_at"` // The driver returns this column as a string
type MouthsFedCount struct {
HostId string `db:"host_id"`
HostName string `db:"host"`
MouthsFedCount int `db:"mouths_fed_count"`
LastCreatedAt string `db:"last_created_at"` // The driver returns this column as a string
}

type Order struct {
Expand All @@ -53,6 +53,6 @@ type Order struct {
type Store interface {
SaveOrder(ctx context.Context, order *Order) error
GetVenuesWithMostOrders(startTime time.Time, limit uint64, channelId string, filteredVenueIds []string) ([]VenueOrderCount, error)
GetHostsWithMostOrders(startTime time.Time, limit uint64, channelId string, filteredHostIds []string) ([]HostOrderCount, error)
GetHostsWithMostMouthsFed(startTime time.Time, limit uint64, channelId string, filteredHostIds []string) ([]MouthsFedCount, error)
GetActiveChannelIds(lastDateConsideredActive time.Time) ([]string, error)
}
26 changes: 13 additions & 13 deletions service/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,24 @@ func buildTopVenuesMessageBlocks(monthlyTopVenues []order.VenueOrderCount, month
return topVenuesBlocks, nil
}

func buildTopHostsMessageBlocks(monthlyTopHosts []order.HostOrderCount, monthlyTopHostsTotalCounts []order.HostOrderCount) ([]slack.Block, error) {
hostIdToTotalOrderCount := make(map[string]int)
func buildTopHostsMessageBlocks(monthlyTopHosts []order.MouthsFedCount, monthlyTopHostsTotalCounts []order.MouthsFedCount) ([]slack.Block, error) {
hostIdToTotalMouthsFedCount := make(map[string]int)
for _, host := range monthlyTopHostsTotalCounts {
hostIdToTotalOrderCount[host.HostId] = host.OrderCount
hostIdToTotalMouthsFedCount[host.HostId] = host.MouthsFedCount
}

topHostsHeader := slack.NewSectionBlock(
nil,
[]*slack.TextBlockObject{
slack.NewTextBlockObject("mrkdwn", ":star: *Top hosts*", false, false),
slack.NewTextBlockObject("mrkdwn", ":spoon: *Most mouths fed*", false, false),
slack.NewTextBlockObject("mrkdwn", fmt.Sprintf("*%s (Total)*", dateOneMonthAgo.Month().String()), false, false),
},
nil,
)

topHostsRows := make([]*slack.TextBlockObject, 0, len(monthlyTopHosts)*2)
for i, host := range monthlyTopHosts {
totalOrderCount, hostExists := hostIdToTotalOrderCount[host.HostId]
totalMouthsFedCount, hostExists := hostIdToTotalMouthsFedCount[host.HostId]
if !hostExists {
return nil, fmt.Errorf("host %s (%s) is not in monthlyTopHostsTotalCounts", host.HostId, host.HostName)
}
Expand All @@ -97,11 +97,11 @@ func buildTopHostsMessageBlocks(monthlyTopHosts []order.HostOrderCount, monthlyT
}

leftColumnString := fmt.Sprintf("%s %s%s%s", positionEmoji, UnicodeLeftToRightMark, host.HostName, UnicodeLeftToRightMark)
if host.OrderCount == totalOrderCount {
if host.MouthsFedCount == totalMouthsFedCount {
leftColumnString += " :new:"
}

rightColumnString := fmt.Sprintf("%d (%d)", host.OrderCount, totalOrderCount)
rightColumnString := fmt.Sprintf("%d (%d)", host.MouthsFedCount, totalMouthsFedCount)

topHostsRows = append(topHostsRows,
slack.NewTextBlockObject("mrkdwn", leftColumnString, false, false),
Expand All @@ -125,10 +125,10 @@ func venueOrderCountsToVenueIds(venueOrderCounts []order.VenueOrderCount) []stri
return venueIds
}

func hostOrderCountsToHostIds(hostOrderCounts []order.HostOrderCount) []string {
func mouthsFedCountsToHostIds(mouthsFedCounts []order.MouthsFedCount) []string {
var hostIds []string
for _, hostOrderCount := range hostOrderCounts {
hostIds = append(hostIds, hostOrderCount.HostId)
for _, mouthsFedCount := range mouthsFedCounts {
hostIds = append(hostIds, mouthsFedCount.HostId)
}
return hostIds
}
Expand All @@ -149,13 +149,13 @@ func (h *Service) getTopVenuesMessageBlocks(channelId string) ([]slack.Block, er
}

func (h *Service) getTopHostsMessageBlocks(channelId string) ([]slack.Block, error) {
monthlyTopHosts, err := h.orderStore.GetHostsWithMostOrders(dateOneMonthAgo, numberOfDigestRows, channelId, []string{})
monthlyTopHosts, err := h.orderStore.GetHostsWithMostMouthsFed(dateOneMonthAgo, numberOfDigestRows, channelId, []string{})
if err != nil {
return nil, fmt.Errorf("error getting top hosts of the last month: %w", err)
}

monthlyTopHostIds := hostOrderCountsToHostIds(monthlyTopHosts)
monthlyTopHostsTotalCounts, err := h.orderStore.GetHostsWithMostOrders(time.Time{}, numberOfDigestRows, channelId, monthlyTopHostIds)
monthlyTopHostIds := mouthsFedCountsToHostIds(monthlyTopHosts)
monthlyTopHostsTotalCounts, err := h.orderStore.GetHostsWithMostMouthsFed(time.Time{}, numberOfDigestRows, channelId, monthlyTopHostIds)
if err != nil {
return nil, fmt.Errorf("error getting top hosts of all time: %w", err)
}
Expand Down

0 comments on commit 6e570d5

Please sign in to comment.