-
Notifications
You must be signed in to change notification settings - Fork 20
/
family_statistics.go
47 lines (38 loc) 路 1.27 KB
/
family_statistics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package html
import (
"github.com/elliotchance/gedcom"
"github.com/elliotchance/gedcom/html/core"
"io"
)
type FamilyStatistics struct {
document *gedcom.Document
}
func NewFamilyStatistics(document *gedcom.Document) *FamilyStatistics {
return &FamilyStatistics{
document: document,
}
}
func (c *FamilyStatistics) WriteHTMLTo(w io.Writer) (int64, error) {
total := len(c.document.Families())
marriageEvents := 0
divorceEvents := 0
for _, family := range c.document.Families() {
n := gedcom.First(gedcom.NodesWithTagPath(family, gedcom.TagMarriage))
if n != nil {
marriageEvents += 1
}
n = gedcom.First(gedcom.NodesWithTagPath(family, gedcom.TagDivorce))
if n != nil {
divorceEvents += 1
}
}
totalFamilies := core.NewNumber(total)
marriageCount := core.NewNumber(marriageEvents)
divorceCount := core.NewNumber(divorceEvents)
totalFamiliesRow := core.NewKeyedTableRow("Total Families", totalFamilies, true)
marriageCountRow := core.NewKeyedTableRow("Marriage Events", marriageCount, true)
divorceCountRow := core.NewKeyedTableRow("Divorce Events", divorceCount, true)
s := core.NewComponents(totalFamiliesRow, marriageCountRow, divorceCountRow)
return core.NewCard(core.NewText("Families"), core.CardNoBadgeCount,
core.NewTable("", s)).WriteHTMLTo(w)
}