🐛 rename breed en name

This commit is contained in:
Havoc412 2024-10-16 13:51:58 +08:00
parent 89d6ed41e9
commit b0e4b1a970
4 changed files with 32 additions and 90 deletions

View File

@ -21,15 +21,20 @@ type Animal struct {
NickName string `gorm:"type:varchar(31)" json:"nick_name,omitempty"` // 别称,辅助查询;存储上采取 , 间隔符的方式; VARCHAR 会比较合适
Status uint8 `json:"status,omitempty"` // 状态
Description string `gorm:"column:description;type:varchar(255)" json:"description,omitempty"` // 简明介绍
Tags string `json:"tags,omitempty"`
// TAG imaegs
Avatar string `gorm:"type:varchar(10)" json:"avatar,omitempty"` // 缩略图 url为 Go 获取 Photo 之后压缩处理后的图像,单独存储。
AvatarHeight uint16 `json:"avatar_height,omitempty"` // 为了方便前端在加载图像前的骨架图 & 瀑布流展示。
AvatarHeight uint16 `json:"avatar_height,omitempty"` // 为了方便前端在加载图像前的骨架图 & 瀑布流展示。 // INFO 暂时没用到
AvatarWidth uint16 `json:"avatar_width,omitempty"` // 为了方便前端在加载图像前的骨架图 & 瀑布流展示。
HeadImg string `gorm:"type:varchar(10)" json:"head_img,omitempty"` // Head 默认处理为正方形。
Photos string `gorm:"type:varchar(100)" json:"photos,omitempty"` // 图片数组
// TAG POI
Latitude float64 `json:"latitude,omitempty"` // POI 位置相关
Longitude float64 `json:"longitude,omitempty"` // POI 位置相关
ActivityRadius uint64 `json:"activity_radius,omitempty"`
Tags string `json:"tags,omitempty"` // 活动半径
ActivityRadius uint64 `json:"activity_radius,omitempty"` // 活动半径
// CatFace
FaceBreeds string `json:"face_breeds,omitempty" gorm:"size:20"`
FaceBreedProbs string `json:"face_breed_probs" gorm:"size:20"`
}
func (a *Animal) TableName() string {

View File

@ -1,20 +0,0 @@
package model
// INFO 写在前面:实际上这个模块是 CatFace 子模块在维护,所以对应的 curd 都交给 python 了。
/**
* @description: 保留 Top 3, 辅助 catface - breed 子模型判断 单独建表因为只会被 CatFace 模块使用
* @return {*}
*/
type AnmFaceBreed struct { // TODO 迁移 python 的时候再考虑一下细节
BaseModel
Top1 uint8
Prob1 float64
Top2 uint8
Prob2 float64
Top3 uint8
Prob3 float64
AnimalId int64 `gorm:"index;column:animal_id"` // INFO 外键设定?
Animal Animal
}

View File

@ -40,8 +40,12 @@ func testInsertSterilzation() {
func testInsertBreed() {
// INFO 为方便之后扩展,将 unknown 默认为 1
colorsZH := []string{"不明", "橘白", "奶牛", "白猫", "黑猫", "橘猫", "狸花", "狸白", "简州", "三花", "彩狸"}
colorsEN := []string{"unknown", "orange", "cow", "white", "black", "orangeCat", "tabby", "tabbyWhite", "jianzhong", "threeColor", "colorCat"}
colorsZH := []string{
"不明", "橘白", "奶牛", "白猫", "黑猫", "橘猫", "狸花", "狸白", "三花", "玳瑁", "简州", "彩狸",
}
colorsEN := []string{
"unknown", "orgwhite", "milk", "white", "black", "orange", "li", "liwhite", "flower", "tortoiseshell", "jianzhou", "color",
}
for i := 0; i < len(colorsZH); i++ {
breed := model.AnmBreed{
BriefModel: model.BriefModel{
@ -96,8 +100,8 @@ func testInsertStatus() {
}
func insertData() {
testInsertSterilzation()
fmt.Println("testInsertSterilzation success.")
// testInsertSterilzation()
// fmt.Println("testInsertSterilzation success.")
testInsertBreed()
fmt.Println("testInsertBreed success.")
@ -123,5 +127,5 @@ func main() {
autoMigrateTable()
fmt.Println("autoMigrateTable over.")
// insertData() // INFO 记得用完注释掉
insertData() // INFO 记得用完注释掉
}

View File

@ -1,47 +0,0 @@
package test
import (
"catface/app/model"
"testing"
"github.com/stretchr/testify/assert"
)
func TestAnmFaceBreed(t *testing.T) {
Init()
err := DB.AutoMigrate(&model.AnmFaceBreed{})
if err != nil {
t.Error(err)
}
// // INFO 查询表上的所有索引
// var indexes []struct {
// IndexName string
// ColumnName string
// }
// DB.Raw(`SELECT INDEX_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?`, "Hav'sCats", "anm_face_breeds").Scan(&indexes)
// fmt.Println("All Indexes:", len(indexes)) // QUESTION 输出 0 ?
// for _, index := range indexes {
// fmt.Printf("Index Name: %s, Column Name: %s\n", index.IndexName, index.ColumnName)
// }
animalFaceBreed := model.AnmFaceBreed{
AnimalId: 1,
Top1: 3,
Prob1: 0.9,
Top2: 4,
Prob2: 0.05,
Top3: 5,
Prob3: 0.05,
}
// res := DB.Create(&animalFaceBreed)
// assert.Nil(t, res.Error)
// 可以进一步检查数据是否正确插入,例如通过查询数据库来验证
var temp model.AnmFaceBreed
result := DB.First(&temp, 1) //animalFaceBreed.BaseModel.Id) // ATT 这里用 Id 直接去拿到默认值 0
assert.Nil(t, result.Error)
assert.Equal(t, animalFaceBreed.Top1, temp.Top1)
}