Skip to content
This repository has been archived by the owner on Jan 5, 2025. It is now read-only.

Commit

Permalink
Merge pull request #230 from lvalics/main
Browse files Browse the repository at this point in the history
Dashboard feature and Errors page view.
  • Loading branch information
codebanesr authored Jan 25, 2024
2 parents eace1e2 + 6f40337 commit 28abd2f
Show file tree
Hide file tree
Showing 21 changed files with 310 additions and 84 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ dj_backend_server/nginx/ssl/cert.pem
dj_backend_server/nginx/nginx.conf
.vscode
dj_backend_server.code-workspace
.aider*
.aiderignore
6 changes: 5 additions & 1 deletion dj_backend_server/web/enums/common_enums.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from enum import Enum
import random

class ChatBotDefaults(Enum):
NAME = "My First Chatbot"
@staticmethod
def NAME():
random_number = random.randint(1000, 9999)
return f"ChatBot {random_number}"
49 changes: 49 additions & 0 deletions dj_backend_server/web/interfaces/dashboard.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
from django.db.models import Count
from django.db.models.functions import TruncDay
from django.utils import timezone
from web.models.chat_histories import ChatHistory
from web.models.crawled_pages import CrawledPages
from web.models.pdf_data_sources import PdfDataSource
from web.models.website_data_sources import WebsiteDataSource


