diff --git a/internal/geo/geo.go b/internal/geo/geo.go new file mode 100644 index 0000000..1cf4f0c --- /dev/null +++ b/internal/geo/geo.go @@ -0,0 +1,132 @@ +// Package geo places IP addresses on the Host screen's map of Iran, offline: +// Iranian addresses to a town, others to a country. The data is DB-IP Lite +// (https://db-ip.com, CC BY 4.0) and Natural Earth's borders, made by +// scripts/geo/build.py. +package geo + +import ( + "bufio" + "bytes" + "compress/gzip" + _ "embed" + "encoding/binary" + "io" + "net/netip" + "sort" + "sync" +) + +// Credit is the attribution DB-IP's license asks for. +const Credit = "IP locations by DB-IP.com" + +// Shape is a country's border ring, lon/lat pairs. +type Shape struct { + Country string + Ring [][2]float64 +} + +// Place is where an address is. +type Place struct { + Country string // ISO 3166 code + Town string // in Iran only + Province string + Lat, Lon float64 +} + +//go:embed ip.bin +var raw []byte + +type span struct { + start, end uint64 + v int +} + +type table struct { + places []Place + countries []Place + ir4, ir6 []span + world []span +} + +var ( + once sync.Once + data *table +) + +func load() *table { + once.Do(func() { + zr, err := gzip.NewReader(bytes.NewReader(raw)) + if err != nil { + panic(err) + } + r := bufio.NewReader(zr) + var magic [4]byte + if _, err := io.ReadFull(r, magic[:]); err != nil || string(magic[:]) != "IZG1" { + panic("geo: bad ip.bin") + } + u := func() uint64 { n, _ := binary.ReadUvarint(r); return n } + s := func() float64 { n, _ := binary.ReadVarint(r); return float64(n) / 100 } + str := func() string { + b := make([]byte, u()) + _, _ = io.ReadFull(r, b) + return string(b) + } + t := &table{} + for n := u(); n > 0; n-- { + lat, lon := s(), s() + town := str() + t.places = append(t.places, Place{Country: "IR", Lat: lat, Lon: lon, Town: town, Province: str()}) + } + for n := u(); n > 0; n-- { + var cc [2]byte + _, _ = io.ReadFull(r, cc[:]) + lat, lon := s(), s() + t.countries = append(t.countries, Place{Country: string(cc[:]), Lat: lat, Lon: lon}) + } + spans := func() []span { + out := make([]span, u()) + last := ^uint64(0) // -1, so the first gap is the first start + for i := range out { + a := last + 1 + u() + b := a + u() + out[i], last = span{a, b, int(u())}, b + } + return out + } + t.ir4, t.ir6, t.world = spans(), spans(), spans() + data = t + }) + return data +} + +func find(spans []span, ip uint64) (int, bool) { + i := sort.Search(len(spans), func(i int) bool { return spans[i].end >= ip }) + if i < len(spans) && spans[i].start <= ip { + return spans[i].v, true + } + return 0, false +} + +// Locate says where an address is; false for private and unknown ones. +func Locate(a netip.Addr) (Place, bool) { + a = a.Unmap() + if !a.IsGlobalUnicast() || a.IsPrivate() { + return Place{}, false + } + t := load() + if a.Is4() { + ip := uint64(binary.BigEndian.Uint32(a.AsSlice())) + if i, ok := find(t.ir4, ip); ok { + return t.places[i], true + } + if i, ok := find(t.world, ip); ok { + return t.countries[i], true + } + return Place{}, false + } + b := a.As16() + if i, ok := find(t.ir6, binary.BigEndian.Uint64(b[:8])); ok { + return t.places[i], true + } + return Place{}, false +} diff --git a/internal/geo/geo_test.go b/internal/geo/geo_test.go new file mode 100644 index 0000000..50d02c1 --- /dev/null +++ b/internal/geo/geo_test.go @@ -0,0 +1,31 @@ +package geo + +import ( + "net/netip" + "testing" +) + +func TestLocate(t *testing.T) { + for _, c := range []struct{ ip, country string }{ + {"2.176.0.1", "IR"}, // TCI, Iran + {"5.160.0.1", "IR"}, // Respina, Iran + {"8.8.8.8", "US"}, // Google + {"81.169.145.1", "DE"}, // Strato, Germany + } { + p, ok := Locate(netip.MustParseAddr(c.ip)) + if !ok || p.Country != c.country { + t.Errorf("%s: %+v %v, want %s", c.ip, p, ok, c.country) + } + if c.country == "IR" && (p.Town == "" || p.Lat < 25 || p.Lat > 40 || p.Lon < 44 || p.Lon > 64) { + t.Errorf("%s: %+v isn't a place in Iran", c.ip, p) + } + } + for _, ip := range []string{"192.168.1.1", "127.0.0.1", "10.0.0.1", "fe80::1"} { + if p, ok := Locate(netip.MustParseAddr(ip)); ok { + t.Errorf("%s: %+v, want none", ip, p) + } + } + if len(Shapes) == 0 || Shapes[0].Country != "IR" { + t.Fatal("Iran's border should come first") + } +} diff --git a/internal/geo/ip.bin b/internal/geo/ip.bin new file mode 100644 index 0000000..5bc618d Binary files /dev/null and b/internal/geo/ip.bin differ diff --git a/internal/geo/shapes.go b/internal/geo/shapes.go new file mode 100644 index 0000000..290c8e1 --- /dev/null +++ b/internal/geo/shapes.go @@ -0,0 +1,32 @@ +// Code generated by scripts/geo/build.py from Natural Earth (public domain). DO NOT EDIT. + +package geo + +// Shapes are Iran's border and its neighbours', as lon/lat rings; Iran's first. +var Shapes = []Shape{ + {"IR", [][2]float64{{56.19, 26.92}, {55.95, 26.70}, {55.85, 26.73}, {55.42, 26.58}, {55.30, 26.64}, {55.76, 26.81}, {55.76, 26.95}, {55.91, 26.91}, {56.21, 27.00}, {56.28, 26.95}, {56.19, 26.92}}}, + {"IR", [][2]float64{{53.91, 37.34}, {54.19, 37.33}, {54.70, 37.47}, {54.90, 37.78}, {55.38, 38.05}, {55.58, 38.10}, {56.27, 38.08}, {56.32, 38.19}, {56.44, 38.25}, {57.19, 38.22}, {57.31, 38.13}, {57.35, 37.97}, {57.98, 37.83}, {58.26, 37.67}, {58.82, 37.68}, {59.30, 37.51}, {59.45, 37.25}, {60.06, 36.96}, {60.34, 36.64}, {61.12, 36.64}, {61.17, 36.57}, {61.21, 36.10}, {61.15, 35.98}, {61.25, 35.87}, {61.28, 35.51}, {61.19, 35.31}, {61.10, 35.27}, {61.15, 35.09}, {61.08, 34.86}, {60.95, 34.65}, {60.73, 34.52}, {60.89, 34.32}, {60.64, 34.31}, {60.49, 34.09}, {60.53, 33.84}, {60.49, 33.71}, {60.57, 33.59}, {60.92, 33.51}, {60.56, 33.14}, {60.83, 32.25}, {60.82, 31.50}, {61.66, 31.38}, {61.76, 31.29}, {61.81, 30.91}, {60.84, 29.86}, {61.32, 29.37}, {61.62, 28.79}, {61.89, 28.55}, {62.35, 28.41}, {62.56, 28.24}, {62.76, 28.24}, {62.81, 27.50}, {62.75, 27.27}, {62.92, 27.22}, {63.17, 27.25}, {63.31, 27.12}, {63.24, 27.08}, {63.25, 26.88}, {63.19, 26.84}, {63.16, 26.65}, {62.44, 26.56}, {62.31, 26.49}, {62.24, 26.36}, {62.13, 26.37}, {61.84, 26.23}, {61.75, 25.84}, {61.66, 25.75}, {61.59, 25.20}, {61.41, 25.10}, {60.66, 25.28}, {60.51, 25.44}, {60.40, 25.31}, {59.62, 25.40}, {59.46, 25.48}, {59.05, 25.42}, {58.80, 25.55}, {58.20, 25.59}, {57.94, 25.69}, {57.80, 25.65}, {57.73, 25.72}, {57.33, 25.79}, {57.10, 26.37}, {57.04, 26.80}, {56.91, 26.99}, {56.73, 27.13}, {56.36, 27.20}, {56.12, 27.14}, {55.94, 27.04}, {55.65, 26.98}, {55.42, 26.77}, {55.29, 26.79}, {54.90, 26.56}, {54.64, 26.51}, {54.25, 26.70}, {53.71, 26.73}, {53.45, 26.94}, {52.69, 27.32}, {52.48, 27.62}, {52.03, 27.82}, {51.59, 27.86}, {51.28, 28.13}, {51.09, 28.51}, {51.06, 28.73}, {50.87, 28.87}, {50.88, 29.06}, {50.68, 29.15}, {50.65, 29.42}, {50.17, 29.92}, {50.07, 30.20}, {49.55, 30.03}, {49.03, 30.33}, {49.05, 30.40}, {49.25, 30.41}, {49.22, 30.47}, {49.00, 30.51}, {49.04, 30.45}, {48.89, 30.33}, {48.92, 30.12}, {48.87, 30.06}, {48.55, 29.96}, {48.43, 30.04}, {48.33, 30.29}, {48.01, 30.47}, {48.01, 30.99}, {47.68, 31.00}, {47.68, 31.40}, {47.83, 31.79}, {47.51, 32.15}, {47.37, 32.42}, {47.12, 32.47}, {46.38, 32.93}, {46.11, 32.96}, {46.08, 33.09}, {46.15, 33.23}, {46.02, 33.42}, {45.87, 33.49}, {45.88, 33.61}, {45.74, 33.60}, {45.40, 33.97}, {45.54, 34.22}, {45.44, 34.42}, {45.50, 34.58}, {45.64, 34.57}, {45.68, 34.80}, {45.92, 35.03}, {46.13, 35.13}, {46.11, 35.32}, {45.98, 35.48}, {46.00, 35.61}, {46.27, 35.77}, {45.78, 35.82}, {45.56, 35.98}, {45.36, 36.02}, {45.24, 36.36}, {45.08, 36.43}, {45.02, 36.70}, {44.88, 36.80}, {44.77, 37.14}, {44.79, 37.29}, {44.57, 37.44}, {44.55, 37.66}, {44.59, 37.71}, {44.22, 37.88}, {44.45, 38.33}, {44.30, 38.39}, {44.27, 38.84}, {44.17, 38.93}, {44.18, 39.14}, {44.08, 39.22}, {44.02, 39.38}, {44.39, 39.42}, {44.46, 39.67}, {44.59, 39.77}, {44.82, 39.65}, {45.14, 39.25}, {45.48, 39.01}, {46.17, 38.87}, {46.55, 38.90}, {47.34, 39.42}, {47.77, 39.65}, {48.00, 39.68}, {48.32, 39.40}, {48.10, 39.24}, {48.29, 39.02}, {48.05, 38.94}, {48.00, 38.85}, {48.59, 38.41}, {48.87, 38.44}, {48.93, 38.02}, {49.08, 37.67}, {49.37, 37.52}, {50.13, 37.41}, {50.53, 37.01}, {51.12, 36.74}, {51.76, 36.61}, {52.19, 36.62}, {53.77, 36.93}, {53.92, 36.93}, {53.68, 36.85}, {53.97, 36.82}, {54.02, 36.90}, {53.91, 37.34}}}, + {"AE", [][2]float64{{56.30, 25.65}, {56.39, 24.98}, {56.06, 24.74}, {56.00, 24.95}, {55.80, 24.87}, {55.76, 24.24}, {55.93, 24.22}, {55.99, 24.06}, {55.47, 23.94}, {55.51, 23.72}, {55.12, 22.62}, {52.56, 22.93}, {51.57, 24.13}, {51.61, 24.34}, {51.91, 23.99}, {52.65, 24.15}, {53.89, 24.08}, {54.40, 24.28}, {54.75, 24.81}, {55.94, 25.79}, {56.08, 26.06}, {56.17, 26.05}, {56.14, 25.69}, {56.30, 25.65}}}, + {"AE", [][2]float64{{53.33, 24.26}, {53.19, 24.29}, {53.41, 24.41}, {53.33, 24.26}}}, + {"AE", [][2]float64{{53.93, 24.18}, {53.63, 24.17}, {53.83, 24.26}, {53.93, 24.18}}}, + {"AF", [][2]float64{{66.52, 37.35}, {67.70, 37.23}, {68.07, 36.95}, {68.91, 37.33}, {69.30, 37.12}, {69.49, 37.55}, {70.19, 37.58}, {70.21, 37.92}, {70.88, 38.46}, {71.26, 38.31}, {71.28, 37.92}, {71.58, 37.91}, {71.43, 37.13}, {71.67, 36.70}, {72.66, 37.03}, {72.90, 37.27}, {73.38, 37.46}, {73.72, 37.42}, {73.65, 37.24}, {74.35, 37.42}, {74.89, 37.23}, {74.73, 37.29}, {74.37, 37.16}, {74.54, 37.02}, {74.04, 36.83}, {73.12, 36.87}, {72.25, 36.73}, {71.23, 36.12}, {71.19, 36.04}, {71.57, 35.55}, {71.62, 35.18}, {70.97, 34.53}, {71.10, 34.37}, {71.05, 34.05}, {70.65, 33.95}, {69.89, 34.01}, {70.26, 33.29}, {69.50, 33.02}, {69.24, 32.43}, {69.28, 31.94}, {68.87, 31.63}, {68.60, 31.80}, {68.16, 31.80}, {67.58, 31.51}, {67.74, 31.34}, {67.45, 31.23}, {66.83, 31.26}, {66.35, 30.80}, {66.24, 30.11}, {66.31, 29.97}, {66.18, 29.84}, {65.10, 29.56}, {64.39, 29.54}, {64.10, 29.39}, {63.57, 29.50}, {62.48, 29.41}, {60.84, 29.86}, {61.81, 30.91}, {61.66, 31.38}, {60.82, 31.50}, {60.83, 32.25}, {60.56, 33.06}, {60.92, 33.51}, {60.51, 33.64}, {60.49, 34.09}, {60.64, 34.31}, {60.89, 34.32}, {60.73, 34.52}, {61.08, 34.86}, {61.26, 35.62}, {61.62, 35.43}, {61.98, 35.44}, {62.31, 35.17}, {62.69, 35.26}, {63.06, 35.45}, {63.13, 35.85}, {64.01, 36.01}, {64.51, 36.34}, {64.82, 37.13}, {65.55, 37.25}, {65.77, 37.57}, {66.52, 37.35}}}, + {"AM", [][2]float64{{44.77, 39.70}, {44.29, 40.04}, {43.67, 40.13}, {43.57, 40.48}, {43.72, 40.72}, {43.44, 41.11}, {45.00, 41.29}, {45.19, 41.15}, {45.07, 41.08}, {45.59, 40.85}, {45.38, 40.64}, {45.97, 40.17}, {45.89, 40.02}, {45.58, 39.98}, {46.20, 39.59}, {46.48, 39.56}, {46.37, 39.40}, {46.58, 39.22}, {46.40, 39.19}, {46.49, 38.91}, {46.11, 38.88}, {45.75, 39.56}, {45.46, 39.49}, {45.15, 39.58}, {45.03, 39.77}, {44.77, 39.70}}}, + {"AZ", [][2]float64{{44.82, 39.65}, {45.03, 39.77}, {45.17, 39.57}, {45.78, 39.55}, {45.77, 39.38}, {45.98, 39.24}, {46.11, 38.88}, {45.48, 39.01}, {44.82, 39.65}}}, + {"AZ", [][2]float64{{48.87, 38.44}, {48.59, 38.41}, {48.00, 38.85}, {48.29, 39.02}, {48.10, 39.24}, {48.32, 39.40}, {48.00, 39.68}, {46.49, 38.91}, {46.40, 39.19}, {46.58, 39.22}, {46.37, 39.40}, {46.48, 39.56}, {46.20, 39.59}, {45.58, 39.98}, {45.89, 40.02}, {45.96, 40.23}, {45.45, 40.53}, {45.38, 40.67}, {45.59, 40.85}, {45.07, 41.08}, {45.19, 41.15}, {45.00, 41.29}, {45.28, 41.45}, {46.53, 41.09}, {46.67, 41.29}, {46.18, 41.66}, {46.43, 41.89}, {46.75, 41.81}, {47.32, 41.28}, {47.79, 41.20}, {48.57, 41.84}, {48.66, 41.79}, {49.46, 40.80}, {50.18, 40.50}, {50.37, 40.28}, {49.92, 40.32}, {49.55, 40.19}, {49.32, 39.61}, {49.36, 39.35}, {49.17, 39.03}, {49.01, 39.13}, {48.85, 38.84}, {48.87, 38.44}}}, + {"BH", [][2]float64{{50.61, 25.88}, {50.57, 25.81}, {50.47, 25.97}, {50.47, 26.23}, {50.59, 26.24}, {50.61, 25.88}}}, + {"GE", [][2]float64{{43.44, 41.11}, {42.75, 41.58}, {42.47, 41.44}, {41.51, 41.52}, {41.76, 41.97}, {41.49, 42.66}, {39.98, 43.42}, {40.15, 43.57}, {40.65, 43.53}, {41.58, 43.22}, {42.76, 43.17}, {43.78, 42.75}, {43.83, 42.57}, {44.51, 42.75}, {44.77, 42.62}, {44.87, 42.76}, {45.71, 42.50}, {45.64, 42.21}, {46.43, 41.89}, {46.18, 41.66}, {46.67, 41.29}, {46.53, 41.09}, {45.28, 41.45}, {44.84, 41.21}, {43.44, 41.11}}}, + {"IQ", [][2]float64{{42.36, 37.11}, {42.77, 37.37}, {43.68, 37.23}, {44.11, 37.30}, {44.28, 36.98}, {44.73, 37.17}, {45.36, 36.02}, {45.78, 35.82}, {46.27, 35.77}, {46.00, 35.61}, {46.13, 35.13}, {45.68, 34.80}, {45.64, 34.57}, {45.50, 34.58}, {45.44, 34.42}, {45.54, 34.22}, {45.40, 33.97}, {46.02, 33.42}, {46.15, 33.23}, {46.11, 32.96}, {47.37, 32.42}, {47.83, 31.79}, {47.68, 31.00}, {48.01, 30.99}, {48.01, 30.47}, {48.33, 30.29}, {48.55, 29.96}, {47.67, 30.10}, {47.22, 30.04}, {46.53, 29.10}, {44.72, 29.19}, {42.07, 31.08}, {40.37, 31.94}, {39.15, 32.12}, {39.29, 32.24}, {39.25, 32.35}, {39.04, 32.31}, {38.77, 33.37}, {40.99, 34.43}, {41.19, 34.77}, {41.35, 35.64}, {41.30, 36.38}, {41.79, 36.60}, {42.36, 37.11}}}, + {"KW", [][2]float64{{48.28, 29.62}, {48.08, 29.80}, {48.18, 29.98}, {48.35, 29.78}, {48.28, 29.62}}}, + {"KW", [][2]float64{{48.44, 28.54}, {47.67, 28.53}, {47.43, 28.99}, {46.53, 29.10}, {47.15, 30.00}, {47.75, 30.08}, {47.98, 29.98}, {48.14, 29.57}, {47.97, 29.62}, {47.72, 29.39}, {48.05, 29.36}, {48.44, 28.54}}}, + {"KZ", [][2]float64{{70.95, 42.25}, {69.15, 41.43}, {68.58, 40.88}, {68.57, 40.62}, {68.42, 40.62}, {68.05, 40.81}, {68.11, 41.03}, {67.94, 41.20}, {66.71, 41.18}, {66.50, 41.99}, {66.01, 42.00}, {66.10, 42.99}, {65.80, 42.88}, {65.50, 43.31}, {64.91, 43.71}, {64.44, 43.55}, {63.21, 43.63}, {61.99, 43.49}, {61.01, 44.39}, {58.56, 45.56}, {55.98, 44.99}, {55.98, 41.32}, {55.43, 41.30}, {54.85, 41.97}, {54.12, 42.34}, {53.06, 42.15}, {52.49, 41.78}, {52.60, 42.76}, {51.90, 42.87}, {51.62, 43.16}, {51.30, 43.17}, {51.30, 43.48}, {50.83, 44.19}, {50.33, 44.33}, {50.25, 44.46}, {50.41, 44.62}, {51.54, 44.53}, {51.01, 44.92}, {51.42, 45.36}, {53.20, 45.33}, {52.77, 45.57}, {53.14, 46.19}, {53.06, 46.48}, {53.17, 46.67}, {53.07, 46.86}, {52.48, 46.99}, {52.14, 46.83}, {51.18, 47.11}, {49.89, 46.60}, {49.35, 46.52}, {49.23, 46.34}, {48.61, 46.57}, {48.52, 46.73}, {48.96, 46.77}, {48.17, 47.71}, {47.29, 47.74}, {47.09, 47.95}, {47.06, 48.23}, {46.66, 48.41}, {46.70, 48.81}, {47.03, 49.15}, {46.80, 49.37}, {46.82, 49.50}, {47.50, 50.40}, {47.71, 50.38}, {48.33, 49.86}, {48.76, 49.93}, {48.84, 50.01}, {48.63, 50.61}, {49.32, 50.85}, {49.50, 51.08}, {50.31, 51.32}, {50.79, 51.73}, {51.16, 51.65}, {51.34, 51.48}, {52.22, 51.71}, {52.57, 51.48}, {53.34, 51.48}, {54.14, 51.04}, {54.56, 50.54}, {54.65, 50.66}, {54.55, 50.95}, {54.64, 51.01}, {55.69, 50.58}, {56.49, 51.02}, {57.01, 51.07}, {57.44, 50.89}, {57.84, 51.09}, {58.36, 51.06}, {58.88, 50.69}, {59.45, 50.62}, {59.52, 50.49}, {59.81, 50.58}, {60.06, 50.85}, {60.42, 50.68}, {60.94, 50.70}, {61.39, 50.86}, {61.55, 51.32}, {60.46, 51.65}, {60.03, 51.93}, {60.99, 52.34}, {60.77, 52.68}, {61.05, 52.97}, {62.08, 53.01}, {61.66, 53.23}, {61.20, 53.29}, {61.23, 53.45}, {61.53, 53.52}, {60.98, 53.62}, {61.23, 54.02}, {61.93, 53.95}, {64.46, 54.38}, {65.09, 54.34}, {65.48, 54.62}, {68.16, 54.98}, {68.21, 55.16}, {68.98, 55.39}, {70.18, 55.16}, {70.74, 55.31}, {71.19, 54.60}, {71.09, 54.21}, {72.00, 54.21}, {72.19, 54.33}, {72.45, 53.94}, {72.62, 54.13}, {73.23, 53.96}, {73.67, 54.06}, {73.68, 53.93}, {73.31, 53.71}, {73.41, 53.45}, {73.86, 53.62}, {74.35, 53.49}, {74.45, 53.65}, {75.22, 53.89}, {75.44, 54.09}, {76.84, 54.44}, {76.65, 54.15}, {76.42, 54.15}, {76.48, 54.02}, {77.86, 53.27}, {79.99, 50.77}, {80.42, 50.95}, {80.45, 51.18}, {80.74, 51.29}, {81.13, 51.19}, {81.07, 50.97}, {81.39, 50.96}, {81.47, 50.74}, {82.49, 50.73}, {83.36, 50.99}, {83.95, 50.77}, {84.32, 50.24}, {84.99, 50.06}, {85.23, 49.62}, {86.18, 49.50}, {86.68, 49.78}, {86.63, 49.56}, {87.32, 49.09}, {86.81, 49.05}, {86.55, 48.53}, {85.75, 48.39}, {85.53, 47.92}, {85.66, 47.25}, {85.48, 47.06}, {84.79, 46.83}, {84.67, 46.97}, {84.02, 46.97}, {83.03, 47.19}, {82.32, 45.59}, {82.61, 45.42}, {82.52, 45.13}, {81.94, 45.16}, {81.69, 45.35}, {79.87, 44.88}, {80.48, 44.71}, {80.36, 44.55}, {80.36, 44.10}, {80.79, 43.16}, {80.39, 43.04}, {80.54, 42.87}, {80.20, 42.73}, {80.21, 42.19}, {79.92, 42.41}, {79.43, 42.48}, {79.13, 42.78}, {76.99, 42.97}, {75.37, 42.84}, {74.21, 43.24}, {73.56, 43.00}, {73.42, 42.59}, {73.49, 42.41}, {71.76, 42.82}, {71.26, 42.73}, {70.89, 42.34}, {70.95, 42.25}}}, + {"OM", [][2]float64{{53.09, 16.65}, {51.98, 19.00}, {54.98, 20.00}, {55.64, 22.00}, {55.19, 22.70}, {55.20, 23.03}, {55.51, 23.72}, {55.47, 23.94}, {55.99, 24.06}, {55.93, 24.22}, {55.76, 24.24}, {55.80, 24.87}, {56.00, 24.95}, {56.06, 24.74}, {56.39, 24.98}, {56.64, 24.47}, {57.12, 23.98}, {58.77, 23.52}, {59.43, 22.66}, {59.82, 22.51}, {59.80, 22.22}, {58.47, 20.41}, {58.21, 20.42}, {58.17, 20.59}, {57.86, 20.24}, {57.71, 19.68}, {57.81, 19.02}, {56.83, 18.75}, {56.38, 17.99}, {55.48, 17.84}, {55.26, 17.59}, {55.28, 17.32}, {55.06, 17.04}, {54.07, 17.01}, {53.09, 16.65}}}, + {"OM", [][2]float64{{56.30, 25.65}, {56.14, 25.69}, {56.17, 26.05}, {56.08, 26.06}, {56.38, 26.36}, {56.30, 25.65}}}, + {"PK", [][2]float64{{76.77, 35.66}, {77.05, 35.11}, {76.59, 34.74}, {75.71, 34.50}, {74.30, 34.77}, {73.96, 34.65}, {73.79, 34.38}, {73.97, 34.24}, {73.90, 34.08}, {74.25, 33.95}, {73.98, 33.72}, {74.15, 33.51}, {74.00, 33.19}, {74.30, 32.99}, {74.35, 32.77}, {74.66, 32.76}, {74.69, 32.49}, {75.33, 32.28}, {74.56, 31.82}, {74.52, 31.19}, {74.63, 31.03}, {73.90, 30.44}, {73.93, 30.22}, {73.81, 30.09}, {73.38, 29.93}, {72.90, 29.03}, {72.34, 28.75}, {71.87, 27.96}, {70.80, 27.71}, {70.40, 28.03}, {69.54, 27.12}, {69.51, 26.74}, {70.15, 26.51}, {70.10, 25.91}, {70.26, 25.71}, {70.65, 25.67}, {70.65, 25.42}, {71.05, 24.69}, {71.04, 24.40}, {70.72, 24.24}, {70.49, 24.41}, {69.81, 24.17}, {68.78, 24.31}, {68.72, 23.96}, {68.28, 23.93}, {68.12, 23.75}, {67.50, 23.94}, {67.31, 24.17}, {67.17, 24.76}, {66.70, 24.86}, {66.70, 25.23}, {66.32, 25.60}, {66.13, 25.49}, {66.47, 25.45}, {64.78, 25.31}, {64.66, 25.18}, {64.06, 25.40}, {63.56, 25.35}, {63.49, 25.21}, {61.57, 25.19}, {61.84, 26.23}, {62.24, 26.36}, {62.44, 26.56}, {63.16, 26.65}, {63.30, 27.15}, {62.76, 27.25}, {62.76, 28.24}, {61.89, 28.55}, {60.84, 29.86}, {62.48, 29.41}, {63.57, 29.50}, {64.10, 29.39}, {64.39, 29.54}, {65.10, 29.56}, {66.23, 29.87}, {66.35, 30.80}, {66.83, 31.26}, {67.45, 31.23}, {67.74, 31.34}, {67.58, 31.51}, {68.16, 31.80}, {68.60, 31.80}, {68.87, 31.63}, {69.28, 31.94}, {69.24, 32.43}, {69.50, 33.02}, {70.26, 33.29}, {69.89, 34.01}, {70.65, 33.95}, {71.05, 34.05}, {71.10, 34.37}, {70.97, 34.53}, {71.62, 35.18}, {71.43, 35.83}, {71.19, 36.04}, {71.62, 36.44}, {72.16, 36.70}, {73.12, 36.87}, {74.04, 36.83}, {74.60, 37.04}, {75.15, 36.97}, {75.35, 36.91}, {75.42, 36.74}, {75.88, 36.60}, {75.91, 36.05}, {76.15, 35.83}, {76.55, 35.89}, {76.77, 35.66}}}, + {"QA", [][2]float64{{51.27, 24.61}, {50.97, 24.57}, {50.86, 24.68}, {50.75, 25.40}, {51.00, 25.98}, {51.26, 26.15}, {51.54, 25.90}, {51.49, 25.52}, {51.61, 25.05}, {51.43, 24.67}, {51.27, 24.61}}}, + {"RU", [][2]float64{{130.69, 42.30}, {130.42, 42.73}, {131.07, 42.90}, {131.26, 43.38}, {131.17, 43.70}, {131.26, 44.07}, {130.98, 44.84}, {131.45, 44.98}, {131.85, 45.33}, {132.94, 45.03}, {133.11, 45.13}, {133.19, 45.49}, {133.44, 45.60}, {133.51, 45.88}, {133.86, 46.25}, {133.87, 46.50}, {134.20, 47.13}, {134.17, 47.30}, {134.75, 47.72}, {134.57, 48.02}, {134.67, 48.25}, {134.29, 48.37}, {133.47, 48.10}, {133.14, 48.11}, {132.71, 47.95}, {132.48, 47.71}, {130.96, 47.71}, {130.73, 48.02}, {130.80, 48.34}, {130.55, 48.60}, {130.55, 48.86}, {130.20, 48.89}, {129.50, 49.39}, {129.07, 49.37}, {128.70, 49.60}, {128.00, 49.57}, {127.55, 49.80}, {127.59, 50.21}, {127.34, 50.35}, {127.31, 50.71}, {126.92, 51.10}, {126.34, 52.36}, {126.02, 52.61}, {126.05, 52.74}, {125.65, 53.04}, {125.08, 53.20}, {124.81, 53.13}, {123.61, 53.55}, {120.99, 53.28}, {120.09, 52.79}, {120.07, 52.63}, {120.66, 52.57}, {120.68, 51.97}, {120.07, 51.60}, {119.16, 50.41}, {119.35, 50.28}, {119.26, 50.07}, {118.45, 49.84}, {117.87, 49.51}, {116.22, 50.01}, {115.43, 49.90}, {114.74, 50.23}, {114.30, 50.27}, {113.57, 50.01}, {112.81, 49.52}, {111.34, 49.36}, {110.71, 49.14}, {108.61, 49.32}, {107.97, 49.65}, {107.92, 49.95}, {107.23, 49.99}, {106.71, 50.31}, {105.38, 50.47}, {104.08, 50.15}, {103.30, 50.20}, {102.29, 50.59}, {102.11, 51.35}, {99.92, 51.76}, {98.89, 52.12}, {98.64, 51.80}, {98.04, 51.45}, {97.84, 51.05}, {98.03, 50.64}, {98.28, 50.53}, {98.25, 50.30}, {98.00, 50.01}, {97.36, 49.74}, {96.07, 50.00}, {95.52, 49.91}, {94.61, 50.02}, {94.35, 50.22}, {94.25, 50.56}, {93.10, 50.60}, {92.94, 50.78}, {92.63, 50.69}, {92.35, 50.86}, {92.19, 50.70}, {91.80, 50.69}, {91.42, 50.47}, {90.05, 50.09}, {89.64, 49.90}, {89.65, 49.72}, {89.11, 49.50}, {88.19, 49.45}, {87.99, 49.19}, {87.42, 49.08}, {86.63, 49.56}, {86.68, 49.78}, {86.18, 49.50}, {85.23, 49.62}, {84.99, 50.06}, {84.32, 50.24}, {83.95, 50.77}, {83.36, 50.99}, {82.49, 50.73}, {81.47, 50.74}, {81.39, 50.96}, {81.07, 50.97}, {81.13, 51.19}, {80.74, 51.29}, {80.45, 51.18}, {80.42, 50.95}, {79.99, 50.77}, {77.86, 53.27}, {76.48, 54.02}, {76.42, 54.15}, {76.65, 54.15}, {76.84, 54.44}, {75.44, 54.09}, {75.22, 53.89}, {74.45, 53.65}, {74.35, 53.49}, {73.86, 53.62}, {73.41, 53.45}, {73.31, 53.71}, {73.68, 53.93}, {73.67, 54.06}, {73.23, 53.96}, {72.62, 54.13}, {72.45, 53.94}, {72.19, 54.33}, {72.00, 54.21}, {71.09, 54.21}, {71.19, 54.60}, {70.74, 55.31}, {70.18, 55.16}, {68.98, 55.39}, {68.21, 55.16}, {68.16, 54.98}, {65.48, 54.62}, {65.09, 54.34}, {64.46, 54.38}, {61.93, 53.95}, {61.23, 54.02}, {60.98, 53.62}, {61.53, 53.52}, {61.23, 53.45}, {61.20, 53.29}, {61.66, 53.23}, {62.08, 53.01}, {61.05, 52.97}, {60.77, 52.68}, {60.99, 52.34}, {60.03, 51.93}, {60.46, 51.65}, {61.55, 51.32}, {61.39, 50.86}, {60.94, 50.70}, {60.42, 50.68}, {60.06, 50.85}, {59.81, 50.58}, {59.52, 50.49}, {59.45, 50.62}, {58.88, 50.69}, {58.36, 51.06}, {57.84, 51.09}, {57.44, 50.89}, {57.01, 51.07}, {56.49, 51.02}, {55.69, 50.58}, {54.64, 51.01}, {54.55, 50.95}, {54.65, 50.66}, {54.56, 50.54}, {54.14, 51.04}, {53.34, 51.48}, {52.57, 51.48}, {52.22, 51.71}, {51.34, 51.48}, {51.16, 51.65}, {50.79, 51.73}, {50.31, 51.32}, {49.50, 51.08}, {49.32, 50.85}, {48.63, 50.61}, {48.84, 50.01}, {48.76, 49.93}, {48.33, 49.86}, {47.71, 50.38}, {47.43, 50.36}, {47.25, 50.00}, {46.89, 49.70}, {46.80, 49.37}, {47.03, 49.15}, {46.70, 48.81}, {46.66, 48.41}, {47.06, 48.23}, {47.09, 47.95}, {47.29, 47.74}, {48.17, 47.71}, {48.96, 46.77}, {48.56, 46.76}, {48.54, 46.61}, {49.25, 46.29}, {48.68, 46.09}, {48.73, 45.90}, {48.49, 45.93}, {47.63, 45.58}, {47.46, 45.68}, {47.51, 45.49}, {47.08, 44.82}, {47.00, 44.88}, {46.72, 44.56}, {46.75, 44.42}, {47.31, 44.10}, {47.46, 43.56}, {47.65, 43.88}, {47.46, 43.04}, {48.57, 41.84}, {47.86, 41.21}, {47.52, 41.23}, {47.26, 41.32}, {46.75, 41.81}, {45.64, 42.21}, {45.66, 42.52}, {44.87, 42.76}, {44.77, 42.62}, {44.51, 42.75}, {43.83, 42.57}, {43.78, 42.75}, {42.76, 43.17}, {41.58, 43.22}, {40.65, 43.53}, {40.15, 43.57}, {39.98, 43.42}, {38.72, 44.29}, {38.18, 44.42}, {37.85, 44.70}, {37.50, 44.70}, {37.20, 44.97}, {36.65, 45.13}, {36.94, 45.29}, {36.79, 45.41}, {37.21, 45.27}, {37.65, 45.38}, {37.61, 45.56}, {37.93, 46.00}, {38.08, 45.93}, {38.18, 46.09}, {38.49, 46.09}, {37.91, 46.41}, {37.77, 46.64}, {38.50, 46.66}, {38.44, 46.81}, {39.27, 47.04}, {39.20, 47.27}, {38.67, 47.14}, {38.55, 47.15}, {38.76, 47.26}, {38.58, 47.24}, {38.21, 47.09}, {38.20, 47.32}, {38.29, 47.56}, {38.82, 47.84}, {39.78, 47.89}, {39.96, 48.27}, {39.85, 48.30}, {39.84, 48.54}, {39.64, 48.59}, {39.79, 48.81}, {40.00, 48.82}, {39.69, 49.01}, {40.11, 49.25}, {40.08, 49.58}, {39.78, 49.57}, {39.17, 49.86}, {38.92, 49.82}, {38.26, 50.05}, {38.05, 49.92}, {37.42, 50.41}, {36.62, 50.21}, {36.12, 50.41}, {35.59, 50.37}, {35.41, 50.54}, {35.31, 51.04}, {35.06, 51.20}, {34.21, 51.26}, {34.12, 51.68}, {34.40, 51.78}, {33.74, 52.34}, {32.44, 52.31}, {32.12, 52.05}, {31.76, 52.10}, {31.58, 52.31}, {31.56, 52.76}, {31.26, 53.02}, {31.42, 53.20}, {32.14, 53.09}, {32.71, 53.42}, {32.47, 53.55}, {32.45, 53.69}, {31.75, 53.81}, {31.83, 54.03}, {31.40, 54.20}, {31.07, 54.49}, {31.15, 54.63}, {30.80, 54.78}, {30.98, 55.05}, {30.81, 55.31}, {30.91, 55.57}, {30.23, 55.85}, {29.48, 55.68}, {29.28, 55.97}, {28.28, 56.06}, {28.15, 56.14}, {28.17, 56.39}, {27.88, 56.82}, {27.64, 56.85}, {27.83, 57.29}, {27.35, 57.55}, {27.54, 57.80}, {27.78, 57.87}, {27.50, 58.22}, {27.43, 58.79}, {27.90, 59.28}, {28.15, 59.37}, {28.01, 59.48}, {28.06, 59.78}, {28.33, 59.69}, {28.52, 59.85}, {28.95, 59.83}, {29.15, 60.00}, {30.12, 59.87}, {30.17, 59.96}, {29.72, 60.20}, {29.07, 60.19}, {28.64, 60.38}, {28.49, 60.54}, {28.62, 60.49}, {28.65, 60.61}, {28.51, 60.68}, {27.80, 60.54}, {31.19, 62.48}, {31.54, 62.92}, {31.18, 63.21}, {29.99, 63.74}, {30.53, 64.08}, {30.49, 64.24}, {29.99, 64.52}, {30.11, 64.73}, {29.60, 64.97}, {29.83, 65.15}, {29.61, 65.25}, {29.82, 65.57}, {29.72, 65.62}, {30.10, 65.68}, {30.09, 65.79}, {29.07, 66.89}, {29.99, 67.67}, {29.34, 68.06}, {28.69, 68.19}, {28.47, 68.49}, {28.77, 68.84}, {28.41, 68.90}, {29.12, 69.05}, {29.39, 69.30}, {29.99, 69.39}, {30.16, 69.63}, {30.86, 69.54}, {30.87, 69.78}, {31.55, 69.70}, {32.00, 69.81}, {31.98, 69.95}, {33.01, 69.72}, {32.92, 69.60}, {32.18, 69.67}, {32.09, 69.63}, {32.38, 69.48}, {33.00, 69.47}, {32.98, 69.37}, {33.45, 69.43}, {33.33, 69.15}, {33.14, 69.07}, {33.68, 69.31}, {35.86, 69.19}, {37.73, 68.69}, {38.43, 68.36}, {39.57, 68.07}, {39.82, 68.06}, {39.81, 68.15}, {40.38, 67.83}, {40.97, 67.71}, {41.13, 67.27}, {41.36, 67.21}, {41.19, 66.83}, {40.10, 66.30}, {38.65, 66.07}, {35.51, 66.40}, {34.82, 66.61}, {34.48, 66.55}, {34.45, 66.65}, {33.15, 66.84}, {32.85, 67.02}, {32.93, 67.09}, {31.90, 67.16}, {32.50, 67.00}, {32.46, 66.92}, {32.86, 66.72}, {33.18, 66.68}, {33.22, 66.53}, {33.66, 66.44}, {33.36, 66.33}, {34.11, 66.23}, {34.69, 65.95}, {34.78, 65.77}, {34.41, 65.40}, {34.80, 64.99}, {34.95, 64.76}, {34.87, 64.56}, {35.04, 64.44}, {35.65, 64.38}, {36.36, 64.00}, {37.44, 63.81}, {37.97, 63.95}, {38.06, 64.09}, {37.95, 64.32}, {37.18, 64.41}, {36.58, 64.79}, {36.53, 64.94}, {36.79, 64.99}, {36.88, 65.17}, {39.76, 64.58}, {40.06, 64.77}, {40.44, 64.78}, {39.80, 65.35}, {39.82, 65.60}, {40.69, 65.96}, {41.48, 66.12}, {42.21, 66.52}, {43.23, 66.42}, {43.65, 66.25}, {43.54, 66.12}, {44.10, 66.01}, {44.10, 66.24}, {44.49, 66.67}, {44.43, 66.94}, {44.29, 67.10}, {43.78, 67.25}, {44.23, 68.00}, {44.20, 68.25}, {43.33, 68.67}, {45.89, 68.48}, {46.68, 67.97}, {46.69, 67.85}, {45.53, 67.76}, {44.90, 67.41}, {45.56, 67.19}, {45.89, 66.89}, {46.49, 66.80}, {47.66, 66.98}, {47.87, 67.58}, {48.83, 67.68}, {48.75, 67.90}, {49.16, 67.87}, {50.70, 68.32}, {51.99, 68.54}, {52.40, 68.35}, {52.72, 68.48}, {52.34, 68.61}, {53.80, 69.00}, {54.49, 68.99}, {53.80, 68.91}, {53.97, 68.84}, {53.76, 68.63}, {53.93, 68.44}, {53.26, 68.27}, {54.86, 68.20}, {54.92, 68.37}, {55.42, 68.57}, {56.04, 68.65}, {57.13, 68.55}, {58.17, 68.89}, {59.06, 69.01}, {59.37, 68.74}, {59.11, 68.62}, {59.10, 68.44}, {59.73, 68.35}, {59.92, 68.47}, {59.90, 68.71}, {60.49, 68.73}, {60.93, 68.99}, {60.17, 69.59}, {60.91, 69.85}, {64.19, 69.53}, {64.93, 69.33}, {64.90, 69.25}, {67.00, 68.87}, {67.73, 68.51}, {68.50, 68.35}, {69.14, 68.95}, {68.54, 68.97}, {68.12, 69.24}, {68.01, 69.48}, {67.62, 69.58}, {67.06, 69.69}, {66.90, 69.55}, {66.80, 69.74}, {66.93, 70.01}, {67.24, 70.11}, {67.15, 70.22}, {67.28, 70.74}, {66.70, 70.82}, {66.85, 71.06}, {66.64, 71.08}, {66.92, 71.28}, {68.27, 71.68}, {69.39, 72.96}, {71.50, 72.91}, {72.81, 72.69}, {72.57, 72.01}, {71.87, 71.46}, {72.58, 71.15}, {72.70, 70.96}, {72.70, 70.46}, {72.47, 70.27}, {72.60, 69.79}, {72.58, 68.97}, {73.59, 68.48}, {73.14, 68.18}, {73.07, 67.77}, {72.59, 67.59}, {71.85, 67.01}, {71.37, 66.96}, {71.54, 66.68}, {70.72, 66.52}, {70.38, 66.60}, {70.69, 66.75}, {69.01, 66.79}, {69.19, 66.58}, {69.98, 66.40}, {72.07, 66.25}, {72.32, 66.33}, {72.42, 66.56}, {73.79, 67.00}, {74.07, 67.41}, {74.77, 67.77}, {74.74, 68.07}, {74.39, 68.42}, {74.58, 68.75}, {75.12, 68.86}, {76.46, 68.98}, {77.24, 68.47}, {77.17, 67.78}, {77.77, 67.57}, {78.92, 67.59}, {77.59, 67.75}, {77.54, 68.01}, {77.66, 68.19}, {78.00, 68.26}, {77.65, 68.90}, {76.00, 69.24}, {74.81, 69.09}, {73.78, 69.20}, {73.89, 69.42}, {73.58, 69.80}, {73.83, 70.18}, {74.34, 70.58}, {73.58, 71.22}, {73.09, 71.44}, {73.67, 71.85}, {74.99, 72.14}, {75.06, 72.55}, {74.79, 72.81}, {75.37, 72.80}, {75.60, 72.58}, {75.74, 72.30}, {75.27, 71.96}, {75.25, 71.81}, {75.50, 71.65}, {75.28, 71.43}, {75.73, 71.27}, {77.59, 71.17}, {78.32, 70.93}, {79.02, 70.95}, {78.49, 71.03}, {78.21, 71.27}, {76.43, 71.55}, {76.03, 71.91}, {76.87, 72.03}, {77.55, 71.84}, {78.19, 71.91}, {78.02, 72.09}, {77.44, 72.16}, {78.48, 72.39}, {79.42, 72.38}, {80.76, 72.09}, {81.66, 71.72}, {83.11, 71.72}, {83.23, 71.67}, {82.98, 71.45}, {82.32, 71.26}, {82.24, 71.00}, {82.34, 70.81}, {82.16, 70.60}, {82.22, 70.40}, {82.59, 70.89}, {83.01, 70.90}, {83.03, 70.58}, {82.68, 70.22}, {83.08, 70.09}, {83.07, 70.28}, {83.50, 70.35}, {83.74, 70.55}, {83.15, 71.10}, {83.55, 71.54}, {83.53, 71.68}, {83.20, 71.87}, {82.65, 71.93}, {82.09, 72.27}, {80.83, 72.49}, {80.66, 72.71}, {80.84, 72.95}, {80.42, 73.23}, {80.58, 73.57}, {85.20, 73.72}, {86.89, 73.89}, {87.03, 73.82}, {85.79, 73.44}, {85.82, 73.33}, {86.68, 73.11}, {85.97, 73.35}, {85.94, 73.46}, {87.12, 73.62}, {87.57, 73.81}, {87.21, 73.88}, {86.57, 74.24}, {86.00, 74.32}, {86.40, 74.45}, {87.23, 74.36}, {85.79, 74.65}, {86.20, 74.82}, {86.86, 74.72}, {87.42, 74.94}, {87.47, 75.01}, {86.94, 75.07}, {87.01, 75.17}, {87.67, 75.13}, {90.18, 75.59}, {94.08, 75.91}, {92.89, 75.91}, {92.97, 76.08}, {93.26, 76.10}, {95.58, 76.14}, {96.08, 76.08}, {95.65, 75.89}, {96.51, 76.01}, {96.60, 75.99}, {96.50, 75.89}, {98.66, 76.24}, {99.77, 76.03}, {99.54, 75.80}, {99.85, 75.93}, {99.83, 76.14}, {98.87, 76.51}, {101.60, 76.44}, {100.93, 76.56}, {101.10, 76.70}, {100.92, 76.82}, {100.99, 76.99}, {102.61, 77.51}, {104.01, 77.73}, {106.06, 77.39}, {104.20, 77.10}, {106.94, 77.03}, {107.43, 76.93}, {106.64, 76.57}, {106.38, 76.59}, {106.41, 76.51}, {107.72, 76.52}, {108.18, 76.74}, {111.11, 76.72}, {111.94, 76.55}, {112.09, 76.48}, {111.94, 76.38}, {112.62, 76.38}, {112.80, 76.13}, {112.66, 76.05}, {113.27, 76.25}, {113.56, 75.89}, {113.86, 75.92}, {113.57, 75.57}, {112.47, 75.84}, {112.96, 75.57}, {113.24, 75.61}, {113.73, 75.45}, {113.61, 75.29}, {112.92, 75.02}, {109.84, 74.32}, {109.91, 74.26}, {109.81, 74.17}, {108.20, 73.69}, {107.27, 73.62}, {106.68, 73.33}, {106.19, 73.31}, {105.14, 72.78}, {105.71, 72.84}, {106.48, 73.14}, {107.75, 73.17}, {110.77, 73.69}, {110.87, 73.73}, {110.72, 73.78}, {109.71, 73.74}, {109.87, 73.93}, {110.26, 74.02}, {111.06, 73.94}, {111.13, 74.05}, {111.55, 74.03}, {111.23, 73.97}, {111.40, 73.83}, {112.15, 73.71}, {112.80, 73.75}, {112.94, 73.84}, {112.84, 73.96}, {113.03, 73.91}, {113.42, 73.65}, {113.16, 73.46}, {113.49, 73.35}, {113.47, 73.05}, {113.13, 72.83}, {113.31, 72.66}, {113.66, 72.63}, {113.22, 72.81}, {113.54, 73.05}, {113.56, 73.23}, {113.89, 73.35}, {113.51, 73.50}, {114.06, 73.58}, {115.34, 73.70}, {118.45, 73.59}, {118.94, 73.48}, {118.46, 73.46}, {118.43, 73.25}, {119.75, 72.98}, {122.54, 72.88}, {122.75, 72.91}, {122.53, 73.02}, {123.16, 72.95}, {123.62, 73.19}, {123.32, 73.43}, {123.42, 73.64}, {124.54, 73.75}, {125.60, 73.45}, {126.25, 73.55}, {126.29, 73.39}, {126.55, 73.33}, {127.03, 73.55}, {127.74, 73.48}, {129.10, 73.11}, {128.60, 72.90}, {129.02, 72.87}, {129.25, 72.71}, {128.42, 72.54}, {129.28, 72.44}, {129.41, 72.32}, {129.28, 72.09}, {128.93, 72.08}, {127.73, 72.41}, {128.91, 71.76}, {129.21, 71.92}, {129.46, 71.74}, {128.84, 71.66}, {129.13, 71.59}, {129.76, 71.12}, {130.54, 70.89}, {130.76, 70.96}, {131.02, 70.75}, {131.56, 70.90}, {132.04, 71.24}, {132.23, 71.64}, {132.65, 71.93}, {133.13, 71.61}, {133.69, 71.43}, {134.70, 71.39}, {136.09, 71.62}, {137.94, 71.13}, {137.84, 71.23}, {138.31, 71.33}, {137.92, 71.38}, {138.23, 71.60}, {138.78, 71.63}, {139.21, 71.44}, {139.98, 71.49}, {139.70, 71.70}, {139.72, 71.88}, {139.36, 71.95}, {140.19, 72.19}, {139.18, 72.16}, {139.14, 72.33}, {139.60, 72.50}, {141.08, 72.59}, {140.65, 72.84}, {140.81, 72.89}, {146.25, 72.44}, {146.23, 72.35}, {144.78, 72.38}, {144.17, 72.26}, {144.47, 72.17}, {146.83, 72.30}, {146.11, 71.94}, {146.01, 71.95}, {146.23, 72.14}, {145.76, 72.23}, {145.66, 72.07}, {145.76, 71.94}, {145.06, 71.93}, {144.99, 71.75}, {145.19, 71.70}, {146.07, 71.81}, {147.26, 72.33}, {149.50, 72.16}, {150.02, 71.90}, {149.05, 71.80}, {148.97, 71.69}, {150.60, 71.52}, {150.67, 71.46}, {150.10, 71.23}, {150.97, 71.38}, {151.58, 71.29}, {152.09, 71.02}, {151.76, 70.98}, {152.51, 70.83}, {155.90, 71.10}, {158.70, 70.94}, {159.35, 70.79}, {159.91, 70.51}, {160.01, 70.31}, {159.73, 69.87}, {159.83, 69.78}, {160.91, 69.61}, {161.04, 69.10}, {161.34, 68.91}, {160.86, 68.54}, {161.10, 68.56}, {161.57, 68.91}, {161.54, 69.38}, {162.17, 69.61}, {163.20, 69.71}, {166.82, 69.50}, {167.86, 69.73}, {168.15, 69.58}, {168.30, 69.27}, {169.31, 69.08}, {169.61, 68.79}, {170.54, 68.83}, {171.00, 69.13}, {170.58, 69.58}, {170.16, 69.63}, {170.50, 69.86}, {170.49, 70.11}, {173.28, 69.82}, {173.44, 69.95}, {175.92, 69.90}, {178.85, 69.39}, {180.00, 68.98}, {180.00, 65.07}, {178.52, 64.60}, {177.75, 64.72}, {176.88, 65.08}, {176.34, 65.05}, {177.04, 65.00}, {177.22, 64.86}, {177.07, 64.79}, {176.06, 64.96}, {174.55, 64.68}, {176.06, 64.90}, {176.35, 64.71}, {176.14, 64.59}, {177.43, 64.76}, {177.43, 64.44}, {177.69, 64.30}, {178.04, 64.22}, {178.23, 64.36}, {178.38, 64.26}, {178.45, 64.01}, {178.65, 63.97}, {178.73, 63.67}, {178.44, 63.61}, {178.71, 63.52}, {178.68, 63.40}, {178.79, 63.54}, {178.92, 63.35}, {179.39, 63.15}, {179.26, 63.01}, {179.57, 62.69}, {179.12, 62.32}, {177.29, 62.60}, {177.34, 62.78}, {177.02, 62.78}, {176.96, 62.66}, {177.16, 62.56}, {174.51, 61.82}, {173.62, 61.72}, {173.13, 61.41}, {172.86, 61.47}, {172.91, 61.31}, {172.40, 61.17}, {172.39, 61.06}, {170.61, 60.43}, {170.35, 59.97}, {169.98, 60.07}, {169.62, 60.44}, {169.23, 60.60}, {168.14, 60.57}, {167.23, 60.41}, {166.27, 59.86}, {166.14, 59.98}, {166.35, 60.48}, {165.08, 60.10}, {164.95, 59.84}, {164.53, 60.06}, {164.11, 59.90}, {164.14, 59.98}, {163.74, 60.03}, {163.36, 59.78}, {163.27, 59.30}, {162.14, 58.45}, {161.96, 58.08}, {162.39, 57.72}, {162.65, 57.95}, {163.23, 57.79}, {162.76, 57.24}, {162.80, 56.81}, {163.26, 56.69}, {163.34, 56.23}, {163.05, 56.04}, {162.84, 56.07}, {162.63, 56.23}, {163.04, 56.52}, {162.67, 56.49}, {162.49, 56.40}, {162.53, 56.26}, {162.08, 56.09}, {161.72, 55.50}, {162.11, 54.75}, {161.62, 54.52}, {160.77, 54.54}, {160.07, 54.19}, {159.84, 53.78}, {160.03, 53.13}, {159.59, 53.24}, {158.75, 52.91}, {158.47, 53.03}, {158.61, 52.87}, {158.49, 52.38}, {158.10, 51.81}, {156.75, 50.97}, {156.52, 51.38}, {156.36, 52.51}, {156.11, 52.87}, {155.56, 55.20}, {155.72, 56.07}, {155.98, 56.70}, {156.85, 57.29}, {156.98, 57.47}, {156.83, 57.78}, {157.45, 57.80}, {157.67, 58.02}, {158.28, 58.01}, {159.21, 58.52}, {159.85, 59.13}, {161.75, 60.15}, {162.07, 60.47}, {163.71, 60.92}, {163.55, 61.03}, {164.01, 61.34}, {163.80, 61.46}, {164.02, 61.71}, {164.21, 62.29}, {164.60, 62.47}, {165.21, 62.37}, {165.40, 62.49}, {164.42, 62.70}, {163.33, 62.55}, {163.02, 61.89}, {163.01, 61.79}, {163.26, 61.70}, {163.09, 61.57}, {162.86, 61.71}, {162.39, 61.66}, {160.77, 60.75}, {160.17, 60.64}, {160.38, 61.03}, {159.79, 60.96}, {159.95, 61.13}, {159.88, 61.29}, {160.25, 61.65}, {160.31, 61.89}, {159.55, 61.72}, {159.19, 61.93}, {157.08, 61.68}, {156.68, 61.48}, {156.63, 61.27}, {155.72, 60.68}, {154.97, 60.38}, {154.29, 59.83}, {154.15, 59.53}, {154.97, 59.45}, {155.17, 59.36}, {155.16, 59.19}, {154.46, 59.22}, {154.01, 59.08}, {153.36, 59.21}, {152.82, 58.93}, {152.32, 59.03}, {152.09, 58.91}, {151.33, 58.88}, {151.12, 59.08}, {151.99, 59.16}, {152.26, 59.22}, {152.17, 59.28}, {151.35, 59.56}, {150.48, 59.49}, {150.67, 59.56}, {149.42, 59.76}, {149.07, 59.63}, {149.20, 59.49}, {148.80, 59.53}, {148.74, 59.37}, {148.96, 59.37}, {148.73, 59.26}, {148.26, 59.41}, {147.51, 59.27}, {146.54, 59.46}, {146.05, 59.17}, {145.55, 59.41}, {143.19, 59.37}, {142.33, 59.15}, {141.60, 58.65}, {140.99, 58.42}, {140.68, 58.21}, {140.45, 57.81}, {139.18, 57.26}, {137.69, 56.14}, {135.54, 55.11}, {135.21, 54.84}, {135.26, 54.73}, {135.85, 54.58}, {136.80, 54.62}, {136.68, 53.93}, {136.80, 53.78}, {137.16, 53.82}, {137.26, 54.03}, {137.14, 54.18}, {137.67, 54.28}, {137.34, 54.10}, {137.83, 53.95}, {137.25, 53.55}, {137.95, 53.60}, {138.53, 53.96}, {138.57, 53.82}, {138.25, 53.52}, {138.45, 53.54}, {138.70, 53.87}, {138.66, 54.30}, {139.32, 54.19}, {139.71, 54.28}, {140.18, 54.05}, {140.69, 53.60}, {141.37, 53.29}, {141.40, 53.18}, {141.18, 53.02}, {140.84, 53.09}, {141.26, 52.84}, {141.13, 52.44}, {141.49, 52.18}, {141.37, 51.92}, {140.93, 51.62}, {140.52, 50.80}, {140.54, 50.13}, {140.62, 50.08}, {140.46, 49.91}, {140.52, 49.60}, {140.31, 49.05}, {140.38, 48.96}, {140.11, 48.42}, {139.37, 47.89}, {138.59, 47.06}, {138.34, 46.54}, {137.69, 45.82}, {135.87, 44.37}, {135.13, 43.53}, {134.01, 42.95}, {133.16, 42.70}, {132.30, 42.88}, {132.31, 43.31}, {131.87, 43.10}, {131.94, 43.30}, {131.16, 42.63}, {130.71, 42.66}, {130.83, 42.52}, {130.69, 42.30}}}, + {"SA", [][2]float64{{51.98, 19.00}, {49.04, 18.58}, {48.17, 18.16}, {47.44, 17.11}, {47.14, 16.95}, {46.98, 16.95}, {46.73, 17.27}, {45.54, 17.30}, {45.15, 17.43}, {43.92, 17.32}, {43.42, 17.52}, {43.19, 17.36}, {43.17, 16.69}, {42.80, 16.37}, {42.29, 17.43}, {41.75, 17.89}, {41.23, 18.68}, {40.76, 19.76}, {39.73, 20.39}, {39.28, 20.97}, {38.99, 21.88}, {39.06, 22.59}, {38.46, 23.71}, {37.92, 24.19}, {37.54, 24.29}, {37.18, 24.82}, {37.27, 24.96}, {37.15, 25.29}, {35.18, 28.03}, {34.62, 28.06}, {34.95, 29.35}, {36.07, 29.20}, {36.76, 29.87}, {37.47, 30.00}, {37.65, 30.33}, {37.98, 30.50}, {36.96, 31.49}, {39.15, 32.12}, {40.37, 31.94}, {42.07, 31.08}, {44.69, 29.20}, {47.43, 28.99}, {47.67, 28.53}, {48.44, 28.54}, {48.80, 27.72}, {49.24, 27.49}, {49.18, 27.44}, {49.41, 27.18}, {50.15, 26.66}, {50.01, 26.68}, {50.21, 26.31}, {50.16, 26.10}, {50.03, 26.11}, {50.08, 25.96}, {50.86, 24.68}, {50.97, 24.57}, {51.41, 24.57}, {51.31, 24.34}, {51.57, 24.29}, {51.59, 24.08}, {52.56, 22.93}, {55.10, 22.62}, {55.19, 22.70}, {55.64, 22.00}, {54.98, 20.00}, {51.98, 19.00}}}, + {"SY", [][2]float64{{35.89, 35.92}, {36.15, 35.83}, {36.38, 36.17}, {36.64, 36.23}, {36.54, 36.46}, {36.66, 36.80}, {37.44, 36.64}, {38.19, 36.90}, {38.77, 36.69}, {39.36, 36.68}, {40.71, 37.10}, {41.52, 37.09}, {42.20, 37.30}, {42.36, 37.11}, {41.79, 36.60}, {41.30, 36.38}, {41.35, 35.64}, {41.19, 34.77}, {40.99, 34.43}, {36.82, 32.32}, {36.37, 32.39}, {35.79, 32.73}, {35.89, 32.94}, {35.79, 33.33}, {36.03, 33.59}, {35.97, 33.73}, {36.37, 33.84}, {36.28, 33.93}, {36.58, 34.22}, {36.50, 34.43}, {36.33, 34.50}, {36.38, 34.66}, {35.98, 34.63}, {35.90, 35.42}, {35.76, 35.57}, {35.89, 35.92}}}, + {"TM", [][2]float64{{55.98, 41.32}, {57.02, 41.26}, {57.12, 41.35}, {56.96, 41.86}, {57.29, 42.12}, {57.81, 42.19}, {58.03, 42.49}, {58.47, 42.30}, {58.15, 42.63}, {58.59, 42.78}, {59.35, 42.32}, {59.99, 42.21}, {59.94, 41.97}, {60.20, 41.80}, {60.08, 41.76}, {60.09, 41.40}, {60.45, 41.22}, {61.50, 41.28}, {61.90, 41.09}, {62.48, 39.98}, {63.76, 39.16}, {65.61, 38.24}, {65.97, 38.24}, {66.57, 38.01}, {66.52, 37.35}, {65.77, 37.57}, {65.55, 37.25}, {64.82, 37.13}, {64.51, 36.34}, {64.01, 36.01}, {63.13, 35.85}, {63.06, 35.45}, {62.31, 35.17}, {61.98, 35.44}, {61.62, 35.43}, {61.26, 35.62}, {61.12, 36.64}, {60.34, 36.64}, {60.06, 36.96}, {59.45, 37.25}, {59.30, 37.51}, {58.82, 37.68}, {58.26, 37.67}, {57.35, 37.97}, {57.19, 38.22}, {56.44, 38.25}, {56.27, 38.08}, {55.38, 38.05}, {54.90, 37.78}, {54.70, 37.47}, {53.91, 37.34}, {53.87, 38.95}, {53.70, 39.21}, {53.34, 39.34}, {53.16, 39.26}, {53.24, 39.61}, {53.60, 39.55}, {53.47, 39.67}, {53.49, 39.91}, {52.99, 39.99}, {53.04, 39.77}, {52.80, 40.05}, {52.73, 40.40}, {52.94, 41.04}, {53.15, 40.82}, {53.62, 40.82}, {53.87, 40.65}, {54.38, 40.69}, {54.32, 40.83}, {54.69, 40.87}, {54.70, 41.07}, {54.09, 41.52}, {53.80, 42.12}, {53.16, 42.09}, {52.97, 41.98}, {52.81, 41.71}, {52.85, 41.20}, {52.49, 41.78}, {53.06, 42.15}, {54.12, 42.34}, {54.85, 41.97}, {55.43, 41.30}, {55.98, 41.32}}}, + {"TR", [][2]float64{{41.51, 41.52}, {42.47, 41.44}, {42.79, 41.56}, {43.63, 40.93}, {43.72, 40.72}, {43.57, 40.48}, {43.67, 40.13}, {44.40, 40.00}, {44.82, 39.65}, {44.59, 39.77}, {44.39, 39.42}, {44.02, 39.38}, {44.27, 38.84}, {44.30, 38.39}, {44.45, 38.33}, {44.21, 37.91}, {44.56, 37.74}, {44.57, 37.44}, {44.80, 37.27}, {44.77, 37.14}, {44.61, 37.18}, {44.28, 36.98}, {44.11, 37.30}, {43.68, 37.23}, {42.77, 37.37}, {42.36, 37.11}, {42.20, 37.30}, {41.52, 37.09}, {40.71, 37.10}, {39.36, 36.68}, {38.77, 36.69}, {38.19, 36.90}, {37.44, 36.64}, {36.66, 36.80}, {36.54, 36.46}, {36.64, 36.23}, {36.38, 36.17}, {36.13, 35.83}, {35.89, 35.92}, {35.81, 36.31}, {36.19, 36.66}, {36.05, 36.91}, {35.39, 36.58}, {34.70, 36.82}, {33.69, 36.18}, {32.79, 36.04}, {31.35, 36.80}, {30.64, 36.87}, {30.45, 36.27}, {29.69, 36.16}, {29.22, 36.32}, {28.97, 36.72}, {28.30, 36.81}, {28.02, 36.63}, {28.08, 36.75}, {27.45, 36.71}, {28.01, 36.83}, {28.24, 37.03}, {27.26, 36.98}, {27.30, 37.13}, {27.54, 37.16}, {27.07, 37.66}, {27.22, 37.73}, {27.23, 37.98}, {26.29, 38.28}, {26.42, 38.37}, {26.44, 38.64}, {26.67, 38.34}, {27.14, 38.45}, {26.91, 38.48}, {26.76, 38.71}, {27.01, 38.89}, {26.81, 38.96}, {26.85, 39.12}, {26.68, 39.29}, {26.90, 39.55}, {26.11, 39.47}, {26.18, 39.99}, {26.74, 40.40}, {27.28, 40.46}, {27.73, 40.33}, {27.85, 40.38}, {27.73, 40.48}, {27.87, 40.51}, {27.99, 40.49}, {27.96, 40.37}, {29.01, 40.39}, {28.79, 40.53}, {28.96, 40.63}, {29.85, 40.76}, {29.11, 40.94}, {29.15, 41.22}, {31.25, 41.11}, {32.31, 41.73}, {33.28, 42.00}, {34.75, 41.96}, {35.01, 42.06}, {35.15, 42.03}, {35.12, 41.89}, {35.30, 41.73}, {36.05, 41.68}, {36.41, 41.27}, {36.78, 41.36}, {37.07, 41.18}, {38.38, 40.92}, {39.43, 41.11}, {40.27, 40.96}, {41.51, 41.52}}}, + {"UZ", [][2]float64{{70.95, 42.25}, {71.23, 42.16}, {70.86, 42.03}, {70.20, 41.51}, {70.69, 41.45}, {70.86, 41.22}, {71.39, 41.12}, {71.42, 41.34}, {71.59, 41.33}, {71.66, 41.54}, {71.88, 41.20}, {72.16, 41.17}, {72.19, 41.03}, {73.14, 40.81}, {72.60, 40.53}, {72.40, 40.58}, {72.36, 40.40}, {72.13, 40.44}, {71.69, 40.15}, {71.30, 40.29}, {70.60, 40.21}, {70.38, 40.44}, {70.75, 40.74}, {70.40, 41.04}, {69.71, 40.66}, {69.41, 40.80}, {69.21, 40.57}, {69.27, 40.20}, {68.63, 40.17}, {68.97, 40.09}, {68.80, 40.05}, {68.87, 39.91}, {68.64, 39.84}, {68.51, 39.56}, {67.72, 39.62}, {67.43, 39.47}, {67.36, 39.22}, {67.65, 39.13}, {67.69, 38.99}, {68.13, 38.93}, {68.09, 38.47}, {68.35, 38.21}, {67.81, 37.49}, {67.76, 37.17}, {66.52, 37.35}, {66.57, 38.01}, {65.97, 38.24}, {65.61, 38.24}, {63.76, 39.16}, {62.48, 39.98}, {61.90, 41.09}, {61.50, 41.28}, {60.45, 41.22}, {60.09, 41.40}, {60.08, 41.76}, {60.20, 41.80}, {59.94, 41.97}, {59.99, 42.21}, {59.35, 42.32}, {58.59, 42.78}, {58.15, 42.63}, {58.47, 42.30}, {58.03, 42.49}, {57.81, 42.19}, {57.29, 42.12}, {56.96, 41.86}, {57.12, 41.35}, {57.02, 41.26}, {55.98, 41.32}, {55.98, 44.99}, {58.56, 45.56}, {61.01, 44.39}, {61.99, 43.49}, {63.21, 43.63}, {64.44, 43.55}, {64.91, 43.71}, {65.50, 43.31}, {65.80, 42.88}, {66.10, 42.99}, {66.01, 42.00}, {66.50, 41.99}, {66.71, 41.18}, {67.94, 41.20}, {68.11, 41.03}, {68.05, 40.81}, {68.42, 40.62}, {68.57, 40.62}, {68.58, 40.88}, {69.15, 41.43}, {70.95, 42.25}}}, +} diff --git a/scripts/geo/build.py b/scripts/geo/build.py new file mode 100644 index 0000000..999bfb1 --- /dev/null +++ b/scripts/geo/build.py @@ -0,0 +1,149 @@ +# build.py DBIP_CITY.csv.gz DBIP_COUNTRY.csv.gz NE_COUNTRIES.geojson +# Writes internal/geo/ip.bin and internal/geo/shapes.go, what the Host +# screen's swarm map needs, from: +# DB-IP Lite, City and Country (CC BY 4.0, https://db-ip.com/db/lite.php): +# Iran's IPv4 and IPv6 ranges to a place, the world's IPv4 ranges to a +# country, and each country's middle (its rows' mean position); +# Natural Earth's 1:50m countries (public domain): Iran's border and its +# neighbours', simplified. +# Run it from the repository's root; refresh now and then, as IPs move. +import csv, gzip, io, json, math, re, struct, sys, unicodedata +from collections import defaultdict +from ipaddress import ip_address + +city_csv, country_csv, ne = sys.argv[1:4] +BOX = (40.0, 22.0, 67.0, 42.0) # lon/lat the map can show, with room around Iran + + +def plain(s): + s = re.sub(r"\s*\(.*?\)", "", s) # "Tehran (District 6)" + s = "".join(c for c in unicodedata.normalize("NFD", s) if not unicodedata.combining(c)) + return re.sub(r"\s+Province$", "", s.replace("'", "").replace("`", "")).strip() + + +def uvarint(n): + out = bytearray() + while True: + b = n & 0x7F + n >>= 7 + if n: + out.append(b | 0x80) + else: + out.append(b) + return bytes(out) + + +def svarint(n): + return uvarint((n << 1) ^ (n >> 63) if n < 0 else n << 1) + + +def text(s): + b = s.encode() + return uvarint(len(b)) + b + + +places, place_ids, sums = [], {}, defaultdict(lambda: [0.0, 0.0, 0]) +ir4, ir6 = [], [] +with gzip.open(city_csv, "rt", encoding="utf-8") as f: + for row in csv.reader(f): + start, end, _, cc, prov, city, lat, lon = row + lat, lon = float(lat), float(lon) + if cc not in ("ZZ", ""): + s = sums[cc] + s[0] += lat; s[1] += lon; s[2] += 1 + if cc != "IR": + continue + key = (plain(prov), plain(city) or plain(prov)) + if key not in place_ids: + place_ids[key] = len(places) + places.append([key, 0.0, 0.0, 0]) + p = places[place_ids[key]] + p[1] += lat; p[2] += lon; p[3] += 1 + a, b = ip_address(start), ip_address(end) + if a.version == 4: + ir4.append((int(a), int(b), place_ids[key])) + else: + ir6.append((int(a) >> 64, int(b) >> 64, place_ids[key])) + +countries = sorted(c for c, s in sums.items() if s[2]) +cid = {c: i for i, c in enumerate(countries)} +world = [] +with gzip.open(country_csv, "rt", encoding="utf-8") as f: + for start, end, cc in csv.reader(f): + a = ip_address(start) + if a.version == 4 and cc in cid: + world.append((int(a), int(ip_address(end)), cid[cc])) + + +def ranges(rs): + """Sorted, adjacent ranges of one value merged, as gap, length, value.""" + rs.sort() + merged = [] + for a, b, v in rs: + if merged and merged[-1][2] == v and merged[-1][1] + 1 >= a: + merged[-1][1] = max(merged[-1][1], b) + elif merged and a <= merged[-1][1]: + continue # overlapping /64s of different places: the first wins + else: + merged.append([a, b, v]) + out, last = bytearray(uvarint(len(merged))), -1 + for a, b, v in merged: + out += uvarint(a - last - 1) + uvarint(b - a) + uvarint(v) + last = b + return bytes(out) + + +blob = bytearray(b"IZG1") +blob += uvarint(len(places)) +for (prov, city), lat, lon, n in places: + blob += svarint(round(lat / n * 100)) + svarint(round(lon / n * 100)) + text(city) + text(prov) +blob += uvarint(len(countries)) +for c in countries: + s = sums[c] + blob += c.encode() + svarint(round(s[0] / s[2] * 100)) + svarint(round(s[1] / s[2] * 100)) +blob += ranges(ir4) + ranges(ir6) + ranges(world) +with open("internal/geo/ip.bin", "wb") as f: + f.write(gzip.compress(bytes(blob), 9, mtime=0)) + + +def simplify(pts, tol): + """Douglas-Peucker.""" + if len(pts) < 3: + return pts + (x1, y1), (x2, y2) = pts[0], pts[-1] + dx, dy = x2 - x1, y2 - y1 + norm = math.hypot(dx, dy) or 1e-9 + far, at = 0, 0 + for i in range(1, len(pts) - 1): + d = abs(dy * (pts[i][0] - x1) - dx * (pts[i][1] - y1)) / norm if (dx or dy) else math.hypot(pts[i][0] - x1, pts[i][1] - y1) + if d > far: + far, at = d, i + if far <= tol: + return [pts[0], pts[-1]] + return simplify(pts[: at + 1], tol)[:-1] + simplify(pts[at:], tol) + + +shapes = [] +for feat in json.load(open(ne))["features"]: + code = feat["properties"]["ISO_A2"] + g = feat["geometry"] + polys = g["coordinates"] if g["type"] == "MultiPolygon" else [g["coordinates"]] + for poly in polys: + ring = poly[0] + if not any(BOX[0] <= x <= BOX[2] and BOX[1] <= y <= BOX[3] for x, y in ring): + continue + ring = simplify(ring, 0.04 if code == "IR" else 0.08) + if len(ring) >= 4: + shapes.append((code, ring)) +shapes.sort(key=lambda s: (s[0] != "IR", s[0])) + +with open("internal/geo/shapes.go", "w") as f: + f.write("// Code generated by scripts/geo/build.py from Natural Earth (public domain). DO NOT EDIT.\n\n") + f.write("package geo\n\n// Shapes are Iran's border and its neighbours', as lon/lat rings; Iran's first.\n") + f.write("var Shapes = []Shape{\n") + for code, ring in shapes: + pts = ", ".join(f"{{{x:.2f}, {y:.2f}}}" for x, y in ring) + f.write(f'\t{{"{code}", [][2]float64{{{pts}}}}},\n') + f.write("}\n") +print(f"{len(places)} places, {len(countries)} countries, {len(ir4)}+{len(ir6)} Iranian and {len(world)} world rows, " + f"{len(shapes)} shapes", file=sys.stderr)