Skip to content

Commit

Permalink
Change percent to rate in retention metrics API (mastodon#16910)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored and jesseplusplus committed Feb 10, 2022
1 parent 251711d commit 1368d20
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions app/javascript/mastodon/components/admin/Retention.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default class Retention extends React.PureComponent {
</td>

{data[0].data.slice(1).map((retention, i) => {
const average = data.reduce((sum, cohort, k) => cohort.data[i + 1] ? sum + (cohort.data[i + 1].percent - sum)/(k + 1) : sum, 0);
const average = data.reduce((sum, cohort, k) => cohort.data[i + 1] ? sum + (cohort.data[i + 1].rate - sum)/(k + 1) : sum, 0);

return (
<td key={retention.date}>
Expand Down Expand Up @@ -118,8 +118,8 @@ export default class Retention extends React.PureComponent {

{cohort.data.slice(1).map(retention => (
<td key={retention.date}>
<div className={classNames('retention__table__box', `retention__table__box--${roundTo10(retention.percent * 100)}`)}>
<FormattedNumber value={retention.percent} style='percent' />
<div className={classNames('retention__table__box', `retention__table__box--${roundTo10(retention.rate * 100)}`)}>
<FormattedNumber value={retention.rate} style='percent' />
</div>
</td>
))}
Expand Down
4 changes: 2 additions & 2 deletions app/lib/admin/metrics/retention.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Cohort < ActiveModelSerializers::Model
end

class CohortData < ActiveModelSerializers::Model
attributes :date, :percent, :value
attributes :date, :rate, :value
end

def initialize(start_at, end_at, frequency)
Expand Down Expand Up @@ -59,7 +59,7 @@ def cohorts

current_cohort.data << CohortData.new(
date: row['retention_period'],
percent: rate.to_f,
rate: rate.to_f,
value: value.to_s
)
end
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/rest/admin/cohort_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class REST::Admin::CohortSerializer < ActiveModel::Serializer
attributes :period, :frequency

class CohortDataSerializer < ActiveModel::Serializer
attributes :date, :percent, :value
attributes :date, :rate, :value

def date
object.date.iso8601
Expand Down

0 comments on commit 1368d20

Please sign in to comment.