Skip to main content

internal/api/portalactivity.go

internal/api · 233 lines · 16 declarations · source

Declarations

type portalRange

type portalRange struct {
Key, Label string
// Length is the window; zero is the whole ledger.
Length time.Duration
// Buckets is how many bars the chart draws. Chosen per window so a bar is a unit a person thinks
// in: an hour of a day, a quarter of a day of a week, a day of a month.
Buckets int
}

portalRange is one window the overview offers.

source

var portalRanges

var portalRanges = []portalRange{
{"all", "All time", 0, 40},
{"24h", "24h", 24 * time.Hour, 24},
{"7d", "7d", 7 * 24 * time.Hour, 28},
{"30d", "30d", 30 * 24 * time.Hour, 30},
{"90d", "90d", 90 * 24 * time.Hour, 45},
}

portalRanges are the windows offered. Closed: a query parameter picks one of these, and cannot ask the ledger for a window of its own choosing.

source

const portalDefaultRange

const portalDefaultRange = "7d"

portalDefaultRange is a week: long enough to show a pattern, short enough that yesterday is visible.

source

func pickRange

func pickRange(key string) portalRange

source

func overviewHref

func overviewHref(rangeKey, project string) string

overviewHref is the overview for a window and, optionally, one project.

source

type portalLink struct {
Label, Href string
Current bool
}

portalLink is a place the page can go, and whether it is the one being shown.

source

type portalSwitch

type portalSwitch struct {
Label string
Items []portalLink
}

portalSwitch moves between projects without leaving the page's kind: the overview narrows to one, the ledger filters to one, and a project page becomes another's.

source

func switcher

func switcher(names []string, current string, href func(string) string) *portalSwitch

source

type portalActivity

type portalActivity struct {
Project string
Ranges []portalLink
Refresh string
Updated string
Compared string
// The four numbers an operator reads first.
Turns, Recalls, Refused, Erasures portalCard
Total, TotalRefused int64
Bars []portalBar
Axis []string
// RankTitle and Ranking are the busiest projects across the instance, or the busiest operations
// within one project when the page is narrowed to it.
RankTitle string
Ranking []portalRank
Operations []pg.OperationActivity
}

source

type portalCard

type portalCard struct {
Value int64
Detail string
Trend string
Direction string
}

source

type portalBar

type portalBar struct {
Allowed, Refused int
Title string
}

portalBar is one bucket as heights: percentages of the busiest bucket, so the chart's scale is the window's own and an idle week does not draw as a flat line at the bottom of somebody else's scale.

source

type portalRank

type portalRank struct {
Label, Href string
Operations, Refused int64
Share int
}

source

func newPortalActivity

func newPortalActivity(rng portalRange, project string, a pg.Activity, now time.Time) *portalActivity

source

func trend

func trend(current, previous int64, has, upIsBad bool) (string, string)

trend says how a number moved against the window before, and whether that is worth a colour.

A percentage, because "+40" means nothing without the number it grew from. A count that grew from nothing is "new" rather than an infinite percentage. Only refusals are coloured as good or bad: more refusals is what an attack looks like from here, while more turns stored is only more use, and colouring it would be the console having an opinion it cannot defend.

source

func direction

func direction(up, upIsBad bool) string

source

func bucketLabel

func bucketLabel(start time.Time, width time.Duration) string

bucketLabel names a bucket at the precision its width needs: an hour needs the time, a day does not.

source