绑定 ESS 双轨治理,拆分超大 H5 页与 Go 引擎,抽出 membership 服务, 并将 star/fortune 重命名为 outlook(JSON 双写兼容);同时修复 /psy API 代理与首页 + 菜单层级。 Co-authored-by: Cursor <cursoragent@cursor.com>
124 lines
2.7 KiB
Go
124 lines
2.7 KiB
Go
package relation
|
|
|
|
import "fmt"
|
|
|
|
type dimScore struct {
|
|
Score int
|
|
Teaser string
|
|
}
|
|
|
|
func dimMap(v any) map[string]dimScore {
|
|
out := map[string]dimScore{}
|
|
arr, ok := v.([]map[string]any)
|
|
if !ok {
|
|
// Build() uses []map[string]any — also tolerate []any
|
|
raw, ok2 := v.([]any)
|
|
if !ok2 {
|
|
return out
|
|
}
|
|
for _, item := range raw {
|
|
m, ok := item.(map[string]any)
|
|
if !ok {
|
|
continue
|
|
}
|
|
key := str(m["key"])
|
|
out[key] = dimScore{Score: asInt(m["score"]), Teaser: str(m["teaser"])}
|
|
}
|
|
return out
|
|
}
|
|
for _, m := range arr {
|
|
key := str(m["key"])
|
|
out[key] = dimScore{Score: asInt(m["score"]), Teaser: str(m["teaser"])}
|
|
}
|
|
return out
|
|
}
|
|
|
|
func asInt(v any) int {
|
|
switch n := v.(type) {
|
|
case int:
|
|
return n
|
|
case float64:
|
|
return int(n)
|
|
default:
|
|
return 0
|
|
}
|
|
}
|
|
|
|
func dimTitle(key string) string {
|
|
switch key {
|
|
case "personality":
|
|
return "性格特点"
|
|
case "communication":
|
|
return "沟通方式"
|
|
case "relation":
|
|
return "关系模式"
|
|
case "career":
|
|
return "事业节奏"
|
|
case "emotion":
|
|
return "情绪调节"
|
|
case "lifestyle":
|
|
return "生活节奏"
|
|
default:
|
|
return key
|
|
}
|
|
}
|
|
|
|
func dimNote(key string, gap int, aName, bName string) string {
|
|
if gap > 12 {
|
|
return fmt.Sprintf("在「%s」上,%s 分值更高,适合由 %s 多给结构,%s 多给弹性。", dimTitle(key), aName, aName, bName)
|
|
}
|
|
if gap < -12 {
|
|
return fmt.Sprintf("在「%s」上,%s 分值更高,相处时可多尊重 %s 的节奏。", dimTitle(key), bName, bName)
|
|
}
|
|
return fmt.Sprintf("在「%s」上双方接近,容易形成默契,也要防止都默认对方「应该懂」。", dimTitle(key))
|
|
}
|
|
|
|
func firstTeaser(m map[string]dimScore, key string) string {
|
|
if d, ok := m[key]; ok && d.Teaser != "" {
|
|
return d.Teaser
|
|
}
|
|
return "表达方式各有节奏"
|
|
}
|
|
|
|
func harmonyIndex(dims []map[string]any) int {
|
|
if len(dims) == 0 {
|
|
return 72
|
|
}
|
|
sum := 0
|
|
for _, d := range dims {
|
|
gap := asInt(d["gap"])
|
|
sum += 100 - gap*4
|
|
}
|
|
avg := sum / len(dims)
|
|
if avg < 45 {
|
|
return 45
|
|
}
|
|
if avg > 96 {
|
|
return 96
|
|
}
|
|
return avg
|
|
}
|
|
|
|
func fitFromHarmony(score int, aLabel, bLabel string) (string, []string) {
|
|
switch {
|
|
case score >= 82:
|
|
return "默契互补型", []string{
|
|
fmt.Sprintf("%s与%s节奏接近,适合共同推进小事。", aLabel, bLabel),
|
|
"把欣赏说出口,默契会更稳。",
|
|
"每周留一次轻松同步,不必每次谈大事。",
|
|
}
|
|
case score >= 68:
|
|
return "磨合成长型", []string{
|
|
"差异可见,正好写成相处说明书。",
|
|
"冲突时先复述再提方案。",
|
|
"共同目标写清楚,减少猜忌。",
|
|
}
|
|
default:
|
|
return "反差探索型", []string{
|
|
"反差大不等于不合,关键是边界与节奏。",
|
|
"重要约定尽量具体、可检查。",
|
|
"给彼此独处充电的空间。",
|
|
}
|
|
}
|
|
}
|