analytics-log prototype

This commit is contained in:
Roman Davydov
2023-10-31 23:36:34 +03:00
parent 06b985742d
commit 68bf8558fd
6 changed files with 83 additions and 5 deletions

View File

@@ -191,7 +191,7 @@ class TwitchChannelPointsMiner:
from TwitchChannelPointsMiner.classes.AnalyticsServer import AnalyticsServer
http_server = AnalyticsServer(
host=host, port=port, refresh=refresh, days_ago=days_ago
host=host, port=port, refresh=refresh, days_ago=days_ago, username=self.username
)
http_server.daemon = True
http_server.name = "Analytics Thread"

View File

@@ -230,6 +230,7 @@ class AnalyticsServer(Thread):
port: int = 5000,
refresh: int = 5,
days_ago: int = 7,
username: str = None
):
super(AnalyticsServer, self).__init__()
@@ -239,6 +240,17 @@ class AnalyticsServer(Thread):
self.port = port
self.refresh = refresh
self.days_ago = days_ago
self.username = username
def generate_log():
logs_path = os.path.join(Path().absolute(), "logs")
log_file_path = os.path.join(logs_path, f"{username}.log")
try:
with open(log_file_path, "r") as log_file:
log_content = log_file.read()
return Response(log_content, status=200, mimetype="text/plain")
except FileNotFoundError:
return Response("Log file not found.", status=404, mimetype="text/plain")
self.app = Flask(
__name__,
@@ -259,6 +271,8 @@ class AnalyticsServer(Thread):
)
self.app.add_url_rule("/json_all", "json_all",
json_all, methods=["GET"])
self.app.add_url_rule(
"/log", "log", generate_log, methods=["GET"])
def run(self):
logger.info(

View File

@@ -27,14 +27,15 @@
<div class="container has-text-centered" style="height: 100vh;">
<div class="columns" id="header">
<div class="column has-text-right">
<img style="margin-top: -20px;" width="600px" src="{{url_for('static', filename='banner.png')}}"
alt="banner">
<a href="https://github.com/rdavydov/Twitch-Channel-Points-Miner-v2" target="_blank"><img
style="margin-top: -20px;" width="600px" src="{{url_for('static', filename='banner.png')}}"
alt="banner"></a>
</div>
<div class="column is-4 has-text-left" style="margin-top: 35px;">
<table>
<tr>
<td>Tkd-Alex</td>
<td>rdavydov</td>
<td><a stylehref="https://github.com/Tkd-Alex" target="_blank">Tkd-Alex</a></td>
<td><a href="https://github.com/rdavydov" target="_blank">rdavydov</a></td>
</tr>
<tr>
<td><a href="https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/blob/master/LICENSE">
@@ -152,6 +153,10 @@
<input class="input" type="date" id="endDate">
</div>
<div class="column has-text-right" style="margin: auto">
<label class="checkbox checkbox-label">
Log
<input type="checkbox" checked="true" id="log">
</label>
<label class="checkbox checkbox-label">
Annotations
<input type="checkbox" checked="true" id="annotations">
@@ -176,6 +181,14 @@
<div class="box" id="chart" style="padding: 0.30rem;"></div>
</div>
</div>
<div class="columns">
<div class="column is-12">
<div class="box" id="log-box" style="padding: 0.30rem;">
<pre
id="log-content">In your run.py file set save=True in logger_settings to save logs to a file</pre>
</div>
</div>
</div>
</div>
</body>

View File

@@ -2,6 +2,12 @@ body {
background: #343E59;
color: #fff;
}
a {
color: #fff;
}
a:hover {
color: #f9826c;
}
.box {
background-color: #2B2D3E;
}
@@ -27,3 +33,7 @@ body {
.checkbox:hover{
color: #f9826c;
}
#log-content {
color: #fff;
background-color: #2B2D3E;
}

View File

@@ -91,6 +91,35 @@ var startDate = new Date();
startDate.setDate(startDate.getDate() - daysAgo);
var endDate = new Date();
// Function to get the full log content
function getFullLog() {
$.get("/log", function (data) {
// Update the log content with the full log
$("#log-content").text(data);
// Scroll to the bottom of the log content
$("#log-content").scrollTop($("#log-content")[0].scrollHeight);
});
}
// Function to continuously update the log content
function updateLogContent() {
// Get the current log content
var currentLogContent = $("#log-content").text();
// Fetch the updated log content
$.get("/log", function (data) {
// If the log content has changed, update the displayed log
if (data !== currentLogContent) {
// Update the log content with the new log data
$("#log-content").text(data);
// Scroll to the bottom of the log content
$("#log-content").scrollTop($("#log-content")[0].scrollHeight);
}
// Schedule the next update after 1 second
setTimeout(updateLogContent, 1000);
});
}
$(document).ready(function () {
// Retrieve the saved header visibility preference from localStorage
var headerVisibility = localStorage.getItem('headerVisibility');
@@ -153,6 +182,11 @@ $(document).ready(function () {
updateAnnotations();
toggleDarkMode();
// Get the full log content when the document is ready
getFullLog();
// Start continuously updating the log content
updateLogContent();
});
function formatDate(date) {

View File

@@ -53,3 +53,10 @@ a {
::-webkit-scrollbar-thumb:hover {
background-color: #a8bbbf;
}
#log-content {
text-align: left;
white-space: pre-wrap;
max-height: 500px;
padding: 0;
}