mapgen

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package mapgen aggregates submitted result files into the data of the public map and writes the static site (no server, no external resources).

Index

Constants

View Source
const TimelineDays = 120

TimelineDays bounds the timeline length.

Variables

View Source
var ErrNoJSON = errors.New("no JSON submission found in the issue body")

ErrNoJSON is returned when an issue body contains no submission.

Functions

func Build

func Build(cat *catalog.Catalog, opt Options) (*Data, []Problem, error)

Build aggregates submissions and writes the static site.

func CheckFile

func CheckFile(root, path string) (*submit.Submission, error)

CheckFile validates a submission file and its location (<root>/AS<asn>/<date>-<hex6>.json, matching the content).

func FromIssue

func FromIssue(body []byte, resultsDir string) (string, error)

FromIssue extracts, validates and stores a submission pasted into an issue. It returns the written path relative to resultsDir's parent.

func I18nFrom

func I18nFrom(keys map[string]map[string]string) map[string]map[string]string

I18nFrom extracts the strings the map needs from the locale catalogs.

func Load

func Load(root string) ([]Entry, []Problem, error)

Load reads every submission under root. Invalid files are returned as problems.

Types

type CategoryInfo

type CategoryInfo struct {
	ID    string            `json:"id"`
	Title map[string]string `json:"title"`
}

CategoryInfo names a category.

type Cell

type Cell struct {
	Status model.Status     `json:"s"`
	Kind   model.Kind       `json:"k"`
	Conf   model.Confidence `json:"c,omitempty"`
	Date   string           `json:"d"`
	N      int              `json:"n"`
}

Cell is the latest state of one target on one network.

type Data

type Data struct {
	Generated   string                       `json:"generated"`
	Updated     string                       `json:"updated,omitempty"`
	Sample      bool                         `json:"sample,omitempty"`
	Submissions int                          `json:"submissions"`
	Categories  []CategoryInfo               `json:"categories"`
	Targets     []TargetInfo                 `json:"targets"`
	Rows        []Row                        `json:"rows"`
	Regions     []RegionInfo                 `json:"regions"`
	Cells       map[string]map[string]Cell   `json:"cells"`
	Timeline    map[string][]Day             `json:"timeline"`
	Events      map[string][]Event           `json:"events"`
	I18n        map[string]map[string]string `json:"i18n"`
	Repo        string                       `json:"repo"`
}

Data is the JSON consumed by the map front-end.

func Aggregate

func Aggregate(entries []Entry, cat *catalog.Catalog, now time.Time) *Data

Aggregate builds the map data from valid submissions.

type Day

type Day [5]any

Day is [date, ok, throttled, partial, blocked] counts.

type Entry

type Entry struct {
	Path string
	Sub  submit.Submission
}

Entry is one valid submission together with its repository path.

func SampleEntries

func SampleEntries(cat *catalog.Catalog, now time.Time) []Entry

SampleEntries generates deterministic, clearly fake data for layout testing. Sample ASNs come from the documentation range (RFC 5398).

type Event

type Event struct {
	Date string       `json:"d"`
	Row  string       `json:"row"`
	From model.Status `json:"from"`
	To   model.Status `json:"to"`
	Kind model.Kind   `json:"k"`
}

Event is a status change of a target on a network.

type Options

type Options struct {
	Results string // directory with submissions
	Out     string // output directory
	Assets  string // optional directory with social-preview.png
	Sample  bool   // add clearly-labelled sample data (never for deployment)
	Now     time.Time
}

Options configure a site build.

type Problem

type Problem struct {
	Path string
	Err  error
}

Problem describes a rejected file.

func ValidatePaths

func ValidatePaths(root string, paths []string) []Problem

ValidatePaths checks specific files (e.g. those changed in a pull request).

func (Problem) Error

func (p Problem) Error() string

type RegionInfo

type RegionInfo struct {
	Code string `json:"code"`
	RU   string `json:"ru"`
	EN   string `json:"en"`
}

RegionInfo names a region.

type Row

type Row struct {
	Key     string `json:"key"`
	ASN     int    `json:"asn"`
	ISP     string `json:"isp"`
	Region  string `json:"region,omitempty"`
	Conn    string `json:"conn"`
	Reports int    `json:"reports"`
	Last    string `json:"last"`
}

Row is one network (ASN × region × connection type).

type TargetInfo

type TargetInfo struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	Category string `json:"category"`
}

TargetInfo names a target.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL