@@ -14,12 +14,17 @@ import (
14
14
)
15
15
16
16
type Stats struct {
17
- Catalogs uint64 `json:"catalogs"`
18
- Collections uint64 `json:"collections"`
19
- Items uint64 `json:"items"`
20
- Assets map [string ]uint64 `json:"assets"`
21
- Extensions map [string ]uint64 `json:"extensions"`
22
- Conformance map [string ]uint64 `json:"conformance"`
17
+ Catalogs * ResourceStats `json:"catalogs,omitempty"`
18
+ Collections * ResourceStats `json:"collections,omitempty"`
19
+ Items * ResourceStats `json:"items,omitempty"`
20
+ }
21
+
22
+ type ResourceStats struct {
23
+ Count uint64 `json:"count"`
24
+ Versions map [string ]uint64 `json:"versions,omitempty"`
25
+ Extensions map [string ]uint64 `json:"extensions,omitempty"`
26
+ Conformance map [string ]uint64 `json:"conformance,omitempty"`
27
+ Assets map [string ]uint64 `json:"assets,omitempty"`
23
28
}
24
29
25
30
var statsCommand = & cli.Command {
@@ -32,6 +37,12 @@ var statsCommand = &cli.Command{
32
37
Usage : "Path to STAC resource (catalog, collection, or item) to crawl" ,
33
38
EnvVars : []string {toEnvVar (flagEntry )},
34
39
},
40
+ & cli.BoolFlag {
41
+ Name : flagExcludeEntry ,
42
+ Usage : "Do not count the entry itself" ,
43
+ Value : false ,
44
+ EnvVars : []string {toEnvVar (flagExcludeEntry )},
45
+ },
35
46
& cli.IntFlag {
36
47
Name : flagConcurrency ,
37
48
Usage : "Concurrency limit" ,
@@ -55,11 +66,7 @@ var statsCommand = &cli.Command{
55
66
}
56
67
57
68
mutext := & sync.Mutex {}
58
- stats := & Stats {
59
- Assets : map [string ]uint64 {},
60
- Extensions : map [string ]uint64 {},
61
- Conformance : map [string ]uint64 {},
62
- }
69
+ stats := & Stats {}
63
70
64
71
bar := progressbar .NewOptions64 (
65
72
- 1 ,
@@ -74,35 +81,82 @@ var statsCommand = &cli.Command{
74
81
progressbar .OptionClearOnFinish (),
75
82
)
76
83
84
+ skip := ctx .Bool (flagExcludeEntry )
77
85
visitor := func (location string , resource crawler.Resource ) error {
86
+ if skip {
87
+ skip = false
88
+ return nil
89
+ }
90
+
78
91
mutext .Lock ()
79
92
defer mutext .Unlock ()
80
93
94
+ var resourceStats * ResourceStats
95
+
81
96
switch resource .Type () {
82
97
case crawler .Catalog :
83
- stats .Catalogs += 1
84
- case crawler .Collection :
85
- stats .Collections += 1
86
- case crawler .Item :
87
- stats .Items += 1
88
- }
98
+ if stats .Catalogs == nil {
99
+ stats .Catalogs = & ResourceStats {}
100
+ }
101
+ for _ , conformance := range resource .ConformsTo () {
102
+ if stats .Catalogs .Conformance == nil {
103
+ stats .Catalogs .Conformance = map [string ]uint64 {}
104
+ }
105
+ stats .Catalogs .Conformance [conformance ] += 1
106
+ }
107
+ resourceStats = stats .Catalogs
89
108
90
- _ = bar .Add (1 )
91
- bar .Describe (fmt .Sprintf ("catalogs: %d; collections: %d; items: %d" , stats .Catalogs , stats .Collections , stats .Items ))
109
+ case crawler .Collection :
110
+ if stats .Collections == nil {
111
+ stats .Collections = & ResourceStats {}
112
+ }
113
+ resourceStats = stats .Collections
92
114
93
- if resource .Type () == crawler .Item {
115
+ case crawler .Item :
116
+ if stats .Items == nil {
117
+ stats .Items = & ResourceStats {}
118
+ }
94
119
for _ , asset := range resource .Assets () {
95
- stats .Assets [asset .Type ()] += 1
120
+ if stats .Items .Assets == nil {
121
+ stats .Items .Assets = map [string ]uint64 {}
122
+ }
123
+ stats .Items .Assets [asset .Type ()] += 1
96
124
}
125
+ resourceStats = stats .Items
97
126
}
98
127
99
128
for _ , extension := range resource .Extensions () {
100
- stats .Extensions [extension ] += 1
129
+ if resourceStats .Extensions == nil {
130
+ resourceStats .Extensions = map [string ]uint64 {}
131
+ }
132
+ resourceStats .Extensions [extension ] += 1
133
+ }
134
+
135
+ if resourceStats .Versions == nil {
136
+ resourceStats .Versions = map [string ]uint64 {}
137
+ }
138
+ resourceStats .Versions [resource .Version ()] += 1
139
+
140
+ resourceStats .Count += 1
141
+
142
+ catalogs := uint64 (0 )
143
+ if stats .Catalogs != nil {
144
+ catalogs = stats .Catalogs .Count
145
+ }
146
+
147
+ collections := uint64 (0 )
148
+ if stats .Collections != nil {
149
+ collections = stats .Collections .Count
101
150
}
102
151
103
- for _ , conformance := range resource .ConformsTo () {
104
- stats .Conformance [conformance ] += 1
152
+ items := uint64 (0 )
153
+ if stats .Items != nil {
154
+ items = stats .Items .Count
105
155
}
156
+
157
+ _ = bar .Add (1 )
158
+ bar .Describe (fmt .Sprintf ("catalogs: %d; collections: %d; items: %d" , catalogs , collections , items ))
159
+
106
160
return nil
107
161
}
108
162
0 commit comments