Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
librestash
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nik | Klampfradler
librestash
Commits
0b6b6e63
Verified
Commit
0b6b6e63
authored
7 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Generate stats independent of exporters.
parent
e850fe71
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
librestash/cmd.py
+2
-3
2 additions, 3 deletions
librestash/cmd.py
librestash/lib/stats/__init__.py
+6
-2
6 additions, 2 deletions
librestash/lib/stats/__init__.py
librestash/lib/stats/basic.py
+14
-13
14 additions, 13 deletions
librestash/lib/stats/basic.py
with
22 additions
and
18 deletions
librestash/cmd.py
+
2
−
3
View file @
0b6b6e63
...
@@ -57,7 +57,7 @@ def stats():
...
@@ -57,7 +57,7 @@ def stats():
"""
Command for all kinds of statistics
"""
"""
Command for all kinds of statistics
"""
parser
=
ArgumentParser
(
parents
=
[
_PARENT_PARSER
])
parser
=
ArgumentParser
(
parents
=
[
_PARENT_PARSER
])
parser
.
add_argument
(
'
--
found-by
'
,
help
=
'
limit caches found by cacher name
'
,
default
=
None
)
parser
.
add_argument
(
'
--
geocacher
'
,
help
=
'
name of geocacher to produce stats for
'
,
default
=
None
)
parser
.
add_argument
(
'
--format
'
,
help
=
'
output format
'
,
default
=
'
json
'
)
parser
.
add_argument
(
'
--format
'
,
help
=
'
output format
'
,
default
=
'
json
'
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
...
@@ -66,8 +66,7 @@ def stats():
...
@@ -66,8 +66,7 @@ def stats():
config
=
get_config
(
args
.
config
)
config
=
get_config
(
args
.
config
)
database
=
get_db
(
config
)
database
=
get_db
(
config
)
exporter
=
CacheExporter
(
config
,
database
)
data
=
all_stats
(
database
,
geocacher_name
=
args
.
geocacher
)
data
=
all_stats
(
exporter
.
export
(
found_by
=
args
.
found_by
))
if
args
.
format
==
'
json
'
:
if
args
.
format
==
'
json
'
:
print
(
stats_to_json
(
data
))
print
(
stats_to_json
(
data
))
...
...
This diff is collapsed.
Click to expand it.
librestash/lib/stats/__init__.py
+
6
−
2
View file @
0b6b6e63
from
..model
import
Geocacher
STATS_PLUGINS
=
[]
STATS_PLUGINS
=
[]
def
stats_plugin
(
func
):
def
stats_plugin
(
func
):
STATS_PLUGINS
.
append
(
func
)
STATS_PLUGINS
.
append
(
func
)
return
func
return
func
def
all_stats
(
data
):
def
all_stats
(
db
,
geocacher_name
):
geocacher
=
db
.
Session
().
query
(
Geocacher
).
filter_by
(
name
=
geocacher_name
).
one
()
res
=
{}
res
=
{}
for
plugin
in
STATS_PLUGINS
:
for
plugin
in
STATS_PLUGINS
:
res
[
plugin
.
__name__
]
=
plugin
(
data
)
res
[
plugin
.
__name__
]
=
plugin
(
geocacher
)
return
res
return
res
from
.basic
import
*
from
.basic
import
*
This diff is collapsed.
Click to expand it.
librestash/lib/stats/basic.py
+
14
−
13
View file @
0b6b6e63
from
.
import
stats_plugin
from
.
import
stats_plugin
def
_field_count
(
data
,
field
):
def
_field_count
(
geocacher
,
field
):
res
=
{}
res
=
{}
for
cache
in
data
:
for
cache
in
geocacher
.
found_geocaches
:
if
not
cache
[
field
]
in
res
:
value
=
getattr
(
cache
,
field
)
res
[
cache
[
field
]]
=
0
if
not
value
in
res
:
res
[
cache
[
field
]]
+=
1
res
[
value
]
=
0
res
[
value
]
+=
1
return
res
return
res
@stats_plugin
@stats_plugin
def
type_count
(
data
):
def
type_count
(
geocacher
):
return
_field_count
(
data
,
'
type
'
)
return
_field_count
(
geocacher
,
'
type
'
)
@stats_plugin
@stats_plugin
def
size_count
(
data
):
def
size_count
(
geocacher
):
return
_field_count
(
data
,
'
size
'
)
return
_field_count
(
geocacher
,
'
size
'
)
@stats_plugin
@stats_plugin
def
difficulty_count
(
data
):
def
difficulty_count
(
geocacher
):
return
_field_count
(
data
,
'
difficulty
'
)
return
_field_count
(
geocacher
,
'
difficulty
'
)
@stats_plugin
@stats_plugin
def
terrain_count
(
data
):
def
terrain_count
(
geocacher
):
return
_field_count
(
data
,
'
terrain
'
)
return
_field_count
(
geocacher
,
'
terrain
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment