Skip to content

Commit

Permalink
fix(worker): add fld river names to index
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Mar 23, 2024
1 parent d72abf8 commit 95e1ba4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
10 changes: 5 additions & 5 deletions worker/preparegspatialjp/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
}
}
24 changes: 17 additions & 7 deletions worker/preparegspatialjp/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"strings"

cms "github.com/reearth/reearth-cms-api/go"
)
Expand Down Expand Up @@ -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
Expand All @@ -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
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions worker/preparegspatialjp/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"path/filepath"
"strings"

"github.com/reearth/reearthx/log"
)

type IndexSeed struct {
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion worker/preparegspatialjp/index_citygml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 95e1ba4

Please sign in to comment.