annotate pkg/mesh/areas.go @ 5591:0011f50cf216 surveysperbottleneckid

Removed no longer used alternative api for surveys/ endpoint. As bottlenecks in the summary for SR imports are now identified by their id and no longer by the (not guarantied to be unique!) name, there is no longer the need to request survey data by the name+date tuple (which isn't reliable anyway). So the workaround was now reversed.
author Sascha Wilde <wilde@sha-bang.de>
date Wed, 06 Apr 2022 13:30:29 +0200
parents 181c2c05b12a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4570
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 // This is Free Software under GNU Affero General Public License v >= 3.0
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2 // without warranty, see README.md and license for details.
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 //
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 // SPDX-License-Identifier: AGPL-3.0-or-later
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 // License-Filename: LICENSES/AGPL-3.0.txt
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 //
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7 // Copyright (C) 2018 by via donau
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 // – Österreichische Wasserstraßen-Gesellschaft mbH
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 // Software engineering by Intevation GmbH
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 //
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 // Author(s):
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de>
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13
4827
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4768
diff changeset
14 package mesh
4570
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 import (
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 "runtime"
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 "sync"
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 "gemma.intevation.de/gemma/pkg/common"
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 )
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22
4853
181c2c05b12a More golint fixes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4827
diff changeset
23 // GenerateRandomVertices generates n random vertices.
181c2c05b12a More golint fixes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4827
diff changeset
24 // X/Y values are diced between the X/Y components of min and max.
181c2c05b12a More golint fixes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4827
diff changeset
25 // eval is called to find out the corresponding Z value.
181c2c05b12a More golint fixes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4827
diff changeset
26 // The random vertices are are transfered in chunks to
181c2c05b12a More golint fixes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4827
diff changeset
27 // the callback function.
4654
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
28 func GenerateRandomVertices(
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
29 n int,
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
30 min, max Vertex,
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
31 eval func(float64, float64) (float64, bool),
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
32 callback func([]Vertex),
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
33 ) {
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
34 var wg sync.WaitGroup
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
35
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
36 jobs := make(chan int)
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
37 out := make(chan []Vertex)
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
38 done := make(chan struct{})
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
39
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
40 cpus := runtime.NumCPU()
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
41
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
42 free := make(chan []Vertex, cpus)
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
43
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
44 for i := 0; i < cpus; i++ {
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
45 wg.Add(1)
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
46 go func() {
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
47 defer wg.Done()
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
48 xRange := common.Random(min.X, max.X)
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
49 yRange := common.Random(min.Y, max.Y)
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
50
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
51 for size := range jobs {
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
52 var vertices []Vertex
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
53 select {
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
54 case vertices = <-free:
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
55 default:
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
56 vertices = make([]Vertex, 0, 1000)
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
57 }
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
58 for len(vertices) < size {
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
59 x, y := xRange(), yRange()
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
60 if z, ok := eval(x, y); ok {
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
61 vertices = append(vertices, Vertex{X: x, Y: y, Z: z})
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
62 }
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
63 }
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
64 out <- vertices
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
65 }
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
66 }()
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
67 }
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
68
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
69 go func() {
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
70 defer close(done)
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
71 for vertices := range out {
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
72 callback(vertices)
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
73 select {
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
74 case free <- vertices[:0]:
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
75 default:
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
76 }
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
77 }
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
78 }()
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
79
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
80 for remain := n; remain > 0; {
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
81 if remain > 1000 {
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
82 jobs <- 1000
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
83 remain -= 1000
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
84 } else {
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
85 jobs <- remain
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
86 remain = 0
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
87 }
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
88 }
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
89 close(jobs)
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
90 wg.Wait()
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
91 close(out)
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
92 <-done
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
93 }