Skip to content

Commit

Permalink
feat(zess): bar colors
Browse files Browse the repository at this point in the history
  • Loading branch information
Topvennie committed Dec 10, 2024
1 parent 97fcd10 commit dbefc43
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 34 deletions.
15 changes: 15 additions & 0 deletions db/migrations/20241210002653_add_scan_id.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- +goose Up
-- +goose StatementBegin
ALTER TABLE scan
ADD COLUMN scan_id INTEGER NOT NULL DEFAULT 0;

ALTER TABLE scan
ALTER COLUMN scan_id
DROP DEFAULT;
-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin
ALTER TABLE scan
DROP COLUMN scan_id;
-- +goose StatementEnd
10 changes: 5 additions & 5 deletions db/queries/scan.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ FROM scan
WHERE id = $1;

-- name: CreateScan :one
INSERT INTO scan (scan_time)
VALUES ($1)
INSERT INTO scan (scan_id, scan_time)
VALUES ($1, $2)
RETURNING *;

-- name: UpdateScan :one
UPDATE scan
SET scan_time = $1
WHERE id = $2
SET scan_id = $1, scan_time = $2
WHERE id = $3
RETURNING *;

-- name: DeleteScan :execrows
Expand All @@ -38,7 +38,7 @@ LIMIT 1;
SELECT *
FROM scan
WHERE id > $1
ORDER BY scan_time ASC;
ORDER BY scan_id, scan_time ASC;

-- name: GetScansInCurrentSeason :one
SELECT COUNT(*) AS amount
Expand Down
10 changes: 8 additions & 2 deletions internal/pkg/db/dto/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,32 @@ import (
// Scan is the DTO for the scan
type Scan struct {
ID int32 `json:"id"`
ScanID int32 `json:"scan_id"`
ScanTime time.Time `json:"scan_time" validate:"required"`
}

// ScanDTO converts a sqlc.Scan to a Scan
func ScanDTO(scan sqlc.Scan) *Scan {
return &Scan{
ID: scan.ID,
ScanID: scan.ScanID,
ScanTime: scan.ScanTime.Time,
}
}

// CreateParams converts a Scan to sqlc.CreateScanParams
func (s *Scan) CreateParams() pgtype.Timestamptz {
return pgtype.Timestamptz{Time: s.ScanTime, Valid: true}
func (s *Scan) CreateParams() sqlc.CreateScanParams {
return sqlc.CreateScanParams{
ScanID: s.ScanID,
ScanTime: pgtype.Timestamptz{Time: s.ScanTime, Valid: true},
}
}

// UpdateParams converts a Scan to sqlc.UpdateScanParams
func (s *Scan) UpdateParams() sqlc.UpdateScanParams {
return sqlc.UpdateScanParams{
ID: s.ID,
ScanID: s.ScanID,
ScanTime: pgtype.Timestamptz{Time: s.ScanTime, Valid: true},
}
}
1 change: 1 addition & 0 deletions internal/pkg/db/sqlc/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 26 additions & 20 deletions internal/pkg/db/sqlc/scan.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions internal/pkg/zess/zess.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/zeusWPI/scc/internal/pkg/db/sqlc"
"github.com/zeusWPI/scc/pkg/config"
"github.com/zeusWPI/scc/pkg/util"
"go.uber.org/zap"
)

// Zess represents a zess instance
Expand Down Expand Up @@ -69,7 +70,7 @@ func (z *Zess) UpdateScans() error {
return err
}

lastScan = sqlc.Scan{ID: -1}
lastScan = sqlc.Scan{ScanID: -1}
}

// Get all scans
Expand All @@ -78,9 +79,11 @@ func (z *Zess) UpdateScans() error {
return err
}

zap.S().Info(lastScan)

errs := make([]error, 0)
for _, scan := range *zessScans {
if lastScan.ID >= scan.ID {
if scan.ScanID <= lastScan.ScanID {
continue
}

Expand Down
1 change: 1 addition & 0 deletions tui/view/event/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var (

// Styles overview
var (
sOverviewTotal = base.AlignVertical(lipgloss.Center)
sOverviewTitle = base.Bold(true).Foreground(cWarning).Width(widthOverview).Align(lipgloss.Center)
sOverview = base.Border(lipgloss.NormalBorder(), true, false, false, false).BorderForeground(cBorder).Width(widthOverview).MarginRight(mOverview)
sPassedName = base.Foreground(cZeus).Faint(true).Width(widthOverviewName)
Expand Down
5 changes: 5 additions & 0 deletions tui/view/event/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ func (m *Model) viewNormal() string {
title := sOverviewTitle.Render("Events")
overview = lipgloss.JoinVertical(lipgloss.Left, title, overview)

// Center the overview
if lipgloss.Height(im) > lipgloss.Height(overview) {
overview = sOverviewTotal.Height(lipgloss.Height(im)).Render(overview)
}

// Combine image and overview
view := lipgloss.JoinHorizontal(lipgloss.Top, overview, im)

Expand Down
29 changes: 26 additions & 3 deletions tui/view/zess/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,39 @@ var (

// Colors
var (
cBarChart = lipgloss.Color("#32012F")

cBorder = lipgloss.Color("#383838")
cZeus = lipgloss.Color("#FF7F00")
cStatsTitle = lipgloss.Color("#EE4B2B")
)

// Message colors
var colors = []string{
"#FAF500", // Yellow
"#3AFA00", // Green
"#FAD700", // Yellow Green
"#FAA600", // Orange
"#FAE200", // Yellow Orange
"#FA7200", // Orange Red
"#FA4600", // Red
"#FA0400", // Real Red
"#FA0079", // Pink Red
"#FA00FA", // Pink
"#EE00FA", // Purple
"#8300FA", // Purple Blue
"#3100FA", // Blue
"#00FAFA", // Light Blue
"#00FAA5", // Green Blue
"#00FA81", // IDK
"#F8FA91", // Weird Light Green
"#FAD392", // Light Orange
"#FA9E96", // Salmon
"#DEA2F9", // Fuchsia
"#B3D2F9", // Boring Blue
}

// Styles chart
var (
sBar = base.Foreground(cBarChart)
sBar = base
)

// Styles stats
Expand Down
2 changes: 1 addition & 1 deletion tui/view/zess/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (m *Model) viewChart() string {
Values: []barchart.BarValue{{
Name: scan.label,
Value: float64(scan.amount),
Style: sBar,
Style: sBar.Foreground(lipgloss.Color(scan.color)),
}},
}

Expand Down
13 changes: 12 additions & 1 deletion tui/view/zess/zess.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package zess

import (
"context"
"math/rand/v2"

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
Expand All @@ -23,6 +24,7 @@ type weekScan struct {
time yearWeek
amount int64
label string
color string
}

// Model represents the Model for the zess view
Expand Down Expand Up @@ -227,7 +229,12 @@ func updateScans(view view.View) (tea.Msg, error) {
}

if !found {
zessScanMsg.scans = append(zessScanMsg.scans, weekScan{time: newTime, amount: 1, label: newScan.ScanTime.Time.Format("02/01")})
zessScanMsg.scans = append(zessScanMsg.scans, weekScan{
time: newTime,
amount: 1,
label: newScan.ScanTime.Time.Format("02/01"),
color: randomColor(),
})
}

// Update scan ID
Expand Down Expand Up @@ -276,3 +283,7 @@ func (z *yearWeek) after(z2 yearWeek) bool {

return z.week > z2.week
}

func randomColor() string {
return colors[rand.IntN(len(colors))]
}

0 comments on commit dbefc43

Please sign in to comment.