-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstats.go
106 lines (89 loc) · 2.33 KB
/
stats.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package luminosity
import (
"sort"
)
type Stats struct {
ByDate DistributionList `json:"by_date"`
ByCamera DistributionList `json:"by_camera"`
ByLens DistributionList `json:"by_lens"`
ByFocalLength DistributionList `json:"by_focal_length"`
ByAperture DistributionList `json:"by_aperture"`
ByExposureTime DistributionList `json:"by_exposure_time"`
ByEditCount DistributionList `json:"by_edit_count"`
ByKeyword DistributionList `json:"by_keyword"`
}
func newStats() *Stats {
return &Stats{
ByDate: DistributionList{},
ByCamera: DistributionList{},
ByLens: DistributionList{},
ByFocalLength: DistributionList{},
ByAperture: DistributionList{},
ByExposureTime: DistributionList{},
ByEditCount: DistributionList{},
ByKeyword: DistributionList{},
}
}
func (s *Stats) Merge(other *Stats) {
s.ByDate = s.ByDate.Merge(other.ByDate)
s.ByCamera = s.ByCamera.Merge(other.ByCamera)
s.ByLens = s.ByLens.Merge(other.ByLens)
s.ByFocalLength = s.ByFocalLength.Merge(other.ByFocalLength)
s.ByAperture = s.ByAperture.Merge(other.ByAperture)
s.ByExposureTime = s.ByExposureTime.Merge(other.ByExposureTime)
s.ByEditCount = s.ByEditCount.Merge(other.ByEditCount)
s.ByKeyword = s.ByKeyword.Merge(other.ByKeyword)
sort.Sort(ByDate(s.ByDate))
}
func (c *Catalog) GetStats() (*Stats, error) {
if c.Stats != nil {
return c.Stats, nil
}
s := newStats()
if c.db == nil {
c.Stats = s
return s, nil
}
if d, err := c.GetPhotoCountsByDate(); err != nil {
return nil, err
} else {
s.ByDate = d
}
if d, err := c.GetCameraDistribution(); err != nil {
return nil, err
} else {
s.ByCamera = d
}
if d, err := c.GetLensDistribution(); err != nil {
return nil, err
} else {
s.ByLens = d
}
if d, err := c.GetFocalLengthDistribution(); err != nil {
return nil, err
} else {
s.ByFocalLength = d
}
if d, err := c.GetApertureDistribution(); err != nil {
return nil, err
} else {
s.ByAperture = d
}
if d, err := c.GetExposureTimeDistribution(); err != nil {
return nil, err
} else {
s.ByExposureTime = d
}
if d, err := c.GetEditCountDistribution(); err != nil {
return nil, err
} else {
s.ByEditCount = d
}
if d, err := c.GetKeywordDistribution(); err != nil {
return nil, err
} else {
s.ByKeyword = d
}
c.Stats = s
return c.Stats, nil
}