Skip to content

Commit

Permalink
Web Widget Analytics fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
devxpy committed Jun 27, 2024
1 parent a1aa3aa commit d7a4bf6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
24 changes: 21 additions & 3 deletions bots/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from django.utils.timesince import timesince

from app_users.models import AppUser
from bots.admin_links import list_related_html_url, change_obj_url
from bots.admin_links import list_related_html_url, change_obj_url, open_in_new_tab
from bots.models import (
FeedbackComment,
CHATML_ROLE_ASSISSTANT,
Expand All @@ -29,11 +29,14 @@
BotIntegrationAnalysisRun,
)
from bots.tasks import create_personal_channels_for_all_members
from daras_ai_v2.fastapi_tricks import get_route_url
from gooeysite.custom_actions import export_to_excel, export_to_csv
from gooeysite.custom_filters import (
related_json_field_summary,
)
from gooeysite.custom_widgets import JSONEditorWidget
from recipes.VideoBots import VideoBotsPage
from routers.root import integrations_stats_route

fb_fields = [
"fb_page_id",
Expand Down Expand Up @@ -160,7 +163,7 @@ class BotIntegrationAdmin(admin.ModelAdmin):
"view_messsages",
"created_at",
"updated_at",
"api_integration_id",
"api_integration_stats_url",
]

fieldsets = [
Expand All @@ -173,7 +176,7 @@ class BotIntegrationAdmin(admin.ModelAdmin):
"published_run",
"billing_account_uid",
"user_language",
"api_integration_id",
"api_integration_stats_url",
],
},
),
Expand Down Expand Up @@ -248,6 +251,21 @@ def view_analysis_results(self, bi: BotIntegration):
html = mark_safe(html)
return html

@admin.display(description="Integration Stats")
def api_integration_stats_url(self, bi: BotIntegration):

integration_id = bi.api_integration_id()
return open_in_new_tab(
url=get_route_url(
integrations_stats_route,
params=dict(
page_slug=VideoBotsPage.slug_versions[-1],
integration_id=integration_id,
),
),
label=integration_id,
)


@admin.register(PublishedRun)
class PublishedRunAdmin(admin.ModelAdmin):
Expand Down
6 changes: 3 additions & 3 deletions bots/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,10 +640,10 @@ def get_active_saved_run(self) -> SavedRun | None:
def get_display_name(self):
return (
(self.wa_phone_number and self.wa_phone_number.as_international)
or self.ig_username
or self.fb_page_name
or self.wa_phone_number_id
or self.fb_page_name
or self.fb_page_id
or self.ig_username
or " | #".join(
filter(None, [self.slack_team_name, self.slack_channel_name])
)
Expand All @@ -656,7 +656,6 @@ def get_display_name(self):

get_display_name.short_description = "Bot"

@admin.display(description="API integraton_id")
def api_integration_id(self):
from routers.bots_api import api_hashids

Expand Down Expand Up @@ -987,6 +986,7 @@ def get_display_name(self):
)
or self.fb_page_id
or self.slack_user_id
or self.web_user_id
)

get_display_name.short_description = "User"
Expand Down
7 changes: 1 addition & 6 deletions recipes/VideoBotsStats.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,7 @@ def calculate_overall_stats(self, bi, run_title, run_url):
rating=Feedback.Rating.RATING_THUMBS_DOWN,
).count()
run_link = f'Powered By: <a href="{run_url}" target="_blank">{run_title}</a>'
connection_detail = (
bi.fb_page_name
or bi.wa_phone_number
or bi.ig_username
or (bi.slack_team_name + " - " + bi.slack_channel_name)
)
connection_detail = bi.get_display_name()
st.markdown(
f"""
- Platform: {Platform(bi.platform).name.capitalize()}
Expand Down

0 comments on commit d7a4bf6

Please sign in to comment.