Skip to content

Commit

Permalink
d7, d30 retention in convo admin
Browse files Browse the repository at this point in the history
  • Loading branch information
devxpy committed Nov 7, 2023
1 parent f5e72c5 commit 4124b4a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion bots/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ class ConversationAdmin(admin.ModelAdmin):
"view_messages",
"view_last_active_delta",
"d1",
"d3",
"d7",
"d30",
]
readonly_fields = [
"created_at",
Expand Down
17 changes: 12 additions & 5 deletions bots/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,8 @@ def to_df(self, tz=pytz.timezone(settings.TIME_ZONE)) -> "pd.DataFrame":
convo.last_active_delta().total_seconds() / 3600
),
"D1": convo.d1(),
"D3": convo.d3(),
"D7": convo.d7(),
"D30": convo.d30(),
}
except Message.DoesNotExist:
pass
Expand Down Expand Up @@ -659,11 +660,17 @@ def d1(self):
d1.short_description = "D1"
d1.boolean = True

def d3(self):
return self.last_active_delta() > datetime.timedelta(days=3)
def d7(self):
return self.last_active_delta() > datetime.timedelta(days=7)

d3.short_description = "D3"
d3.boolean = True
d7.short_description = "D7"
d7.boolean = True

def d30(self):
return self.last_active_delta() > datetime.timedelta(days=30)

d30.short_description = "D30"
d30.boolean = True


class MessageQuerySet(models.QuerySet):
Expand Down

0 comments on commit 4124b4a

Please sign in to comment.