def get_discussion_counts():
# Aggregate discussion counts per day grouped by session_id
thirty_days_ago = timezone.now() - timezone.timedelta(days=30)
discussion_counts = (
ChatHistory.objects
.filter(created_at__gte=thirty_days_ago)
.values('session_id')
.annotate(created_date=TruncDay('created_at'))
.values('created_date')
Expand All @@ -20,3 +26,46 @@ def get_discussion_counts():
return formatted_counts


def get_data_source_counts():
# Aggregate data source counts per day
thirty_days_ago = timezone.now() - timezone.timedelta(days=30)
crawled_pages_counts = (
CrawledPages.objects
.filter(created_at__gte=thirty_days_ago)
.annotate(created_date=TruncDay('created_at'))
.values('created_date')
.annotate(count=Count('id'))
.order_by('created_date')
)
pdf_data_sources_counts = (
PdfDataSource.objects
.filter(created_at__gte=thirty_days_ago)
.annotate(created_date=TruncDay('created_at'))
.values('created_date')
.annotate(count=Count('id'))
.order_by('created_date')
)
website_data_sources_counts = (
WebsiteDataSource.objects
.filter(created_at__gte=thirty_days_ago)
.annotate(created_date=TruncDay('created_at'))
.values('created_date')
.annotate(count=Count('id'))
.order_by('created_date')
)
# Combine and format the counts
all_dates = sorted(set(
[cp['created_date'] for cp in crawled_pages_counts] +
[pdf['created_date'] for pdf in pdf_data_sources_counts] +
[ws['created_date'] for ws in website_data_sources_counts]
))
formatted_counts = []
for date in all_dates:
formatted_counts.append({
'date': str(date.date()),
'crawled_pages': next((cp['count'] for cp in crawled_pages_counts if cp['created_date'] == date), 0),
'pdf_data_sources': next((pdf['count'] for pdf in pdf_data_sources_counts if pdf['created_date'] == date), 0),
'website_data_sources': next((ws['count'] for ws in website_data_sources_counts if ws['created_date'] == date), 0),
})
return formatted_counts

24 changes: 14 additions & 10 deletions dj_backend_server/web/templates/create_user.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ <h1 class="text-3xl text-slate-800 font-bold mb-6">Create a new user</h1>
<p style="margin-bottom: 2rem">Please note down the username and password to send to the user.
They will be required to change these credentials upon their first login.</p>

{% if error_message %}
<div class="bg-danger text-sm text-white p-3" role="alert">
<span class="font-bold">Error:</span> {{ error_message }}
</div>
{% endif %}

{% if error_messages %}
<div class="bg-danger text-sm text-white p-3" role="alert">
{% for message in error_messages %}
<div><span class="font-bold">Error:</span> {{ message }}</div>
{% endfor %}
</div>
{% endif %}



<!-- Form -->
Expand All @@ -31,7 +35,7 @@ <h1 class="text-3xl text-slate-800 font-bold mb-6">Create a new user</h1>
<div>
<label class="block text-sm font-medium mb-1" for="Username">Username
<span class="text-rose-500">*</span></label>
<input type="text" id="simpleinput" class="form-input">
<input type="text" id="username" name="username" class="form-input">
</div>

</li>
Expand All @@ -40,7 +44,7 @@ <h1 class="text-3xl text-slate-800 font-bold mb-6">Create a new user</h1>

<div>
<label class="block text-sm font-medium mb-1" for="first_name">First name
<span class="text-rose-500">*</span></label>
</label>
<input id="first_name" class="form-input w-full" type="text" name="first_name">
</div>

Expand All @@ -50,7 +54,7 @@ <h1 class="text-3xl text-slate-800 font-bold mb-6">Create a new user</h1>

<div>
<label class="block text-sm font-medium mb-1" for="last_name">Last name
<span class="text-rose-500">*</span></label>
</label>
<input id="last_name" class="form-input w-full" type="text" name="last_name">

</div>
Expand All @@ -71,7 +75,7 @@ <h1 class="text-3xl text-slate-800 font-bold mb-6">Create a new user</h1>
<div>
<label class="block text-sm font-medium mb-1" for="password">Password
<span class="text-rose-500">*</span></label>
<input id="password" class="form-input w-full" type="password" name="password">
<input id="password" class="form-input w-full" type="password" name="password" required>
<p>Suggested password (user will change) <strong>{{ SUGGESTEDPASS }}</strong></p>
</div>

Expand All @@ -82,7 +86,7 @@ <h1 class="text-3xl text-slate-800 font-bold mb-6">Create a new user</h1>
<div>
<label class="block text-sm font-medium mb-1" for="check_password">Check password
<span class="text-rose-500">*</span></label>
<input id="check_password" class="form-input w-full" type="password" name="check_password">
<input id="check_password" class="form-input w-full" type="password" name="check_password" required>
</div>

</li>
Expand Down
77 changes: 77 additions & 0 deletions dj_backend_server/web/templates/errors_check.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{% extends 'layout/app.html' %}
{% block content %}
<main class="p-6">
<div class="flex flex-col gap-6">
<div class="card">

<div class="container mx-auto p-4">
<h1 class="text-xl font-bold mb-4">Error Check</h1>
<table class="min-w-full leading-normal">
<thead>
<tr>
<th
class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">
Payload
</th>
<th
class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">
UUID
</th>
<th
class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">
Exception
</th>
<th
class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">
Failed At
</th>
</tr>
</thead>
<tbody>
{% for error in errors %}
<tr>
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm">
{{ error.payload }}
</td>
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm">
{{ error.uuid }}
</td>
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm">
{{ error.exception }}
</td>
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm">
{{ error.failed_at }}
</td>
</tr>
{% empty %}
<tr>
<td colspan="4" class="px-5 py-5 border-b border-gray-200 bg-white text-sm text-center">
No errors found.
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="pagination">
<span class="step-links">
{% if errors.has_previous %}
<a href="?page=1">&laquo; first</a>
<a href="?page={{ errors.previous_page_number }}">previous</a>
{% endif %}
<span class="current">
Page {{ errors.number }} of {{ errors.paginator.num_pages }}.
</span>
{% if errors.has_next %}
<a href="?page={{ errors.next_page_number }}">next</a>
<a href="?page={{ errors.paginator.num_pages }}">last &raquo;</a>
{% endif %}
</span>
</div>

</div>

</div>
</div>

</main>
{% endblock %}
39 changes: 36 additions & 3 deletions dj_backend_server/web/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h1 class="text-2xl md:text-3xl text-slate-800 font-bold">My chatbots ✨</h1>
<div class="grid xl:grid-cols-4 md:grid-cols-2 gap-6 mb-6" style="padding-top: 20px;">
<div class="px-5 py-3 bg-indigo-50 border border-indigo-100 rounded-sm text-center xl:text-left xl:flex xl:flex-wrap xl:justify-between xl:items-center">
<div class="bg-primary/25 text-primary text-sm p-3" role="alert">
<span class="font-bold">Numer of bots</span> 5
<span class="font-bold">Numer of bots</span> {{ chatbots.count }}
</div>
<div class="text-slate-800 font-semibold mb-2 xl:mb-0">
<button type="button" class="btn bg-primary text-white text-lg w-full"><a href="{% url 'onboarding.welcome' %}">Create new chatbot <span class="uil uil-chat-bubble-user"></span></a></button>
Expand Down Expand Up @@ -65,7 +65,23 @@ <h4 class="card-title mb-4">Statistics of discussions in the last days</h4>
</div>
</div>
</div>

<div class="grid lg:grid-cols-3 gap-6 mb-6">
<div class="lg:col-span-2">
<div class="card">
<div class="p-5">
<div class="grid lg:grid-cols-3 gap-5">
<div class="lg:col-span-3">
<div class="flex justify-between items-center">
<h4 class="card-title mb-4">Data Sources Added Over Time</h4>
</div>
<div id="morris_data_sources_counts" class="morris-chart"></div>
</div>
</div>
</div>
</div>
</div>
</div>




Expand Down Expand Up @@ -94,7 +110,6 @@ <h4 class="card-title mb-4">Statistics of discussions in the last days</h4>
$(function () {
'use strict';
var discussionCountsData = JSON.parse('{{ discussion_counts_json }}');
console.log(discussionCountsData);
if ($("#morris_discussion_counts").length) {
Morris.Bar({
element: 'morris_discussion_counts',
Expand All @@ -109,6 +124,24 @@ <h4 class="card-title mb-4">Statistics of discussions in the last days</h4>
labels: ['Discussions']
});
}

var dataSourcesCountsData = JSON.parse('{{ data_sources_counts_json }}');
console.log(dataSourcesCountsData);
if ($("#morris_data_sources_counts").length) {
Morris.Bar({
element: 'morris_data_sources_counts',
barColors: ['#ffad46', '#00b19d', '#ff5b5b'],
data: dataSourcesCountsData,
xkey: 'date',
ykeys: ['crawled_pages', 'pdf_data_sources', 'website_data_sources'],
hideHover: 'auto',
gridLineColor: '#eef0f2',
resize: true,
barSizeRatio: 0.4,
labels: ['Crawled Pages', 'PDF Data Sources', 'Website Data Sources']
});
}

});
</script>

Expand Down
12 changes: 10 additions & 2 deletions dj_backend_server/web/templates/layout/sidebar-bot-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
<!--- Menu -->
<div data-simplebar>
<ul class="menu">
<li class="menu-title">Menu</li>

<li class="menu-item">
<a href="{{ APP_URL }}" class="menu-link">
<span class="menu-icon"><i class="uil uil-estate"></i></span>
<span class="menu-text"> Dashboard </span>
</a>
</li>

{% if request.resolver_match.kwargs.id %}
<li class="menu-title">Chatbot</li>
<li class="menu-item">
<a href="{% url 'chatbot.settings-theme' id=request.resolver_match.kwargs.id %}" class="menu-link">
<span class="menu-icon"><i class="uil uil-comment-alt-share"></i></span>
Expand Down Expand Up @@ -47,12 +47,19 @@
</li>
{% endif %}
{% if user.is_superuser %}
<li class="menu-title">Super Admin</li>
<li class="menu-item">
<a class="menu-link" href="{% url 'checkerrors' %}">
<span class="menu-icon"><i class="uil uil-exclamation-triangle"></i></span>
<span class="menu-text"> Errors check </span></a>
</li>
<li class="menu-item">
<a class="menu-link" href="{% url 'createuser' %}">
<span class="menu-icon"><i class="uil uil-user-plus"></i></span>
<span class="menu-text"> Create user </span></a>
</li>
{% endif %}
<li class="menu-title">User</li>
<li class="menu-item">
<a class="menu-link" href="{% url 'modify_user' %}">
<span class="menu-icon"><i class="uil uil-user-arrows"></i></span>
Expand All @@ -62,6 +69,7 @@




</ul>
</div>
</div>
Expand Down
7 changes: 5 additions & 2 deletions dj_backend_server/web/templates/modify_user.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h1 class="text-3xl text-slate-800 font-bold mb-6">Modify your user data</h1>

<div>
<label class="block text-sm font-medium mb-1" for="first_name">First name
<span class="text-rose-500">*</span></label>
</label>
<input id="first_name" class="form-input w-full" type="text" name="first_name" value="{{ user.first_name }}">
</div>

Expand All @@ -39,7 +39,7 @@ <h1 class="text-3xl text-slate-800 font-bold mb-6">Modify your user data</h1>

<div>
<label class="block text-sm font-medium mb-1" for="last_name">Last name
<span class="text-rose-500">*</span></label>
</label>
<input id="last_name" class="form-input w-full" type="text" name="last_name" value="{{ user.last_name }}">
</div>

Expand Down Expand Up @@ -77,6 +77,9 @@ <h1 class="text-3xl text-slate-800 font-bold mb-6">Modify your user data</h1>
</li>
<!-- List item -->
</ul>
<div class="bg-secondary/25 text-secondary text-sm p-3" role="alert">
<span class="font-bold">Password and Check password</span> do not need to be sent if they are not changing.
</div>
</div>
<div class="flex items-center justify-between">
<button type="submit" class="btn bg-primary text-white py-2 px-3">Update user -&gt;</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ <h1 class="text-3xl text-slate-800 font-bold mb-6">Upload files as sources ✨</
</div>
<div class="flex items-center justify-between">
<a class="text-sm underline hover:no-underline" href="{% url 'onboarding.welcome' %}">&lt;- Back</a>
<button form="pdfCreate" type="submit" class="btn bg-indigo-500 hover:bg-indigo-600 text-white ml-auto">Next Step -&gt;</button>
<button form="pdfCreate" type="submit" class="btn bg-primary text-white py-2 px-3">Next Step -&gt;</button>
</div>
</form>
</div>
Expand Down
Loading

0 comments on commit 28abd2f

Please sign in to comment.