Files
redux-scraper/app/views/telegram_bot_logs/show.html.erb
2025-08-05 05:05:21 +00:00

277 lines
14 KiB
Plaintext

<div class="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8">
<div class="sm:flex sm:items-center">
<div class="sm:flex-auto">
<h1 class="text-2xl font-semibold text-slate-900">Telegram Bot Log Details</h1>
<p class="mt-2 text-sm text-slate-700">
Detailed view of Telegram bot interaction #<%= @telegram_bot_log.id %>
</p>
</div>
<div class="mt-4 sm:ml-16 sm:mt-0 sm:flex-none">
<%= link_to "← Back to Logs", telegram_bot_logs_path,
class: "bg-slate-500 hover:bg-slate-700 text-white font-bold py-2 px-4 rounded" %>
</div>
</div>
<div class="mt-6 grid grid-cols-1 gap-6 lg:grid-cols-2">
<!-- User Information -->
<div class="bg-white shadow sm:rounded-lg">
<div class="px-4 py-5 sm:p-6">
<h3 class="text-lg font-medium leading-6 text-slate-900">User Information</h3>
<div class="mt-4 space-y-3">
<div class="flex justify-between">
<dt class="text-sm font-medium text-slate-500">Display Name</dt>
<dd class="text-sm text-slate-900 font-medium"><%= @telegram_bot_log.user_display_name %></dd>
</div>
<div class="flex justify-between">
<dt class="text-sm font-medium text-slate-500">Telegram User ID</dt>
<dd class="text-sm text-slate-900 font-mono"><%= @telegram_bot_log.telegram_user_id %></dd>
</div>
<% if @telegram_bot_log.telegram_username.present? %>
<div class="flex justify-between">
<dt class="text-sm font-medium text-slate-500">Username</dt>
<dd class="text-sm text-slate-900">@<%= @telegram_bot_log.telegram_username %></dd>
</div>
<% end %>
<% if @telegram_bot_log.telegram_first_name.present? %>
<div class="flex justify-between">
<dt class="text-sm font-medium text-slate-500">First Name</dt>
<dd class="text-sm text-slate-900"><%= @telegram_bot_log.telegram_first_name %></dd>
</div>
<% end %>
<% if @telegram_bot_log.telegram_last_name.present? %>
<div class="flex justify-between">
<dt class="text-sm font-medium text-slate-500">Last Name</dt>
<dd class="text-sm text-slate-900"><%= @telegram_bot_log.telegram_last_name %></dd>
</div>
<% end %>
<div class="flex justify-between">
<dt class="text-sm font-medium text-slate-500">Chat ID</dt>
<dd class="text-sm text-slate-900 font-mono"><%= @telegram_bot_log.telegram_chat_id %></dd>
</div>
</div>
</div>
</div>
<!-- Request Information -->
<div class="bg-white shadow sm:rounded-lg">
<div class="px-4 py-5 sm:p-6">
<h3 class="text-lg font-medium leading-6 text-slate-900">Request Information</h3>
<div class="mt-4 space-y-3">
<div class="flex justify-between">
<dt class="text-sm font-medium text-slate-500">Status</dt>
<dd class="text-sm">
<% status_color = case @telegram_bot_log.status
when "success"
"bg-green-100 text-green-800"
when "error"
"bg-red-100 text-red-800"
when "no_results"
"bg-yellow-100 text-yellow-800"
when "invalid_image"
"bg-orange-100 text-orange-800"
else
"bg-slate-100 text-slate-800"
end %>
<span class="<%= status_color %> inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium">
<%= @telegram_bot_log.status.humanize %>
</span>
</dd>
</div>
<div class="flex justify-between">
<dt class="text-sm font-medium text-slate-500">Timestamp</dt>
<dd class="text-sm text-slate-900">
<div><%= @telegram_bot_log.request_timestamp.strftime("%B %d, %Y at %I:%M:%S %p") %></div>
<div class="text-xs text-slate-500"><%= time_ago_in_words(@telegram_bot_log.request_timestamp) %> ago</div>
</dd>
</div>
<div class="flex justify-between">
<dt class="text-sm font-medium text-slate-500">Search Results</dt>
<dd class="text-sm text-slate-900">
<span class="font-medium"><%= @telegram_bot_log.search_results_count %></span>
<% if @telegram_bot_log.search_results_count > 0 %>
<span class="text-green-600 text-xs ml-1">matches found</span>
<% else %>
<span class="text-slate-400 text-xs ml-1">no matches</span>
<% end %>
</dd>
</div>
<% if @telegram_bot_log.error_message.present? %>
<div class="space-y-1">
<dt class="text-sm font-medium text-slate-500">Error Message</dt>
<dd class="text-sm text-red-700 bg-red-50 p-2 rounded border">
<%= @telegram_bot_log.error_message %>
</dd>
</div>
<% end %>
</div>
</div>
</div>
</div>
<!-- Performance Metrics -->
<% if @telegram_bot_log.has_performance_metrics? %>
<div class="mt-6 bg-white shadow sm:rounded-lg">
<div class="px-4 py-5 sm:p-6">
<h3 class="text-lg font-medium leading-6 text-slate-900">Performance Metrics</h3>
<div class="mt-4 grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-5">
<div class="bg-blue-50 p-4 rounded-lg">
<div class="text-sm font-medium text-slate-500">Download Time</div>
<div class="text-xl font-bold text-blue-700 font-mono">
<%= sprintf("%.3f", @telegram_bot_log.download_time) %>s
</div>
<div class="text-xs text-blue-600">From Telegram</div>
</div>
<% if @telegram_bot_log.image_processing_time.present? %>
<div class="bg-purple-50 p-4 rounded-lg">
<div class="text-sm font-medium text-slate-500">Processing Time</div>
<div class="text-xl font-bold text-purple-700 font-mono">
<%= sprintf("%.3f", @telegram_bot_log.image_processing_time) %>s
</div>
<div class="text-xs text-purple-600">File handling</div>
</div>
<% end %>
<div class="bg-yellow-50 p-4 rounded-lg">
<div class="text-sm font-medium text-slate-500">Fingerprint Time</div>
<div class="text-xl font-bold text-yellow-700 font-mono">
<%= sprintf("%.3f", @telegram_bot_log.fingerprint_computation_time) %>s
</div>
<div class="text-xs text-yellow-600">Image analysis</div>
</div>
<div class="bg-green-50 p-4 rounded-lg">
<div class="text-sm font-medium text-slate-500">Search Time</div>
<div class="text-xl font-bold text-green-700 font-mono">
<%= sprintf("%.3f", @telegram_bot_log.search_computation_time) %>s
</div>
<div class="text-xs text-green-600">Find matches</div>
</div>
<div class="bg-slate-50 p-4 rounded-lg">
<div class="text-sm font-medium text-slate-500">Total Request Time</div>
<div class="text-xl font-bold font-mono
<%= @telegram_bot_log.total_request_time && @telegram_bot_log.total_request_time > 1.0 ? 'text-red-600' : 'text-slate-700' %>">
<%= @telegram_bot_log.total_request_time ? sprintf("%.3f", @telegram_bot_log.total_request_time) : 'N/A' %>s
</div>
<div class="text-xs
<%= @telegram_bot_log.total_request_time && @telegram_bot_log.total_request_time > 1.0 ? 'text-red-500' : 'text-slate-500' %>">
<%= @telegram_bot_log.total_request_time && @telegram_bot_log.total_request_time > 1.0 ? 'Slow request' : 'Normal speed' %>
</div>
</div>
</div>
</div>
</div>
<% end %>
<!-- Processed Image -->
<% if @telegram_bot_log.processed_image.present? %>
<div class="mt-6 bg-white shadow sm:rounded-lg">
<div class="px-4 py-5 sm:p-6">
<h3 class="text-lg font-medium leading-6 text-slate-900">Processed Image</h3>
<div class="mt-4 space-y-3">
<div class="flex justify-between">
<dt class="text-sm font-medium text-slate-500">Content Type</dt>
<dd class="text-sm text-slate-900 font-mono"><%= @telegram_bot_log.processed_image.content_type %></dd>
</div>
<div class="flex justify-between">
<dt class="text-sm font-medium text-slate-500">File Size</dt>
<dd class="text-sm text-slate-900"><%= number_to_human_size(@telegram_bot_log.processed_image.size_bytes) %></dd>
</div>
<div class="flex justify-between">
<dt class="text-sm font-medium text-slate-500">SHA256 Hash</dt>
<dd class="text-sm text-slate-900 font-mono break-all"><%= @telegram_bot_log.processed_image.sha256.unpack1('H*') %></dd>
</div>
<div class="flex justify-between">
<dt class="text-sm font-medium text-slate-500">Created</dt>
<dd class="text-sm text-slate-900">
<%= @telegram_bot_log.processed_image.created_at.strftime("%B %d, %Y at %I:%M:%S %p") %>
<div class="text-xs text-slate-500"><%= time_ago_in_words(@telegram_bot_log.processed_image.created_at) %> ago</div>
</dd>
</div>
</div>
</div>
</div>
<% end %>
<!-- Response Data -->
<% if @telegram_bot_log.response_data.present? && @telegram_bot_log.response_data.any? %>
<div class="mt-6 bg-white shadow sm:rounded-lg">
<div class="px-4 py-5 sm:p-6">
<h3 class="text-lg font-medium leading-6 text-slate-900">Response Data</h3>
<div class="mt-4">
<% if @telegram_bot_log.status == "success" && @telegram_bot_log.response_data["results"].present? %>
<!-- Success Response with Results -->
<div class="space-y-4">
<div class="grid grid-cols-2 gap-4 text-sm">
<div class="flex justify-between">
<span class="font-medium text-slate-500">Matches Found:</span>
<span class="text-slate-900"><%= @telegram_bot_log.response_data["matches"] %></span>
</div>
<div class="flex justify-between">
<span class="font-medium text-slate-500">Similarity Threshold:</span>
<span class="text-slate-900"><%= @telegram_bot_log.response_data["threshold"] %>%</span>
</div>
</div>
<div class="border-t border-slate-200 pt-4">
<h4 class="font-medium text-slate-900 mb-3">Search Results</h4>
<div class="space-y-2">
<% @telegram_bot_log.response_data["results"].each_with_index do |result, index| %>
<div class="bg-slate-50 p-3 rounded border">
<div class="flex justify-between items-start">
<div>
<div class="text-sm font-medium text-slate-900">
Result #<%= index + 1 %>
</div>
<% if result["post_id"] %>
<div class="text-xs text-slate-500">Post ID: <%= result["post_id"] %></div>
<% end %>
</div>
<div class="text-right">
<div class="text-sm font-bold
<%= result["similarity"] >= 95 ? 'text-green-600' : result["similarity"] >= 90 ? 'text-yellow-600' : 'text-red-600' %>">
<%= result["similarity"] %>% similar
</div>
</div>
</div>
<% if result["url"] %>
<div class="mt-2">
<%= link_to result["url"], result["url"],
target: "_blank",
class: "text-blue-600 hover:text-blue-800 text-xs break-all" %>
</div>
<% end %>
</div>
<% end %>
</div>
</div>
</div>
<% else %>
<!-- Raw JSON Response -->
<div class="bg-slate-50 p-4 rounded-lg border">
<pre class="text-sm text-slate-900 whitespace-pre-wrap break-words"><%= JSON.pretty_generate(@telegram_bot_log.response_data) %></pre>
</div>
<% end %>
</div>
</div>
</div>
<% end %>
<!-- System Information -->
<div class="mt-6 bg-white shadow sm:rounded-lg">
<div class="px-4 py-5 sm:p-6">
<h3 class="text-lg font-medium leading-6 text-slate-900">System Information</h3>
<div class="mt-4 space-y-3">
<div class="flex justify-between">
<dt class="text-sm font-medium text-slate-500">Record ID</dt>
<dd class="text-sm text-slate-900 font-mono"><%= @telegram_bot_log.id %></dd>
</div>
<div class="flex justify-between">
<dt class="text-sm font-medium text-slate-500">Created At</dt>
<dd class="text-sm text-slate-900">
<%= @telegram_bot_log.created_at.strftime("%B %d, %Y at %I:%M:%S %p") %>
<div class="text-xs text-slate-500"><%= time_ago_in_words(@telegram_bot_log.created_at) %> ago</div>
</dd>
</div>
<div class="flex justify-between">
<dt class="text-sm font-medium text-slate-500">Last Updated</dt>
<dd class="text-sm text-slate-900">
<%= @telegram_bot_log.updated_at.strftime("%B %d, %Y at %I:%M:%S %p") %>
<div class="text-xs text-slate-500"><%= time_ago_in_words(@telegram_bot_log.updated_at) %> ago</div>
</dd>
</div>
</div>
</div>
</div>
</div>