|
|
<!DOCTYPE html> |
|
|
<html lang="ko"> |
|
|
<head> |
|
|
<script type="text/javascript"> |
|
|
(function(c,l,a,r,i,t,y){ |
|
|
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)}; |
|
|
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i; |
|
|
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y); |
|
|
})(window, document, "clarity", "script", "ujskfvh0bu"); |
|
|
</script> |
|
|
<meta charset="UTF-8"> |
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|
|
<title>ํ ํฐ ์ฌ์ฉ๋ ํต๊ณ - SOY NV AI</title> |
|
|
<link rel="preconnect" href="https://fonts.googleapis.com" crossorigin> |
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet"> |
|
|
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script> |
|
|
<style> |
|
|
* { |
|
|
margin: 0; |
|
|
padding: 0; |
|
|
box-sizing: border-box; |
|
|
} |
|
|
|
|
|
body { |
|
|
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; |
|
|
background: #f8f9fa; |
|
|
color: #202124; |
|
|
} |
|
|
|
|
|
.header { |
|
|
background: white; |
|
|
border-bottom: 1px solid #dadce0; |
|
|
padding: 16px 24px; |
|
|
display: flex; |
|
|
align-items: center; |
|
|
justify-content: space-between; |
|
|
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1); |
|
|
overflow: visible; |
|
|
position: relative; |
|
|
z-index: 100; |
|
|
} |
|
|
|
|
|
.header-title { |
|
|
font-size: 20px; |
|
|
font-weight: 500; |
|
|
display: flex; |
|
|
align-items: center; |
|
|
gap: 12px; |
|
|
} |
|
|
|
|
|
.header-actions { |
|
|
display: flex; |
|
|
gap: 8px; |
|
|
align-items: center; |
|
|
flex-wrap: wrap; |
|
|
position: relative; |
|
|
z-index: 101; |
|
|
} |
|
|
|
|
|
|
|
|
.dropdown { |
|
|
position: relative; |
|
|
display: inline-block; |
|
|
z-index: 10001; |
|
|
} |
|
|
|
|
|
|
|
|
.dropdown::after { |
|
|
content: ''; |
|
|
position: absolute; |
|
|
left: 0; |
|
|
right: 0; |
|
|
top: 100%; |
|
|
height: 8px; |
|
|
} |
|
|
|
|
|
.dropdown-toggle { |
|
|
padding: 8px 16px; |
|
|
background: #f1f3f4; |
|
|
color: #202124; |
|
|
border: none; |
|
|
border-radius: 6px; |
|
|
font-size: 14px; |
|
|
font-weight: 500; |
|
|
cursor: pointer; |
|
|
transition: all 0.2s; |
|
|
display: flex; |
|
|
align-items: center; |
|
|
gap: 6px; |
|
|
} |
|
|
|
|
|
.dropdown-toggle:hover { |
|
|
background: #e8eaed; |
|
|
} |
|
|
|
|
|
.dropdown-toggle::after { |
|
|
content: 'โผ'; |
|
|
font-size: 10px; |
|
|
transition: transform 0.2s; |
|
|
} |
|
|
|
|
|
.dropdown:hover .dropdown-toggle::after { |
|
|
transform: rotate(180deg); |
|
|
} |
|
|
|
|
|
.dropdown-menu { |
|
|
position: absolute; |
|
|
top: calc(100% + 4px); |
|
|
left: 0; |
|
|
margin-top: 0; |
|
|
background: white; |
|
|
border: 1px solid #dadce0; |
|
|
border-radius: 6px; |
|
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); |
|
|
min-width: 200px; |
|
|
opacity: 0; |
|
|
visibility: hidden; |
|
|
transform: translateY(-8px); |
|
|
transition: all 0.2s ease; |
|
|
z-index: 10002; |
|
|
padding: 4px 0; |
|
|
pointer-events: none; |
|
|
white-space: nowrap; |
|
|
} |
|
|
|
|
|
.dropdown:hover .dropdown-menu { |
|
|
opacity: 1; |
|
|
visibility: visible; |
|
|
transform: translateY(0); |
|
|
pointer-events: auto; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.dropdown-item { |
|
|
display: block; |
|
|
padding: 10px 16px; |
|
|
color: #202124; |
|
|
text-decoration: none; |
|
|
font-size: 14px; |
|
|
transition: background 0.2s; |
|
|
} |
|
|
|
|
|
.dropdown-item:hover { |
|
|
background: #f8f9fa; |
|
|
} |
|
|
|
|
|
.dropdown-item:first-child { |
|
|
border-top-left-radius: 6px; |
|
|
border-top-right-radius: 6px; |
|
|
} |
|
|
|
|
|
.dropdown-item:last-child { |
|
|
border-bottom-left-radius: 6px; |
|
|
border-bottom-right-radius: 6px; |
|
|
} |
|
|
|
|
|
.menu-toggle { |
|
|
display: none; |
|
|
background: none; |
|
|
border: none; |
|
|
font-size: 24px; |
|
|
cursor: pointer; |
|
|
padding: 8px; |
|
|
color: #202124; |
|
|
} |
|
|
|
|
|
.mobile-menu { |
|
|
display: none; |
|
|
position: fixed; |
|
|
top: 0; |
|
|
left: 0; |
|
|
right: 0; |
|
|
bottom: 0; |
|
|
background: rgba(0, 0, 0, 0.5); |
|
|
z-index: 1000; |
|
|
} |
|
|
|
|
|
.mobile-menu.active { |
|
|
display: block; |
|
|
} |
|
|
|
|
|
.mobile-menu-content { |
|
|
position: fixed; |
|
|
top: 0; |
|
|
right: -100%; |
|
|
width: 280px; |
|
|
max-width: 80%; |
|
|
height: 100%; |
|
|
background: white; |
|
|
box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1); |
|
|
transition: right 0.3s ease; |
|
|
overflow-y: auto; |
|
|
z-index: 1001; |
|
|
} |
|
|
|
|
|
.mobile-menu.active .mobile-menu-content { |
|
|
right: 0; |
|
|
} |
|
|
|
|
|
.mobile-menu-header { |
|
|
padding: 16px 20px; |
|
|
border-bottom: 1px solid #dadce0; |
|
|
display: flex; |
|
|
justify-content: space-between; |
|
|
align-items: center; |
|
|
background: white; |
|
|
position: sticky; |
|
|
top: 0; |
|
|
z-index: 10; |
|
|
} |
|
|
|
|
|
.mobile-menu-title { |
|
|
font-size: 18px; |
|
|
font-weight: 500; |
|
|
} |
|
|
|
|
|
.mobile-menu-close { |
|
|
background: none; |
|
|
border: none; |
|
|
font-size: 28px; |
|
|
cursor: pointer; |
|
|
color: #202124; |
|
|
padding: 0; |
|
|
width: 32px; |
|
|
height: 32px; |
|
|
display: flex; |
|
|
align-items: center; |
|
|
justify-content: center; |
|
|
} |
|
|
|
|
|
.mobile-menu-user { |
|
|
padding: 12px 20px; |
|
|
background: #f8f9fa; |
|
|
border-bottom: 1px solid #dadce0; |
|
|
font-size: 14px; |
|
|
color: #5f6368; |
|
|
} |
|
|
|
|
|
.mobile-menu-items { |
|
|
padding: 8px 0; |
|
|
} |
|
|
|
|
|
.mobile-menu-item { |
|
|
display: block; |
|
|
padding: 12px 20px; |
|
|
color: #202124; |
|
|
text-decoration: none; |
|
|
font-size: 14px; |
|
|
transition: background 0.2s; |
|
|
} |
|
|
|
|
|
.mobile-menu-item:hover { |
|
|
background: #f8f9fa; |
|
|
} |
|
|
|
|
|
.btn { |
|
|
padding: 8px 16px; |
|
|
border: none; |
|
|
border-radius: 6px; |
|
|
font-size: 14px; |
|
|
font-weight: 500; |
|
|
cursor: pointer; |
|
|
text-decoration: none; |
|
|
display: inline-block; |
|
|
transition: all 0.2s; |
|
|
} |
|
|
|
|
|
.btn-primary { |
|
|
background: #1a73e8; |
|
|
color: white; |
|
|
} |
|
|
|
|
|
.btn-primary:hover { |
|
|
background: #1557b0; |
|
|
} |
|
|
|
|
|
.btn-secondary { |
|
|
background: #f1f3f4; |
|
|
color: #202124; |
|
|
} |
|
|
|
|
|
.btn-secondary:hover { |
|
|
background: #e8eaed; |
|
|
} |
|
|
|
|
|
.container { |
|
|
max-width: 1400px; |
|
|
margin: 0 auto; |
|
|
padding: 24px; |
|
|
} |
|
|
|
|
|
.page-header { |
|
|
margin-bottom: 24px; |
|
|
} |
|
|
|
|
|
.page-header h1 { |
|
|
font-size: 28px; |
|
|
font-weight: 600; |
|
|
margin-bottom: 8px; |
|
|
} |
|
|
|
|
|
.page-header p { |
|
|
color: #5f6368; |
|
|
} |
|
|
|
|
|
.card { |
|
|
background: white; |
|
|
border-radius: 8px; |
|
|
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1); |
|
|
padding: 24px; |
|
|
margin-bottom: 24px; |
|
|
} |
|
|
|
|
|
.card-header { |
|
|
display: flex; |
|
|
justify-content: space-between; |
|
|
align-items: center; |
|
|
margin-bottom: 20px; |
|
|
} |
|
|
|
|
|
.card-title { |
|
|
font-size: 18px; |
|
|
font-weight: 500; |
|
|
} |
|
|
|
|
|
.filters { |
|
|
display: flex; |
|
|
gap: 12px; |
|
|
flex-wrap: wrap; |
|
|
margin-bottom: 20px; |
|
|
} |
|
|
|
|
|
.filter-group { |
|
|
display: flex; |
|
|
flex-direction: column; |
|
|
gap: 4px; |
|
|
} |
|
|
|
|
|
.filter-group label { |
|
|
font-size: 12px; |
|
|
color: #5f6368; |
|
|
font-weight: 500; |
|
|
} |
|
|
|
|
|
.filter-group input, |
|
|
.filter-group select { |
|
|
padding: 8px 12px; |
|
|
border: 1px solid #dadce0; |
|
|
border-radius: 6px; |
|
|
font-size: 14px; |
|
|
font-family: inherit; |
|
|
} |
|
|
|
|
|
.filter-group input:focus, |
|
|
.filter-group select:focus { |
|
|
outline: none; |
|
|
border-color: #1a73e8; |
|
|
box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.1); |
|
|
} |
|
|
|
|
|
.stats-grid { |
|
|
display: grid; |
|
|
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); |
|
|
gap: 16px; |
|
|
margin-bottom: 24px; |
|
|
} |
|
|
|
|
|
.stat-card { |
|
|
background: white; |
|
|
border-radius: 8px; |
|
|
padding: 20px; |
|
|
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1); |
|
|
} |
|
|
|
|
|
.stat-label { |
|
|
font-size: 14px; |
|
|
color: #5f6368; |
|
|
margin-bottom: 8px; |
|
|
} |
|
|
|
|
|
.stat-value { |
|
|
font-size: 24px; |
|
|
font-weight: 600; |
|
|
color: #202124; |
|
|
} |
|
|
|
|
|
.chart-container { |
|
|
position: relative; |
|
|
height: 400px; |
|
|
margin-bottom: 24px; |
|
|
} |
|
|
|
|
|
.alert { |
|
|
padding: 12px 16px; |
|
|
border-radius: 6px; |
|
|
margin-bottom: 16px; |
|
|
font-size: 14px; |
|
|
} |
|
|
|
|
|
.alert.error { |
|
|
background: #fce8e6; |
|
|
color: #c5221f; |
|
|
} |
|
|
|
|
|
.alert.success { |
|
|
background: #e8f5e9; |
|
|
color: #137333; |
|
|
} |
|
|
|
|
|
@media (max-width: 768px) { |
|
|
.header { |
|
|
padding: 12px 16px; |
|
|
} |
|
|
|
|
|
.header-title { |
|
|
font-size: 18px; |
|
|
} |
|
|
|
|
|
.menu-toggle { |
|
|
display: block; |
|
|
} |
|
|
|
|
|
.header-actions { |
|
|
display: none; |
|
|
} |
|
|
|
|
|
.container { |
|
|
padding: 16px; |
|
|
} |
|
|
|
|
|
.filters { |
|
|
flex-direction: column; |
|
|
} |
|
|
|
|
|
.filter-group { |
|
|
width: 100%; |
|
|
} |
|
|
|
|
|
.chart-container { |
|
|
height: 300px; |
|
|
} |
|
|
} |
|
|
</style> |
|
|
</head> |
|
|
<body> |
|
|
<div class="header"> |
|
|
<div class="header-title"> |
|
|
<span>๐</span> |
|
|
<span>ํ ํฐ ์ฌ์ฉ๋ ํต๊ณ</span> |
|
|
</div> |
|
|
<button class="menu-toggle" onclick="toggleMobileMenu()" aria-label="๋ฉ๋ด ์ด๊ธฐ">โฐ</button> |
|
|
<div class="header-actions"> |
|
|
<span style="margin-right: 12px; color: #5f6368;">{{ current_user.nickname or current_user.username }}</span> |
|
|
|
|
|
{# ์ฌ์ดํธ ๊ด๋ฆฌ #} |
|
|
<div class="dropdown"> |
|
|
<button type="button" class="dropdown-toggle">์ฌ์ดํธ ๊ด๋ฆฌ</button> |
|
|
<div class="dropdown-menu"> |
|
|
<a href="{{ url_for('main.admin') }}" class="dropdown-item">์ฌ์ฉ์ ๊ด๋ฆฌ</a> |
|
|
<a href="{{ url_for('main.admin_tokens') }}" class="dropdown-item">ํ ํฐ ํต๊ณ</a> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
{# ์น์์ค ๊ด๋ฆฌ #} |
|
|
<div class="dropdown"> |
|
|
<button type="button" class="dropdown-toggle">์น์์ค ๊ด๋ฆฌ</button> |
|
|
<div class="dropdown-menu"> |
|
|
<a href="{{ url_for('main.admin_webnovels') }}" class="dropdown-item">์น์์ค ์
๋ก๋ ๋ฐ ๊ด๋ฆฌ</a> |
|
|
<a href="{{ url_for('main.admin_messages') }}" class="dropdown-item">๋ฉ์์ง ํ์ธ</a> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
{# AI ์ค์ #} |
|
|
<div class="dropdown"> |
|
|
<button type="button" class="dropdown-toggle">AI ์ค์ </button> |
|
|
<div class="dropdown-menu"> |
|
|
<a href="{{ url_for('main.admin_settings') }}" class="dropdown-item">AI ์ค์ </a> |
|
|
<a href="{{ url_for('main.admin_prompts') }}" class="dropdown-item">ํ๋กฌํํธ ๊ด๋ฆฌ</a> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
{# ์ฑ๋ด #} |
|
|
<div class="dropdown"> |
|
|
<button type="button" class="dropdown-toggle">์ฑ๋ด</button> |
|
|
<div class="dropdown-menu"> |
|
|
<a href="{{ url_for('main.admin_tags') }}" class="dropdown-item">ํ๊ทธ/ํ๋กฌํํธ</a> |
|
|
<a href="{{ url_for('main.admin_chatbot_prompts') }}" class="dropdown-item">์ฑ๋ด ํ๋กฌํํธ</a> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
{# ํธ์๊ธฐ๋ฅ #} |
|
|
<div class="dropdown"> |
|
|
<button type="button" class="dropdown-toggle">ํธ์๊ธฐ๋ฅ</button> |
|
|
<div class="dropdown-menu"> |
|
|
<a href="{{ url_for('main.admin_utils') }}" class="dropdown-item">์ ํธ</a> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
{# ๋ฉ์ธ์ผ๋ก #} |
|
|
<a href="{{ url_for('main.index') }}" class="btn btn-secondary" style="padding: 8px 16px; font-size: 14px; margin-right: 4px;">๋ฉ์ธ์ผ๋ก</a> |
|
|
<a href="{{ url_for('main.logout') }}" class="btn btn-secondary" style="padding: 8px 16px; font-size: 14px;">๋ก๊ทธ์์</a> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
|
|
|
<div class="mobile-menu" id="mobileMenu" onclick="closeMobileMenuOnBackdrop(event)"> |
|
|
<div class="mobile-menu-content" onclick="event.stopPropagation()"> |
|
|
<div class="mobile-menu-header"> |
|
|
<div class="mobile-menu-title">๋ฉ๋ด</div> |
|
|
<button class="mobile-menu-close" onclick="toggleMobileMenu()" aria-label="๋ฉ๋ด ๋ซ๊ธฐ">×</button> |
|
|
</div> |
|
|
<div class="mobile-menu-user">{{ current_user.nickname or current_user.username }}</div> |
|
|
<div class="mobile-menu-items"> |
|
|
<div style="padding: 8px 20px; font-size: 11px; font-weight: 600; color: #5f6368; text-transform: uppercase; border-bottom: 1px solid #f1f3f4;">์ฌ์ดํธ ๊ด๋ฆฌ</div> |
|
|
<a href="{{ url_for('main.admin') }}" class="mobile-menu-item" onclick="closeMobileMenu()">์ฌ์ฉ์ ๊ด๋ฆฌ</a> |
|
|
<a href="{{ url_for('main.admin_tokens') }}" class="mobile-menu-item" onclick="closeMobileMenu()">ํ ํฐ ํต๊ณ</a> |
|
|
|
|
|
<div style="padding: 8px 20px; font-size: 11px; font-weight: 600; color: #5f6368; text-transform: uppercase; border-bottom: 1px solid #f1f3f4; margin-top: 8px;">์น์์ค ๊ด๋ฆฌ</div> |
|
|
<a href="{{ url_for('main.admin_webnovels') }}" class="mobile-menu-item" onclick="closeMobileMenu()">์น์์ค ์
๋ก๋ ๋ฐ ๊ด๋ฆฌ</a> |
|
|
<a href="{{ url_for('main.admin_messages') }}" class="mobile-menu-item" onclick="closeMobileMenu()">๋ฉ์์ง ํ์ธ</a> |
|
|
|
|
|
<div style="padding: 8px 20px; font-size: 11px; font-weight: 600; color: #5f6368; text-transform: uppercase; border-bottom: 1px solid #f1f3f4; margin-top: 8px;">AI ์ค์ </div> |
|
|
<a href="{{ url_for('main.admin_settings') }}" class="mobile-menu-item" onclick="closeMobileMenu()">AI ์ค์ </a> |
|
|
<a href="{{ url_for('main.admin_prompts') }}" class="mobile-menu-item" onclick="closeMobileMenu()">ํ๋กฌํํธ ๊ด๋ฆฌ</a> |
|
|
|
|
|
<div style="padding: 8px 20px; font-size: 11px; font-weight: 600; color: #5f6368; text-transform: uppercase; border-bottom: 1px solid #f1f3f4; margin-top: 8px;">์ฑ๋ด</div> |
|
|
<a href="{{ url_for('main.admin_tags') }}" class="mobile-menu-item" onclick="closeMobileMenu()">ํ๊ทธ/ํ๋กฌํํธ</a> |
|
|
<a href="{{ url_for('main.admin_chatbot_prompts') }}" class="mobile-menu-item" onclick="closeMobileMenu()">์ฑ๋ด ํ๋กฌํํธ</a> |
|
|
|
|
|
<div style="padding: 8px 20px; font-size: 11px; font-weight: 600; color: #5f6368; text-transform: uppercase; border-bottom: 1px solid #f1f3f4; margin-top: 8px;">ํธ์๊ธฐ๋ฅ</div> |
|
|
<a href="{{ url_for('main.admin_utils') }}" class="mobile-menu-item" onclick="closeMobileMenu()">์ ํธ</a> |
|
|
|
|
|
<div style="padding: 8px 20px; font-size: 11px; font-weight: 600; color: #5f6368; text-transform: uppercase; border-bottom: 1px solid #f1f3f4; margin-top: 8px;">๊ธฐํ</div> |
|
|
<a href="{{ url_for('main.index') }}" class="mobile-menu-item" onclick="closeMobileMenu()">๋ฉ์ธ์ผ๋ก</a> |
|
|
<a href="{{ url_for('main.logout') }}" class="mobile-menu-item" onclick="closeMobileMenu()">๋ก๊ทธ์์</a> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
<div class="container"> |
|
|
<div class="page-header"> |
|
|
<h1>ํ ํฐ ์ฌ์ฉ๋ ํต๊ณ</h1> |
|
|
<p>AI ๋ชจ๋ธ๋ณ ํ ํฐ ์ฌ์ฉ๋์ ์๊ฐํํ์ฌ ํ์ธํ ์ ์์ต๋๋ค.</p> |
|
|
</div> |
|
|
|
|
|
<div id="alertContainer"></div> |
|
|
|
|
|
|
|
|
<div class="card"> |
|
|
<div class="card-header"> |
|
|
<div class="card-title">ํํฐ</div> |
|
|
</div> |
|
|
<div class="filters"> |
|
|
<div class="filter-group"> |
|
|
<label for="startDate">์์ ๋ ์ง</label> |
|
|
<input type="date" id="startDate"> |
|
|
</div> |
|
|
<div class="filter-group"> |
|
|
<label for="endDate">์ข
๋ฃ ๋ ์ง</label> |
|
|
<input type="date" id="endDate"> |
|
|
</div> |
|
|
<div class="filter-group"> |
|
|
<label for="modelFilter">AI ๋ชจ๋ธ</label> |
|
|
<select id="modelFilter"> |
|
|
<option value="">์ ์ฒด</option> |
|
|
</select> |
|
|
</div> |
|
|
<div class="filter-group"> |
|
|
<label for="groupBy">๊ทธ๋ฃนํ</label> |
|
|
<select id="groupBy"> |
|
|
<option value="day">์ผ๋ณ</option> |
|
|
<option value="model">๋ชจ๋ธ๋ณ</option> |
|
|
</select> |
|
|
</div> |
|
|
<div class="filter-group" style="justify-content: flex-end;"> |
|
|
<label> </label> |
|
|
<button class="btn btn-primary" onclick="loadTokenUsage()">์กฐํ</button> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
|
|
|
<div class="stats-grid" id="statsGrid"> |
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
<div class="card"> |
|
|
<div class="card-header"> |
|
|
<div class="card-title">ํ ํฐ ์ฌ์ฉ๋ ๊ทธ๋ํ</div> |
|
|
</div> |
|
|
<div class="chart-container"> |
|
|
<canvas id="tokenChart"></canvas> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
<script> |
|
|
let tokenChart = null; |
|
|
|
|
|
function toggleMobileMenu() { |
|
|
const menu = document.getElementById('mobileMenu'); |
|
|
menu.classList.toggle('active'); |
|
|
document.body.style.overflow = menu.classList.contains('active') ? 'hidden' : ''; |
|
|
} |
|
|
|
|
|
function closeMobileMenu() { |
|
|
const menu = document.getElementById('mobileMenu'); |
|
|
menu.classList.remove('active'); |
|
|
document.body.style.overflow = ''; |
|
|
} |
|
|
|
|
|
function closeMobileMenuOnBackdrop(event) { |
|
|
if (event.target.id === 'mobileMenu') { |
|
|
closeMobileMenu(); |
|
|
} |
|
|
} |
|
|
|
|
|
function showAlert(message, type = 'success') { |
|
|
const container = document.getElementById('alertContainer'); |
|
|
container.innerHTML = `<div class="alert ${type}">${message}</div>`; |
|
|
setTimeout(() => { |
|
|
container.innerHTML = ''; |
|
|
}, 5000); |
|
|
} |
|
|
|
|
|
|
|
|
function setDefaultDates() { |
|
|
const endDate = new Date(); |
|
|
const startDate = new Date(); |
|
|
startDate.setDate(startDate.getDate() - 30); |
|
|
|
|
|
document.getElementById('endDate').value = endDate.toISOString().split('T')[0]; |
|
|
document.getElementById('startDate').value = startDate.toISOString().split('T')[0]; |
|
|
} |
|
|
|
|
|
|
|
|
async function loadTokenUsage() { |
|
|
try { |
|
|
const startDate = document.getElementById('startDate').value; |
|
|
const endDate = document.getElementById('endDate').value; |
|
|
const modelName = document.getElementById('modelFilter').value; |
|
|
const groupBy = document.getElementById('groupBy').value; |
|
|
|
|
|
if (!startDate || !endDate) { |
|
|
showAlert('์์ ๋ ์ง์ ์ข
๋ฃ ๋ ์ง๋ฅผ ๋ชจ๋ ์ ํํด์ฃผ์ธ์.', 'error'); |
|
|
return; |
|
|
} |
|
|
|
|
|
const params = new URLSearchParams({ |
|
|
start_date: startDate, |
|
|
end_date: endDate, |
|
|
group_by: groupBy |
|
|
}); |
|
|
|
|
|
if (modelName) { |
|
|
params.append('model_name', modelName); |
|
|
} |
|
|
|
|
|
console.log('[ํ ํฐ ํต๊ณ] ์์ฒญ URL:', `/api/admin/token-usage?${params}`); |
|
|
const response = await fetch(`/api/admin/token-usage?${params}`, { |
|
|
method: 'GET', |
|
|
credentials: 'include' |
|
|
}); |
|
|
|
|
|
const data = await response.json(); |
|
|
console.log('[ํ ํฐ ํต๊ณ] ์๋ต ๋ฐ์ดํฐ:', data); |
|
|
|
|
|
if (response.ok && data.success) { |
|
|
if (data.stats && data.stats.length > 0) { |
|
|
updateStats(data.stats, data.total_messages, data.user_usage, data.system_usage); |
|
|
updateChart(data.stats, groupBy); |
|
|
} else { |
|
|
showAlert('์ ํํ ๊ธฐ๊ฐ์ ํ ํฐ ์ ๋ณด๊ฐ ์๋ ๋ฉ์์ง๊ฐ ์์ต๋๋ค.', 'error'); |
|
|
|
|
|
updateStats([], 0, null, null); |
|
|
updateChart([], groupBy); |
|
|
} |
|
|
} else { |
|
|
console.error('[ํ ํฐ ํต๊ณ] API ์ค๋ฅ:', data); |
|
|
showAlert(data.error || 'ํ ํฐ ์ฌ์ฉ๋ ์กฐํ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.', 'error'); |
|
|
} |
|
|
} catch (error) { |
|
|
console.error('ํ ํฐ ์ฌ์ฉ๋ ์กฐํ ์ค๋ฅ:', error); |
|
|
showAlert(`์ค๋ฅ: ${error.message}`, 'error'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function updateStats(stats, totalMessages, userUsage, systemUsage) { |
|
|
const statsGrid = document.getElementById('statsGrid'); |
|
|
|
|
|
let totalInput = 0; |
|
|
let totalOutput = 0; |
|
|
let totalTokens = 0; |
|
|
|
|
|
if (stats && stats.length > 0) { |
|
|
stats.forEach(stat => { |
|
|
totalInput += stat.input_tokens || 0; |
|
|
totalOutput += stat.output_tokens || 0; |
|
|
totalTokens += stat.total_tokens || 0; |
|
|
}); |
|
|
} |
|
|
|
|
|
|
|
|
let systemInput = 0; |
|
|
let systemOutput = 0; |
|
|
let systemTotal = 0; |
|
|
if (systemUsage) { |
|
|
systemInput = systemUsage.input_tokens || 0; |
|
|
systemOutput = systemUsage.output_tokens || 0; |
|
|
systemTotal = systemUsage.total_tokens || 0; |
|
|
} |
|
|
|
|
|
statsGrid.innerHTML = ` |
|
|
<div class="stat-card"> |
|
|
<div class="stat-label">์ด ์
๋ ฅ ํ ํฐ</div> |
|
|
<div class="stat-value">${totalInput.toLocaleString()}</div> |
|
|
</div> |
|
|
<div class="stat-card"> |
|
|
<div class="stat-label">์ด ์ถ๋ ฅ ํ ํฐ</div> |
|
|
<div class="stat-value">${totalOutput.toLocaleString()}</div> |
|
|
</div> |
|
|
<div class="stat-card"> |
|
|
<div class="stat-label">์ด ํ ํฐ</div> |
|
|
<div class="stat-value">${totalTokens.toLocaleString()}</div> |
|
|
</div> |
|
|
<div class="stat-card"> |
|
|
<div class="stat-label">์ด ๋ฉ์์ง ์</div> |
|
|
<div class="stat-value">${totalMessages.toLocaleString()}</div> |
|
|
</div> |
|
|
<div class="stat-card" style="border-left: 4px solid #34a853;"> |
|
|
<div class="stat-label">์์คํ
์ฌ์ฉ (์
๋ ฅ)</div> |
|
|
<div class="stat-value">${systemInput.toLocaleString()}</div> |
|
|
</div> |
|
|
<div class="stat-card" style="border-left: 4px solid #34a853;"> |
|
|
<div class="stat-label">์์คํ
์ฌ์ฉ (์ถ๋ ฅ)</div> |
|
|
<div class="stat-value">${systemOutput.toLocaleString()}</div> |
|
|
</div> |
|
|
<div class="stat-card" style="border-left: 4px solid #34a853;"> |
|
|
<div class="stat-label">์์คํ
์ฌ์ฉ (์ด)</div> |
|
|
<div class="stat-value">${systemTotal.toLocaleString()}</div> |
|
|
</div> |
|
|
`; |
|
|
} |
|
|
|
|
|
|
|
|
function updateChart(stats, groupBy) { |
|
|
const ctx = document.getElementById('tokenChart').getContext('2d'); |
|
|
|
|
|
if (tokenChart) { |
|
|
tokenChart.destroy(); |
|
|
} |
|
|
|
|
|
let labels, inputData, outputData; |
|
|
|
|
|
if (!stats || stats.length === 0) { |
|
|
|
|
|
labels = ['๋ฐ์ดํฐ ์์']; |
|
|
inputData = [0]; |
|
|
outputData = [0]; |
|
|
} else if (groupBy === 'day') { |
|
|
labels = stats.map(s => s.date); |
|
|
inputData = stats.map(s => s.input_tokens || 0); |
|
|
outputData = stats.map(s => s.output_tokens || 0); |
|
|
} else if (groupBy === 'model') { |
|
|
labels = stats.map(s => s.model || 'Unknown'); |
|
|
inputData = stats.map(s => s.input_tokens || 0); |
|
|
outputData = stats.map(s => s.output_tokens || 0); |
|
|
} else { |
|
|
labels = ['์ ์ฒด']; |
|
|
inputData = [stats[0]?.input_tokens || 0]; |
|
|
outputData = [stats[0]?.output_tokens || 0]; |
|
|
} |
|
|
|
|
|
tokenChart = new Chart(ctx, { |
|
|
type: 'line', |
|
|
data: { |
|
|
labels: labels, |
|
|
datasets: [ |
|
|
{ |
|
|
label: '์
๋ ฅ ํ ํฐ', |
|
|
data: inputData, |
|
|
borderColor: 'rgb(26, 115, 232)', |
|
|
backgroundColor: 'rgba(26, 115, 232, 0.1)', |
|
|
tension: 0.4 |
|
|
}, |
|
|
{ |
|
|
label: '์ถ๋ ฅ ํ ํฐ', |
|
|
data: outputData, |
|
|
borderColor: 'rgb(234, 67, 53)', |
|
|
backgroundColor: 'rgba(234, 67, 53, 0.1)', |
|
|
tension: 0.4 |
|
|
} |
|
|
] |
|
|
}, |
|
|
options: { |
|
|
responsive: true, |
|
|
maintainAspectRatio: false, |
|
|
plugins: { |
|
|
legend: { |
|
|
position: 'top', |
|
|
}, |
|
|
title: { |
|
|
display: true, |
|
|
text: 'ํ ํฐ ์ฌ์ฉ๋ ์ถ์ด' |
|
|
} |
|
|
}, |
|
|
scales: { |
|
|
y: { |
|
|
beginAtZero: true, |
|
|
ticks: { |
|
|
callback: function(value) { |
|
|
return value.toLocaleString(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}); |
|
|
} |
|
|
|
|
|
|
|
|
async function loadModels() { |
|
|
try { |
|
|
|
|
|
const endDate = new Date(); |
|
|
const startDate = new Date(); |
|
|
startDate.setFullYear(startDate.getFullYear() - 1); |
|
|
|
|
|
const params = new URLSearchParams({ |
|
|
start_date: startDate.toISOString().split('T')[0], |
|
|
end_date: endDate.toISOString().split('T')[0], |
|
|
group_by: 'model' |
|
|
}); |
|
|
|
|
|
const response = await fetch(`/api/admin/token-usage?${params}`, { |
|
|
method: 'GET', |
|
|
credentials: 'include' |
|
|
}); |
|
|
|
|
|
const data = await response.json(); |
|
|
|
|
|
if (response.ok && data.success && data.models) { |
|
|
const modelFilter = document.getElementById('modelFilter'); |
|
|
|
|
|
const existingOptions = Array.from(modelFilter.options).map(opt => opt.value); |
|
|
data.models.forEach(model => { |
|
|
if (!existingOptions.includes(model)) { |
|
|
const option = document.createElement('option'); |
|
|
option.value = model; |
|
|
option.textContent = model; |
|
|
modelFilter.appendChild(option); |
|
|
} |
|
|
}); |
|
|
} |
|
|
} catch (error) { |
|
|
console.error('๋ชจ๋ธ ๋ชฉ๋ก ๋ก๋ ์ค๋ฅ:', error); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function() { |
|
|
setDefaultDates(); |
|
|
loadModels(); |
|
|
loadTokenUsage(); |
|
|
}); |
|
|
</script> |
|
|
</body> |
|
|
</html> |
|
|
|
|
|
|