Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle empty users for histogram of age for new contests #216

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions client/src/Components/Histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,21 @@ function Histogram({
return (
<>
<h3>{pathToTitle(path, field, resp.unit)}</h3>
<Chart
// Because we have pre-binned data.
chartType="ColumnChart"
data={resp.data}
options={options}
width={width}
height={height}
/>

{
// The header is the first entry, the rest are
// the bins. This indicates that there is data.
(resp.data.length > 1) ? <Chart
// Because we have pre-binned data.
chartType="ColumnChart"
data={resp.data}
options={options}
width={width}
height={height}
/> : <p>No data available.</p>}
</>
);
}
};

const transform = (data, field) => {
// Display a cutoff for the last bin,
Expand Down
14 changes: 14 additions & 0 deletions home/tests/unit/test_histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ def create_test_cases(self):
"error": "not supported",
},
},
{
"name": "empty contest with no user",
"input": {
"field": "age",
"bin_size": 10,
"model": Account,
"contest_id": self.empty_contest_id,
},
"expect": {
"response": {
"data": [],
}
},
},
{
"name": "require contest id data for Leaderboard",
"input": {
Expand Down
4 changes: 2 additions & 2 deletions home/views/api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ def fill_missing_bin_idx(
query_set,
bin_size: int = None,
bin_custom: list = None,
total_bin_ct: int = None,
total_bin_ct: int = 0,
):
"""Fill in missing bin intervals lazily.

Expand Down Expand Up @@ -662,7 +662,7 @@ def create_filler(cursor, bin_size, bin_custom):
cursor = next(bin_idx_counter)
# Fill in the rest of the bins with 0 count,
# until we reach the total expected count of bins.
while cursor < total_bin_ct:
while cursor and cursor < total_bin_ct:
yield create_filler(
cursor=cursor, bin_size=bin_size, bin_custom=bin_custom
)
Expand Down