clone

an offline map explorer where each world, from a game map to a city's open data, ships as one .atlas file

archive/golden-reference
atlas / tools / maturity / main.go
main.go 4.3K
1// Command maturity reads the library and reports how mature each build of2// each volume is, along the axes internal/measure defines -- the same3// yardstick the cartograph workbench judges by, aligned with the semantic4// conventions the payloads speak: how thoroughly locations are explained in5// writing, how much visual map information the rasters hold, how much6// machine-readable structure rides beyond the pixels, and how much of the7// shared vocabulary the build actually declares.8//9// Every number is an absolute measurement of one build, never a rank within10// the collection: ranks move when the collection does, and a merge gate needs11// figures that stand still. A build that adds icons, or descriptions, or a12// deeper pyramid, reads higher than the build before it, and a build that13// lost something reads lower -- which is the judgement the library exists to14// make visible.15package main1617import (18 "flag"19 "fmt"20 "os"21 "path/filepath"22 "sort"2324 "github.com/FelineStateMachine/atlas/internal/bundle"25 "github.com/FelineStateMachine/atlas/internal/measure"26)2728func main() {29 bundles := flag.String("bundles", "",30 "registry directory holding .atlas bundles (default: the application's own library)")31 flag.Parse()32 if *bundles == "" {33 library, err := bundle.DefaultDir()34 if err != nil {35 fmt.Fprintln(os.Stderr, "maturity: resolving the bundle library:", err)36 os.Exit(1)37 }38 *bundles = library39 }40 if err := run(*bundles); err != nil {41 fmt.Fprintln(os.Stderr, "maturity:", err)42 os.Exit(1)43 }44}4546func run(dir string) error {47 paths, err := filepath.Glob(filepath.Join(dir, "*.atlas"))48 if err != nil {49 return err50 }51 if len(paths) == 0 {52 return fmt.Errorf("no bundles in %s", dir)53 }5455 byGame := make(map[string][]*measure.Build)56 for _, path := range paths {57 build, err := measure.MeasureBundle(path)58 if err != nil {59 return fmt.Errorf("%s: %w", filepath.Base(path), err)60 }61 byGame[build.VolumeSlug] = append(byGame[build.VolumeSlug], build)62 }6364 slugs := make([]string, 0, len(byGame))65 for slug := range byGame {66 slugs = append(slugs, slug)67 }68 sort.Strings(slugs)69 for _, slug := range slugs {70 builds := byGame[slug]71 // The registry's own order, spelled once in internal/measure, so the72 // first line of every volume is the build the reader sees.73 sort.Slice(builds, func(a, b int) bool { return measure.Newer(builds[a], builds[b]) })74 fmt.Printf("%s (%s)\n", builds[0].VolumeTitle, slug)75 for at, b := range builds {76 marker := " "77 if at == 0 {78 marker = "serving "79 }80 fmt.Printf(" %s%s\n", marker, b.File)81 fmt.Printf(" annotation %5d pins · %d described (%s) · median %d chars\n",82 b.Pins, b.Described, b.DescribedPct(), b.MedianLength)83 fmt.Printf(" cartography %5d tiles · %s MB unique raster · depth z%d holds %d tiles\n",84 b.TileCount, b.RasterMB(), b.Depth, b.DepthTiles)85 fmt.Printf(" structure %5d categories in %d groups · %d text label sets · %d zones (%d vertices) · %d layers\n",86 b.Categories, b.Groups, b.TextSets, b.Zones, b.Vertices, b.Lenses)87 fmt.Printf(" icons %5d of %d marker categories carry one (%s)\n",88 b.IconsCarried, b.IconsWanted, b.IconPct())89 fmt.Printf(" conventions %s\n", conventionsLine(b))90 for _, account := range b.Merges {91 fmt.Printf(" merge %s: %d donor pins · %d donor shapes · %d matched (median %dpx) · %d added (%d adopted) · %d held · %d rejected\n",92 account.Source, account.DonorPins, account.DonorShapesN(), account.MatchedN(), account.MedianMatchPx(),93 account.Added, account.AdoptedN(), account.HeldN(), account.RejectedN())94 }95 }96 }97 return nil98}99100// conventionsLine says how much of the shared vocabulary a build speaks. A101// build from before the conventions says so plainly rather than scoring102// zero on a test it never sat.103func conventionsLine(b *measure.Build) string {104 if b.Conventions == 0 {105 return "none declared (pre-conventions build)"106 }107 line := fmt.Sprintf("v%d · %s of categories declare their rendering · geometry %s",108 b.Conventions, b.RenderPct(), b.Geometry)109 if b.StdIcons > 0 {110 line += fmt.Sprintf(" · %d standard icons", b.StdIcons)111 }112 if b.GeoPins > 0 {113 line += fmt.Sprintf(" · %d pins carry true coordinates", b.GeoPins)114 }115 if b.UnknownAttrs > 0 {116 line += fmt.Sprintf(" · %d attributes this build does not know", b.UnknownAttrs)117 }118 return line119}