Skip to content

Commit

Permalink
Merge pull request #65 from Doist/proxi/precent
Browse files Browse the repository at this point in the history
fix: Fix typo precent -> percent.
  • Loading branch information
proxi authored Aug 1, 2024
2 parents 0d90905 + a3f26cd commit 249f7e1
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
23 changes: 13 additions & 10 deletions bitmapist/cohort/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def render_html_form(
select1b=None,
select2=None,
select2b=None,
as_precent=1,
as_percent=1,
num_results=31,
num_of_rows=12,
start_date=None,
Expand Down Expand Up @@ -137,7 +137,7 @@ def render_html_form(
select2=select2,
select2b=select2b,
action_url=action_url,
as_precent=as_precent,
as_percent=as_percent,
num_results=int(num_results),
num_of_rows=int(num_of_rows),
start_date=start_date,
Expand All @@ -147,7 +147,7 @@ def render_html_form(

def render_html_data(
dates_data,
as_precent=True,
as_percent=True,
time_group="days",
num_results: int = 31,
num_of_rows: int = 12,
Expand All @@ -157,15 +157,15 @@ def render_html_data(
Render's data as HTML, inside a TABLE element.
:param :dates_data The data that's returned by `get_dates_data`
:param :as_precent Should the data be shown as percents or as counts. Defaults to `True`
:param :as_percent Should the data be shown as percents or as counts. Defaults to `True`
:param :time_group What is the data grouped by? Can be `days`, `weeks`, `months`, `years`
"""
return (
get_lookup()
.get_template("table_data.mako")
.render(
dates_data=dates_data,
as_precent=as_precent,
as_percent=as_percent,
time_group=time_group,
num_results=num_results,
num_of_rows=num_of_rows,
Expand All @@ -176,7 +176,7 @@ def render_html_data(

def render_csv_data(
dates_data,
as_precent=True,
as_percent=True,
time_group="days",
num_results: int = 31,
num_of_rows: int = 12,
Expand All @@ -188,7 +188,7 @@ def render_csv_data(
.get_template("table_data_csv.mako")
.render(
dates_data=dates_data,
as_precent=as_precent,
as_percent=as_percent,
time_group=time_group,
num_results=num_results,
num_of_rows=num_of_rows,
Expand All @@ -207,7 +207,7 @@ def get_dates_data(
select2b=None,
time_group="days",
system="default",
as_precent=1,
as_percent=1,
num_results=31,
num_of_rows=12,
start_date=None,
Expand All @@ -221,7 +221,7 @@ def get_dates_data(
:param :select2b Second filter (could be `playlist:created`, optional)
:param :time_group What is the data grouped by? Can be `days`, `weeks`, `months`, `years`
:param :system What bitmapist should be used?
:param :as_precent If `True` then percents as calculated and shown. Defaults to `True`
:param :as_percent If `True` then percents as calculated and shown. Defaults to `True`
:return A list of day data, formatted like `[[datetime, count], ...]`
"""
num_results = int(num_results)
Expand All @@ -242,6 +242,7 @@ def get_dates_data(

def timedelta_inc(d):
return timedelta(days=d)

# Weeks
elif time_group == "weeks":
fn_get_events = _weeks_events_fn
Expand All @@ -251,6 +252,7 @@ def timedelta_inc(d):

def timedelta_inc(w):
return relativedelta(weeks=w)

# Months
elif time_group == "months":
fn_get_events = _month_events_fn
Expand All @@ -261,6 +263,7 @@ def timedelta_inc(w):

def timedelta_inc(m):
return relativedelta(months=m)

# Years
elif time_group == "years":
fn_get_events = _year_events_fn
Expand Down Expand Up @@ -311,7 +314,7 @@ def timedelta_inc(m):
# Append to result
if both_count == 0:
result.append(0.0)
elif as_precent:
elif as_percent:
result.append((float(both_count) / float(select1_count)) * 100)
else:
result.append(both_count)
Expand Down
8 changes: 4 additions & 4 deletions bitmapist/cohort/tmpl/form_data.mako
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
</dd>

<dd>
As precent:
<select name="as_precent">
<option value="1" ${ 'selected="selected"' if as_precent else '' }>Yes</option>
<option value="0" ${ 'selected="selected"' if not as_precent else '' }>No</option>
As percent:
<select name="as_percent">
<option value="1" ${ 'selected="selected"' if as_percent else '' }>Yes</option>
<option value="0" ${ 'selected="selected"' if not as_percent else '' }>No</option>
</select>
</dd>

Expand Down
4 changes: 2 additions & 2 deletions bitmapist/cohort/tmpl/table_data.mako
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@

## '' denotes no entry
%if data_entry != '':
%if as_precent:
%if as_percent:
<%
color = 'hsla(200, 100%%, 0%%, %s);' % (round(float(data_entry/100)+0.5, 1))
%>
Expand Down Expand Up @@ -110,7 +110,7 @@
%>

<td class="avg_row">
%if as_precent:
%if as_percent:
${ round(average, 2) }%
%else:
${ int(average) }
Expand Down
2 changes: 1 addition & 1 deletion bitmapist/cohort/tmpl/table_data_csv.mako
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ for i in range(2, 15):
if prct == '':
day_results.append('')
else:
if as_precent:
if as_percent:
day_results.append(str(round(prct, 2)))
else:
day_results.append(str(int(prct)))
Expand Down
2 changes: 1 addition & 1 deletion test/test_cohort.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_cohort(select1, select1b, select2, select2b, expected, events):
select2=select2,
select2b=select2b,
time_group="days",
as_precent=1,
as_percent=1,
num_results=1,
num_of_rows=1,
)
Expand Down

0 comments on commit 249f7e1

Please sign in to comment.