Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
internewshid
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
aptivate
client-projects
internewshid
Commits
459e13d2
Commit
459e13d2
authored
9 years ago
by
Alice Heaton
Browse files
Options
Downloads
Plain Diff
Merge branch 'bar_chart_unknown' into develop
parents
b09fafd8
5bf9a689
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
django/website/hid/tests/term_count_widget_tests.py
+38
-0
38 additions, 0 deletions
django/website/hid/tests/term_count_widget_tests.py
django/website/hid/widgets/term_count_chart.py
+10
-2
10 additions, 2 deletions
django/website/hid/widgets/term_count_chart.py
with
48 additions
and
2 deletions
django/website/hid/tests/term_count_widget_tests.py
+
38
−
0
View file @
459e13d2
...
...
@@ -230,3 +230,41 @@ class TestTermCountChartWidget(TestCase):
self
.
assertEqual
(
t1
,
itemcount_kwargs
[
'
start_time
'
])
self
.
assertEqual
(
t2
,
itemcount_kwargs
[
'
end_time
'
])
def
test_categories_can_be_excluded
(
self
):
widget
=
TermCountChartWidget
()
with
patch
(
'
hid.widgets.term_count_chart.term_itemcount
'
)
as
itemcount
:
itemcount
.
return_value
=
[
{
'
name
'
:
'
Ebola updates
'
,
'
long_name
'
:
'
What are the current updates on Ebola.
'
,
'
count
'
:
0
,
},
{
'
name
'
:
'
Ebola prevention
'
,
'
long_name
'
:
'
What measures could be put in place to end Ebola.
'
,
'
count
'
:
4
,
},
{
'
name
'
:
'
Liberia Ebola-free
'
,
'
long_name
'
:
'
Can Liberia be Ebola free.
'
,
'
count
'
:
3
,
},
{
'
name
'
:
'
Unknown
'
,
'
long_name
'
:
'
Unknown.
'
,
'
count
'
:
2
,
},
]
context_data
=
widget
.
get_context_data
(
title
=
'
test-name
'
,
taxonomy
=
'
tax
'
,
exclude_categories
=
[
'
Unknown
'
,
'
Liberia Ebola-free
'
]
)
ticks
=
context_data
[
'
options
'
][
'
yaxis
'
][
'
ticks
'
]
labels
=
[
t
[
1
]
for
t
in
ticks
]
self
.
assertIn
(
'
What are the current updates on Ebola.
'
,
labels
)
self
.
assertIn
(
'
What measures could be put in place to end Ebola.
'
,
labels
)
self
.
assertNotIn
(
'
Can Liberia be Ebola free.
'
,
labels
)
self
.
assertNotIn
(
'
Unknown.
'
,
labels
)
This diff is collapsed.
Click to expand it.
django/website/hid/widgets/term_count_chart.py
+
10
−
2
View file @
459e13d2
...
...
@@ -28,7 +28,8 @@ class TermCountChartWidget(object):
'
hid/widgets/chart.js
'
]
def
_fetch_counts
(
self
,
taxonomy
,
count
,
start
,
end
,
other_label
):
def
_fetch_counts
(
self
,
taxonomy
,
count
,
start
,
end
,
other_label
,
exclude_categories
=
None
):
"""
Given a taxonomy, fetch the count per term.
Args:
...
...
@@ -49,6 +50,11 @@ class TermCountChartWidget(object):
)
else
:
itemcount
=
term_itemcount
(
taxonomy
)
if
exclude_categories
is
not
None
:
itemcount
=
[
t
for
t
in
itemcount
if
t
[
'
name
'
]
not
in
exclude_categories
]
itemcount
.
sort
(
key
=
lambda
k
:
int
(
k
[
'
count
'
]),
reverse
=
True
)
if
count
>
0
:
head
=
itemcount
[
0
:
count
-
1
]
...
...
@@ -129,6 +135,7 @@ class TermCountChartWidget(object):
count
=
kwargs
.
get
(
'
count
'
,
0
)
other_label
=
kwargs
.
get
(
'
other_label
'
,
'
Others
'
)
periods
=
kwargs
.
get
(
'
periods
'
,
[])
exclude_categories
=
kwargs
.
get
(
'
exclude_categories
'
)
if
len
(
periods
)
>
1
:
raise
WidgetError
(
'
Only one time period is currently supported
'
)
...
...
@@ -153,7 +160,8 @@ class TermCountChartWidget(object):
label
=
''
counts
=
self
.
_fetch_counts
(
taxonomy
,
count
,
start_time
,
end_time
,
other_label
taxonomy
,
count
,
start_time
,
end_time
,
other_label
,
exclude_categories
)
(
values
,
yticks
)
=
self
.
_create_axis_values
(
counts
)
return
{
...
...
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