Documentation ¶
Index ¶
- Constants
- Variables
- func AfterDelete(tx *gorm.DB, tableIdx int) (bool, error)
- func CheckDoubleChick(tx *gorm.DB, id uint, name string) error
- func ClearMateTable(tx *gorm.DB, tableIdx int) error
- func CombineHD(hd1, hd2 string) string
- func ComputeALC(tx *gorm.DB, dog *Dog) (float64, error)
- func CreateChick(tx *gorm.DB, chick *Chick, name string) error
- func FillMateTable(tx *gorm.DB, tableIdx int, chickID uint, chickName string) error
- func FindFreeMateTable(tx *gorm.DB) int
- func Init(dbFname string) (*gorm.DB, error)
- type BaseMetaFeature
- type Chick
- type Color
- type Dog
- type FeatureGroup
- type FemaleDog
- type Litter
- type MaleDog
- type Mate
- type Mate1
- type Mate10
- type Mate2
- type Mate3
- type Mate4
- type Mate5
- type Mate6
- type Mate7
- type Mate8
- type Mate9
- type Percentage
- type Star
- type TypeEnum
Constants ¶
const MateTableCount = 10
MateTableCount is the number of tables used for mating. Counting starts at 1.
const UnknownHD = "--"
UnknownHD is the display and DB value for an unknown HD.
Variables ¶
var ( TypeUnknown = TypeEnum{""} TypeString = TypeEnum{"string"} TypeText = TypeEnum{"text"} TypeCheckbox = TypeEnum{"checkbox"} TypeInt = TypeEnum{"integer"} TypeFloat = TypeEnum{"floating point"} TypeDate = TypeEnum{"date"} TypeDateTime = TypeEnum{"timestamp"} TypeSelectOne = TypeEnum{"select one"} TypeSelectMany = TypeEnum{"select many"} )
var AllTypeEnums = []string{ TypeUnknown.slug, TypeString.slug, TypeText.slug, TypeCheckbox.slug, TypeInt.slug, TypeFloat.slug, TypeDate.slug, TypeDateTime.slug, TypeSelectOne.slug, TypeSelectMany.slug, }
Functions ¶
func AfterDelete ¶
AfterDelete deletes the chick associated with the mate table after the last mate has been deleted.
func CheckDoubleChick ¶
CheckDoubleChick checks if the chick is already mating.
func ClearMateTable ¶
ClearMateTable deletes all mates from the chosen mate table.
func ComputeALC ¶
ComputeALC calculates the correct ALC for 6 generations. WARNING: All generations have to be present!
func CreateChick ¶
CreateChick first checks if the chick is already mating and creates it only if not.
func FillMateTable ¶
FillMateTable fills the chosen mate table with male dogs that are candidates for mating.
func FindFreeMateTable ¶
FindFreeMateTable returns the number (between 1 and 10) of the first currently unused mate table.
Types ¶
type BaseMetaFeature ¶
type Chick ¶
type Chick struct { ID uint `gorm:"primary_key"` MateALC Percentage MateHD string `gorm:"size:8"` MateTable int `gorm:"unique;not null"` // we allow up to 9 tables for male partners (mate1 ... mate9) }
Chick is a female dog chosen for mating (opposite of Mate). The technically correct term for this ('Bitch') sounds insulting for many so I chose 'Chick' instead. Deleting a record from the corresponding table should not just fill a deleted_at column but really delete the DB row or the same dog couldn't mate twice. Because of that we don't use gorm.Model.
type Dog ¶
type Dog struct { gorm.Model Name string `gorm:"size:32;unique;not null"` BirthDate *time.Time Gender string `gorm:"size:16"` Star Star ALC Percentage HD string `gorm:"size:8"` MateCount int FatherID uint Father MaleDog `gorm:"foreignkey:FatherID;association_autocreate:false;association_autoupdate:false"` MotherID uint Mother FemaleDog `gorm:"foreignkey:MotherID;association_autocreate:false;association_autoupdate:false"` Remark string }
Dog has got Mother and Father parents. This is the central data structure of the whole application.
func FindAncestorsForDog ¶
FindAncestorsForDog finds all ancestors up to the given generation.
func FindAncestorsForID ¶
FindAncestorsForID finds all ancestors up to the given generation.
func (*Dog) BeforeDelete ¶
BeforeDelete checks if the dog is currently mating and returns an error if this is the case.
type FeatureGroup ¶
type FemaleDog ¶
FemaleDog is a view of female dogs (rows in the dogs table with gender set to 'F'). A FemaleDog belongs to a Dog (it's child) as Mother.
type Litter ¶
type Litter struct { ID uint `gorm:"primary_key"` CreatedAt time.Time Name string ALC Percentage HD string `gorm:"size:8"` FatherID uint Father MaleDog `gorm:"foreignkey:FatherID;association_autocreate:false;association_autoupdate:false"` MotherID uint Mother FemaleDog `gorm:"foreignkey:MotherID;association_autocreate:false;association_autoupdate:false"` Remark string }
Litter is the result of a successful mating action.
type MaleDog ¶
MaleDog is a view of male dogs (rows in the dogs table with gender set to 'M'). A MaleDog belongs to a Dog (it's child) as Father.
type Mate ¶
type Mate struct { ID uint `gorm:"primary_key"` Name string BirthDate time.Time ALC Percentage HD string `gorm:"size:8"` MateCount int FatherID uint Father MaleDog `gorm:"foreignkey:FatherID;association_autocreate:false;association_autoupdate:false"` MotherID uint Mother FemaleDog `gorm:"foreignkey:MotherID;association_autocreate:false;association_autoupdate:false"` ChildALC Percentage Remark string }
Mate is a male dog chosen as a candidate for mating. Mate is like Dog but doesn't need Star or Gender because it is always true and male. Deleting a record from the corresponding table should not just fill a deleted_at column but really delete the DB row or the same dog couldn't mate twice. Because of that we don't use gorm.Model.
func GenericMate ¶
func GenericMate(result interface{}) *Mate
GenericMate returns the Mate common to all mate tables.
type Percentage ¶
type Percentage float64
Percentage can be stored in the DB and displayed nicely (with only 2 decimal places).
func (Percentage) String ¶
func (p Percentage) String() string
String is implemented for nicer looking numbers.