From 95e1ba44dea2520c39b454507e2691d53ccadb99 Mon Sep 17 00:00:00 2001 From: rot1024 Date: Sun, 24 Mar 2024 01:38:00 +0900 Subject: [PATCH] fix(worker): add fld river names to index --- worker/preparegspatialjp/command_test.go | 10 +++++----- worker/preparegspatialjp/feature.go | 24 ++++++++++++++++------- worker/preparegspatialjp/index.go | 4 ++++ worker/preparegspatialjp/index_citygml.go | 1 - 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/worker/preparegspatialjp/command_test.go b/worker/preparegspatialjp/command_test.go index 4f26388a9..0f1a1c32b 100644 --- a/worker/preparegspatialjp/command_test.go +++ b/worker/preparegspatialjp/command_test.go @@ -7,13 +7,13 @@ import ( "github.com/joho/godotenv" ) -func TestCommandSingle(t *testing.T) { +func TestCommand(t *testing.T) { _ = godotenv.Load("../.env") conf := Config{ CMSURL: os.Getenv("REEARTH_CMS_URL"), CMSToken: os.Getenv("REEARTH_CMS_TOKEN"), - ProjectID: "", + ProjectID: os.Getenv("REEARTH_CMS_PROJECT"), CityItemID: "", SkipCityGML: true, SkipPlateau: true, @@ -24,11 +24,11 @@ func TestCommandSingle(t *testing.T) { Clean: true, } - if conf.ProjectID == "" || conf.CityItemID == "" { - t.Skip("ProjectID or CityItemID is empty") + if conf.CMSURL == "" || conf.CMSToken == "" || conf.ProjectID == "" || conf.CityItemID == "" { + t.Skip("CMS URL, CMS Token, ProjectID, or CityItemID is empty") } - if err := CommandSingle(&conf); err != nil { + if err := Command(&conf); err != nil { t.Fatal(err) } } diff --git a/worker/preparegspatialjp/feature.go b/worker/preparegspatialjp/feature.go index 3e4e4b7be..a02d14675 100644 --- a/worker/preparegspatialjp/feature.go +++ b/worker/preparegspatialjp/feature.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "strings" cms "github.com/reearth/reearth-cms-api/go" ) @@ -112,7 +113,7 @@ func mergeDics(dics map[string]FeatureItem) (res map[string]map[string]string) { } res = map[string]map[string]string{} - for k, f := range dics { + for ft, f := range dics { dic := f.Dic if dic == "" { continue @@ -129,17 +130,26 @@ func mergeDics(dics map[string]FeatureItem) (res map[string]map[string]string) { continue } - if res[k] == nil { - res[k] = map[string]string{} + key := e.Name.String() + if key == "" { + key = e.Code.String() + } + if key == "" { + continue } - if e.Name != nil { - res[k][e.Name.String()] = e.Description + desc := e.Description + if ft == "fld" { + key = strings.TrimSuffix(key, "_l1") + key = strings.TrimSuffix(key, "_l2") + desc += "洪水浸水想定区域" } - if e.Code != nil { - res[k][e.Code.String()] = e.Description + if res[ft] == nil { + res[ft] = map[string]string{} } + + res[ft][key] = desc } } } diff --git a/worker/preparegspatialjp/index.go b/worker/preparegspatialjp/index.go index 71197620a..0040df1c5 100644 --- a/worker/preparegspatialjp/index.go +++ b/worker/preparegspatialjp/index.go @@ -5,6 +5,8 @@ import ( "fmt" "path/filepath" "strings" + + "github.com/reearth/reearthx/log" ) type IndexSeed struct { @@ -38,6 +40,8 @@ func PrepareIndex(ctx context.Context, cw *CMSWrapper, seed *IndexSeed) (err err return fmt.Errorf("目録の生成に失敗しました: %w", err) } + log.Infofc(ctx, "index generated: %s", index) + if err := cw.UpdateDataItem(ctx, &GspatialjpDataItem{ Index: index, }); err != nil { diff --git a/worker/preparegspatialjp/index_citygml.go b/worker/preparegspatialjp/index_citygml.go index b3f05663f..69418db6d 100644 --- a/worker/preparegspatialjp/index_citygml.go +++ b/worker/preparegspatialjp/index_citygml.go @@ -46,7 +46,6 @@ func generateCityGMLIndexItem(seed *IndexSeed, name string, size uint64, f fs.FS } if name, ok := citygmlDic[base]; ok { - ft = "" return &IndexItem{ Name: fmt.Sprintf("**%s**:%s", base, name), }, nil