Skip to content

Commit

Permalink
refactor(fate): update comments and adjust code formatting
Browse files Browse the repository at this point in the history
- Update Chinese comments for clarity and consistency.
- Enforce coding standards by adjusting function and variable names.
- Remove unnecessary TODO comments and correct spelling errors.
- Improve readability by formatting code blocks and inline comments.
  • Loading branch information
godcong committed Jun 27, 2024
1 parent 79858c9 commit 2ce3f81
Show file tree
Hide file tree
Showing 25 changed files with 183 additions and 171 deletions.
81 changes: 41 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,22 @@ Github上第一个开源的中文取名项目(The first chinese name create tool
1. 编写运行go代码,接口调用生成姓名

```go
//使用前请导入database的数据(测试字库已基本完善, 保险起见生成姓名后可以去一些测名网站验证下)
//加载配置(具体参数参考example/create_a_name)
// 使用前请导入database的数据(测试字库已基本完善, 保险起见生成姓名后可以去一些测名网站验证下)
// 加载配置(具体参数参考example/create_a_name)
cfg := config.Default()
//生日:
// 生日:
born := chronos.New("2020/01/23 11:31")
//姓氏:
// 姓氏:
lastName := ""
//第一参数:姓氏
//第二参数:生日
// 第一参数:姓氏
// 第二参数:生日
f := fate.NewFate(lastName, born.Solar().Time(), fate.ConfigOption(cfg))

e := f.MakeName(context.Background())
if e != nil {
t.Fatal(e)
}

```

2. 使用预编译二进制文件生成姓名
Expand All @@ -64,8 +65,8 @@ Github上第一个开源的中文取名项目(The first chinese name create tool
```

3. ~~针对没有安装Go环境的用户,使用二进制文件在运行前务必把zoneinfo.zip下载并和二进制文件放在一起(不要解压),不然会报错.~~
~~[zoneinfo文件](https://github.com/babyname/fate/blob/master/zoneinfo.zip)~~
最新编译的版本使用了Go新版编译, 已经不再需要手动下载`zoneinfo.zip`文件了.
~~[zoneinfo文件](https://github.com/babyname/fate/blob/master/zoneinfo.zip)~~
最新编译的版本使用了Go新版编译, 已经不再需要手动下载`zoneinfo.zip`文件了.

### 常见问题

Expand Down Expand Up @@ -93,11 +94,11 @@ Github上第一个开源的中文取名项目(The first chinese name create tool
```

3. 数据库配置, 替换config.json中相关部分
- MYSQL配置:
- host填写mysql数据库的地址
- user填写mysql数据库的用户名
- pwd填写mysql数据库的密码
- name填写mysql数据库的库名
- MYSQL配置:
- host填写mysql数据库的地址
- user填写mysql数据库的用户名
- pwd填写mysql数据库的密码
- name填写mysql数据库的库名

```json
"database": {
Expand All @@ -116,8 +117,8 @@ Github上第一个开源的中文取名项目(The first chinese name create tool
},
```

- SQLITE3配置:
- name填写本地sqlite的数据库名字, 放在fate同一目录下
- SQLITE3配置:
- name填写本地sqlite的数据库名字, 放在fate同一目录下

```json
"database": {
Expand Down Expand Up @@ -152,12 +153,12 @@ FATE使用了以下算法,查询字典库自动生成匹配规则的名字.
按照每种算法的准确度,使用程度也有高有低,不会一概而否,也不会偏向单独某种算法.
不会按照个人喜好做出选择.

- 周易卦象
- 大衍之数
- 三才五格
- 喜用神(平衡用神)
- 生肖用字
- 八字吉凶
- 周易卦象
- 大衍之数
- 三才五格
- 喜用神(平衡用神)
- 生肖用字
- 八字吉凶

目前Fate以六大派为基准综合计算生成名字:

Expand All @@ -170,31 +171,31 @@ FATE使用了以下算法,查询字典库自动生成匹配规则的名字.

目前使用到的一些库:

- 八字计算(用于计算生辰): <https://github.com/godcong/chronos>
- 八字计算(用于计算生辰): <https://github.com/godcong/chronos>
- 字典数据(一个爬虫工具填充字典数据库): <https://github.com/godcong/excavator>
如果谁有更好用的可以告诉我.
如果谁有更好用的可以告诉我.

### 资料查询

1. 全国及各省重名查询网址汇总

网友提供:`https://zhuanlan.zhihu.com/p/89654568`(**请谨慎访问非本站点地址**)
[本仓库地址](./docs/chinese_name_query.md)
网友提供:`https://zhuanlan.zhihu.com/p/89654568`(**请谨慎访问非本站点地址**)
[本仓库地址](./docs/chinese_name_query.md)

## 一些废话

在过去的几年中虽然Fate经过了好几个版本的改进, 但是仍然有许多不足之处.
包括生成的名字太多不容易筛选,
有些用户遇到了一些和Go相关的问题,
一些用户不知道如何导入数据库等.
这些问题都只能慢慢想办法去解决.

还有些用户因为字典库生成的名字中有些字的寓意不好, 你可以手动删掉你不喜欢字, 却来恶意中伤作者.
我想说的是这个字也不是我造的, 你如果有问题可以去找造那个字的人.
如果觉得这个工具不好你可以不用.

最近一年中因为作者个人原因导致Fate更新缓慢, 在这里向大家道个歉.
大家也知道现在国内的IT环境, 毕竟我也要生活, 生活所迫没有太多时间放在业余的项目上.
我只能尽量抽出时间来完善Fate的规则和代码.
在这里同样要感谢支持我的朋友们, 大家的出发点我相信是一样的.
用这个工具目的都是为了给孩子取一个好名字.
在过去的几年中虽然Fate经过了好几个版本的改进, 但是仍然有许多不足之处.
包括生成的名字太多不容易筛选,
有些用户遇到了一些和Go相关的问题,
一些用户不知道如何导入数据库等.
这些问题都只能慢慢想办法去解决.

还有些用户因为字典库生成的名字中有些字的寓意不好, 你可以手动删掉你不喜欢字, 却来恶意中伤作者.
我想说的是这个字也不是我造的, 你如果有问题可以去找造那个字的人.
如果觉得这个工具不好你可以不用.

最近一年中因为作者个人原因导致Fate更新缓慢, 在这里向大家道个歉.
大家也知道现在国内的IT环境, 毕竟我也要生活, 生活所迫没有太多时间放在业余的项目上.
我只能尽量抽出时间来完善Fate的规则和代码.
在这里同样要感谢支持我的朋友们, 大家的出发点我相信是一样的.
用这个工具目的都是为了给孩子取一个好名字.
1 change: 1 addition & 0 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/babyname/fate)](https://goreportcard.com/report/github.com/babyname/fate)

## Introduce

A modern science chinese name create tool.
The first chinese name create tool in github
It uses some traditional Chinese algorithms. It is used to get a good name for a newborn baby.
27 changes: 14 additions & 13 deletions bazi.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package fate

import (
"github.com/godcong/chronos"
"strings"

"github.com/godcong/chronos"
)

var diIndex = map[string]int{
Expand All @@ -13,7 +14,7 @@ var tianIndex = map[string]int{
"甲": 0, "乙": 1, "丙": 2, "丁": 3, "戊": 4, "己": 5, "庚": 6, "辛": 7, "壬": 8, "癸": 9,
}

//天干强度表
// 天干强度表
var tiangan = [][]int{
{1200, 1200, 1000, 1000, 1000, 1000, 1000, 1000, 1200, 1200},
{1060, 1060, 1000, 1000, 1100, 1100, 1140, 1140, 1100, 1100},
Expand All @@ -29,7 +30,7 @@ var tiangan = [][]int{
{1200, 1200, 1000, 1000, 1000, 1000, 1000, 1000, 1140, 1140},
}

//地支强度表
// 地支强度表
var dizhi = []map[string][]int{
{
"癸": {1200, 1100, 1000, 1000, 1040, 1060, 1000, 1000, 1200, 1200, 1060, 1140},
Expand Down Expand Up @@ -98,12 +99,12 @@ var wuXingDiZhi = map[string]string{
"亥": "水",
}

//WuXingTianGan 五行天干
// WuXingTianGan 五行天干
func WuXingTianGan(s string) string {
return wuXingTianGan[s]
}

//WuXingDiZhi 五行地支
// WuXingDiZhi 五行地支
func WuXingDiZhi(s string) string {
return wuXingDiZhi[s]
}
Expand All @@ -115,7 +116,7 @@ type BaZi struct {
xiyong *XiYong
}

//NewBazi 创建八字
// NewBazi 创建八字
func NewBazi(calendar chronos.Calendar) *BaZi {
ec := calendar.Lunar().EightCharacter()
return &BaZi{
Expand All @@ -129,26 +130,26 @@ func (z *BaZi) String() string {
return strings.Join(z.baZi, "")
}

//RiZhu 日主
// RiZhu 日主
func (z *BaZi) RiZhu() string {
return z.baZi[4]
}

func (z *BaZi) calcXiYong() {
z.xiyong = &XiYong{}
//TODO:need fix
z.point().calcSimilar().calcHeterogeneous() //.yongShen().xiShen()
// TODO:need fix
z.point().calcSimilar().calcHeterogeneous() // .yongShen().xiShen()
}

//XiYong 喜用神
// XiYong 喜用神
func (z *BaZi) XiYong() *XiYong {
if z.xiyong == nil {
z.calcXiYong()
}
return z.xiyong
}

//XiYongShen 平衡用神
// XiYongShen 平衡用神
func (z *BaZi) XiYongShen() string {
return z.XiYong().Shen()
}
Expand Down Expand Up @@ -180,7 +181,7 @@ func baziToWuXing(bazi []string) []string {
return wx
}

//计算同类
// 计算同类
func (z *BaZi) calcSimilar() *BaZi {
for i := range sheng {
if wuXingTianGan[z.RiZhu()] == sheng[i] {
Expand All @@ -200,7 +201,7 @@ func (z *BaZi) calcSimilar() *BaZi {
return z
}

//计算异类
// 计算异类
func (z *BaZi) calcHeterogeneous() *BaZi {
for i := range sheng {
for ti := range z.xiyong.Similar {
Expand Down
6 changes: 4 additions & 2 deletions bazi_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package fate_test

import (
"github.com/godcong/chronos"
"github.com/babyname/fate"
"log"
"testing"

"github.com/godcong/chronos"

"github.com/babyname/fate"
)

func TestPoint(t *testing.T) {
Expand Down
55 changes: 28 additions & 27 deletions character.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,36 @@ package fate
import (
"crypto/sha256"
"fmt"

"github.com/xormsharp/builder"
"github.com/xormsharp/xorm"
)

//Character 字符
// Character 字符
type Character struct {
Hash string `xorm:"pk hash"`
PinYin []string `xorm:"default() notnull pin_yin"` //拼音
Ch string `xorm:"default() notnull ch"` //字符
ScienceStroke int `xorm:"default(0) notnull science_stroke" json:"science_stroke"` //科学笔画
Radical string `xorm:"default() notnull radical"` //部首
RadicalStroke int `xorm:"default(0) notnull radical_stroke"` //部首笔画
Stroke int `xorm:"default() notnull stroke"` //总笔画数
IsKangXi bool `xorm:"default(0) notnull is_kang_xi"` //是否康熙字典
KangXi string `xorm:"default() notnull kang_xi"` //康熙
KangXiStroke int `xorm:"default(0) notnull kang_xi_stroke"` //康熙笔画
SimpleRadical string `xorm:"default() notnull simple_radical"` //简体部首
SimpleRadicalStroke int `xorm:"default(0) notnull simple_radical_stroke"` //简体部首笔画
SimpleTotalStroke int `xorm:"default(0) notnull simple_total_stroke"` //简体笔画
TraditionalRadical string `xorm:"default() notnull traditional_radical"` //繁体部首
TraditionalRadicalStroke int `xorm:"default(0) notnull traditional_radical_stroke"` //繁体部首笔画
TraditionalTotalStroke int `xorm:"default(0) notnull traditional_total_stroke"` //简体部首笔画
NameScience bool `xorm:"default(0) notnull name_science"` //姓名学
WuXing string `xorm:"default() notnull wu_xing"` //五行
Lucky string `xorm:"default() notnull lucky"` //吉凶寓意
Regular bool `xorm:"default(0) notnull regular"` //常用
TraditionalCharacter []string `xorm:"default() notnull traditional_character"` //繁体字
VariantCharacter []string `xorm:"default() notnull variant_character"` //异体字
Comment []string `xorm:"default() notnull comment"` //解释
PinYin []string `xorm:"default() notnull pin_yin"` // 拼音
Ch string `xorm:"default() notnull ch"` // 字符
ScienceStroke int `xorm:"default(0) notnull science_stroke" json:"science_stroke"` // 科学笔画
Radical string `xorm:"default() notnull radical"` // 部首
RadicalStroke int `xorm:"default(0) notnull radical_stroke"` // 部首笔画
Stroke int `xorm:"default() notnull stroke"` // 总笔画数
IsKangXi bool `xorm:"default(0) notnull is_kang_xi"` // 是否康熙字典
KangXi string `xorm:"default() notnull kang_xi"` // 康熙
KangXiStroke int `xorm:"default(0) notnull kang_xi_stroke"` // 康熙笔画
SimpleRadical string `xorm:"default() notnull simple_radical"` // 简体部首
SimpleRadicalStroke int `xorm:"default(0) notnull simple_radical_stroke"` // 简体部首笔画
SimpleTotalStroke int `xorm:"default(0) notnull simple_total_stroke"` // 简体笔画
TraditionalRadical string `xorm:"default() notnull traditional_radical"` // 繁体部首
TraditionalRadicalStroke int `xorm:"default(0) notnull traditional_radical_stroke"` // 繁体部首笔画
TraditionalTotalStroke int `xorm:"default(0) notnull traditional_total_stroke"` // 简体部首笔画
NameScience bool `xorm:"default(0) notnull name_science"` // 姓名学
WuXing string `xorm:"default() notnull wu_xing"` // 五行
Lucky string `xorm:"default() notnull lucky"` // 吉凶寓意
Regular bool `xorm:"default(0) notnull regular"` // 常用
TraditionalCharacter []string `xorm:"default() notnull traditional_character"` // 繁体字
VariantCharacter []string `xorm:"default() notnull variant_character"` // 异体字
Comment []string `xorm:"default() notnull comment"` // 解释
}

// InsertOrUpdateCharacter ...
Expand Down Expand Up @@ -84,10 +85,10 @@ func Stoker(s int, options ...CharacterOptions) func(engine *xorm.Engine) *xorm.
return func(engine *xorm.Engine) *xorm.Session {
session := engine.Where("pin_yin IS NOT NULL").
And(builder.Eq{"science_stroke": s})
//Or(builder.Eq{"stroke": s}).
//Or(builder.Eq{"kang_xi_stroke": s}).
//Or(builder.Eq{"simple_total_stroke": s}).
//Or(builder.Eq{"traditional_total_stroke": s}))
// Or(builder.Eq{"stroke": s}).
// Or(builder.Eq{"kang_xi_stroke": s}).
// Or(builder.Eq{"simple_total_stroke": s}).
// Or(builder.Eq{"traditional_total_stroke": s}))
for _, option := range options {
session = option(session)
}
Expand Down
4 changes: 2 additions & 2 deletions database.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ func initSQL(database config.Database) *xorm.Engine {
eng.ShowSQL(true)
}

//if database.ShowExecTime {
// if database.ShowExecTime {
// eng.ShowExecTime(true)
//}
// }
return eng
}
8 changes: 4 additions & 4 deletions dayan.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,22 @@ type DaYan struct {
Number int
Lucky string
Max bool
Sex Sex //male(false),female(true)
Sex Sex // male(false),female(true)
SkyNine string
Comment string
}

//IsNotSuitableSex 女性不宜此数
// IsNotSuitableSex 女性不宜此数
func (dy DaYan) IsNotSuitableSex() bool {
return dy.Sex == SexGirl
}

//IsMax 是否最大好运数
// IsMax 是否最大好运数
func (dy DaYan) IsMax() bool {
return dy.Max
}

//GetDaYan 获取大衍之数
// GetDaYan 获取大衍之数
func GetDaYan(idx int) DaYan {
if idx <= 0 {
panic("wrong idx")
Expand Down
Loading

0 comments on commit 2ce3f81

Please sign in to comment.