Update ppq-analyzer.html
This commit is contained in:
1 parent
4fbbb5fa55
commit
80f947ba23
1 file changed
+233
-244
+233
-244
@@ -5,39 +5,17 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>PPQ Cost Analyzer</title>
|
<title>PPQ Cost Analyzer</title>
|
||||||
<style>
|
<style>
|
||||||
* {
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
body {
|
||||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
}
|
}
|
||||||
|
.container { max-width: 1200px; margin: 0 auto; }
|
||||||
.container {
|
header { text-align: center; color: white; margin-bottom: 30px; }
|
||||||
max-width: 1200px;
|
header h1 { font-size: 2rem; margin-bottom: 10px; }
|
||||||
margin: 0 auto;
|
header p { opacity: 0.9; }
|
||||||
}
|
|
||||||
|
|
||||||
header {
|
|
||||||
text-align: center;
|
|
||||||
color: white;
|
|
||||||
margin-bottom: 30px;
|
|
||||||
}
|
|
||||||
|
|
||||||
header h1 {
|
|
||||||
font-size: 2.5rem;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
header p {
|
|
||||||
opacity: 0.9;
|
|
||||||
}
|
|
||||||
|
|
||||||
.upload-section {
|
.upload-section {
|
||||||
background: white;
|
background: white;
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
@@ -46,25 +24,17 @@
|
|||||||
margin-bottom: 30px;
|
margin-bottom: 30px;
|
||||||
box-shadow: 0 10px 40px rgba(0,0,0,0.2);
|
box-shadow: 0 10px 40px rgba(0,0,0,0.2);
|
||||||
}
|
}
|
||||||
|
|
||||||
.upload-area {
|
.upload-area {
|
||||||
border: 3px dashed #ccc;
|
border: 3px dashed #ccc;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
padding: 40px;
|
padding: 60px 20px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: all 0.3s;
|
transition: all 0.3s;
|
||||||
}
|
}
|
||||||
|
.upload-area:hover, .upload-area.dragover {
|
||||||
.upload-area:hover {
|
|
||||||
border-color: #6d4aff;
|
|
||||||
background: #f8f5ff;
|
|
||||||
}
|
|
||||||
|
|
||||||
.upload-area.dragover {
|
|
||||||
border-color: #6d4aff;
|
border-color: #6d4aff;
|
||||||
background: #f0ebff;
|
background: #f0ebff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.file-info {
|
.file-info {
|
||||||
display: none;
|
display: none;
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
@@ -73,7 +43,6 @@
|
|||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
color: #2e7d32;
|
color: #2e7d32;
|
||||||
}
|
}
|
||||||
|
|
||||||
button.analyze-btn {
|
button.analyze-btn {
|
||||||
background: #6d4aff;
|
background: #6d4aff;
|
||||||
color: white;
|
color: white;
|
||||||
@@ -83,14 +52,10 @@
|
|||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
transition: all 0.3s;
|
display: none;
|
||||||
}
|
}
|
||||||
|
button.analyze-btn:hover { background: #5a3fd6; }
|
||||||
button.analyze-btn:hover {
|
button.analyze-btn:disabled { background: #ccc; cursor: not-allowed; }
|
||||||
background: #5a3fd6;
|
|
||||||
transform: translateY(-2px);
|
|
||||||
}
|
|
||||||
|
|
||||||
.report-section {
|
.report-section {
|
||||||
background: white;
|
background: white;
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
@@ -98,45 +63,28 @@
|
|||||||
box-shadow: 0 10px 40px rgba(0,0,0,0.2);
|
box-shadow: 0 10px 40px rgba(0,0,0,0.2);
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
.report-section.active { display: block; }
|
||||||
.report-section.active {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
h2 {
|
h2 {
|
||||||
color: #6d4aff;
|
color: #6d4aff;
|
||||||
margin: 30px 0 20px 0;
|
margin: 30px 0 20px 0;
|
||||||
padding-bottom: 10px;
|
padding-bottom: 10px;
|
||||||
border-bottom: 2px solid #eee;
|
border-bottom: 2px solid #eee;
|
||||||
}
|
}
|
||||||
|
h2:first-of-type { margin-top: 0; }
|
||||||
h2:first-of-type {
|
|
||||||
margin-top: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
table {
|
table {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
margin: 20px 0;
|
margin: 20px 0;
|
||||||
font-size: 0.95rem;
|
font-size: 0.95rem;
|
||||||
|
overflow-x: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
th, td {
|
th, td {
|
||||||
padding: 12px 15px;
|
padding: 12px 15px;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
border-bottom: 1px solid #ddd;
|
border-bottom: 1px solid #ddd;
|
||||||
}
|
}
|
||||||
|
th { background: #f8f5ff; color: #6d4aff; font-weight: 600; }
|
||||||
th {
|
tr:hover { background: #faf9fc; }
|
||||||
background: #f8f5ff;
|
|
||||||
color: #6d4aff;
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
tr:hover {
|
|
||||||
background: #faf9fc;
|
|
||||||
}
|
|
||||||
|
|
||||||
.metric-card {
|
.metric-card {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
background: linear-gradient(135deg, #6d4aff 0%, #8b5cf6 100%);
|
background: linear-gradient(135deg, #6d4aff 0%, #8b5cf6 100%);
|
||||||
@@ -144,47 +92,34 @@
|
|||||||
padding: 20px 30px;
|
padding: 20px 30px;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
margin: 10px;
|
margin: 10px;
|
||||||
min-width: 200px;
|
min-width: 180px;
|
||||||
box-shadow: 0 4px 15px rgba(109,74,255,0.3);
|
box-shadow: 0 4px 15px rgba(109,74,255,0.3);
|
||||||
}
|
}
|
||||||
|
.metric-value { font-size: 1.8rem; font-weight: bold; margin-bottom: 5px; }
|
||||||
.metric-value {
|
.metric-label { opacity: 0.9; font-size: 0.9rem; }
|
||||||
font-size: 2rem;
|
.finding-box, .warning-box, .success-box {
|
||||||
font-weight: bold;
|
|
||||||
margin-bottom: 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.metric-label {
|
|
||||||
opacity: 0.9;
|
|
||||||
font-size: 0.9rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.finding-box {
|
|
||||||
background: #fff3cd;
|
|
||||||
border-left: 4px solid #ffc107;
|
|
||||||
padding: 15px 20px;
|
padding: 15px 20px;
|
||||||
margin: 20px 0;
|
margin: 20px 0;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
|
border-left: 4px solid;
|
||||||
}
|
}
|
||||||
|
.finding-box { background: #fff3cd; border-color: #ffc107; }
|
||||||
.warning-box {
|
.warning-box { background: #f8d7da; border-color: #dc3545; }
|
||||||
background: #f8d7da;
|
.success-box { background: #d4edda; border-color: #28a745; }
|
||||||
border-left: 4px solid #dc3545;
|
.debug-log {
|
||||||
padding: 15px 20px;
|
background: #1a1a2e;
|
||||||
|
color: #0f0;
|
||||||
|
padding: 15px;
|
||||||
|
border-radius: 8px;
|
||||||
margin: 20px 0;
|
margin: 20px 0;
|
||||||
border-radius: 4px;
|
font-family: monospace;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
max-height: 200px;
|
||||||
|
overflow-y: auto;
|
||||||
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.success-box {
|
|
||||||
background: #d4edda;
|
|
||||||
border-left: 4px solid #28a745;
|
|
||||||
padding: 15px 20px;
|
|
||||||
margin: 20px 0;
|
|
||||||
border-radius: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.privacy-note {
|
.privacy-note {
|
||||||
background: rgba(255,255,255,0.1);
|
background: rgba(255,255,255,0.15);
|
||||||
color: white;
|
color: white;
|
||||||
padding: 15px;
|
padding: 15px;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
@@ -192,71 +127,83 @@
|
|||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
font-size: 0.9rem;
|
font-size: 0.9rem;
|
||||||
}
|
}
|
||||||
|
.status-msg {
|
||||||
@media (max-width: 768px) {
|
padding: 10px;
|
||||||
.metric-card {
|
|
||||||
display: block;
|
|
||||||
margin: 10px 0;
|
margin: 10px 0;
|
||||||
|
border-radius: 8px;
|
||||||
|
display: none;
|
||||||
}
|
}
|
||||||
|
.status-error { background: #f8d7da; color: #721c24; }
|
||||||
table {
|
.status-success { background: #d4edda; color: #155724; }
|
||||||
font-size: 0.85rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
th, td {
|
|
||||||
padding: 8px 10px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<header>
|
<header>
|
||||||
<h1>📊 PPQ Cost Analyzer</h1>
|
<h1>📊 PPQ Cost Analyzer</h1>
|
||||||
<p>Analyser PayPerQ-bruken din - alle data held seg i nettlesaren din</p>
|
<p>Drag & drop CSV-fila di her - alle data held seg lokalt!</p>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<section class="upload-section" id="uploadSection">
|
<section class="upload-section" id="uploadSection">
|
||||||
<h2>📁 Last opp CSV-fil</h2>
|
<div class="upload-area" id="uploadArea">
|
||||||
<p style="margin-bottom: 20px; color: #666;">Drag & drop eller klikk for å velje fil</p>
|
<div style="font-size: 3rem; margin-bottom: 15px;">📄</div>
|
||||||
|
<div style="font-size: 1.2rem; margin-bottom: 10px;"><strong>Drag & drop CSV-fila her</strong></div>
|
||||||
|
<div style="color: #666;">eller klikk for å velje fil</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<input type="file" id="fileInput" accept=".csv" style="display:none">
|
<input type="file" id="fileInput" accept=".csv" style="display:none">
|
||||||
<div class="upload-area" id="uploadArea">
|
|
||||||
<div style="font-size: 3rem; margin-bottom: 10px;">📄</div>
|
<div class="status-msg" id="statusMsg"></div>
|
||||||
<div><strong>PayPerQ-Usage_*.csv</strong></div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="file-info" id="fileInfo"></div>
|
<div class="file-info" id="fileInfo"></div>
|
||||||
|
|
||||||
<button class="analyze-btn" id="analyzeBtn" style="display:none">Analyser data</button>
|
<button class="analyze-btn" id="analyzeBtn">Analyser data</button>
|
||||||
|
|
||||||
|
<div class="debug-log" id="debugLog">
|
||||||
|
<strong>Debug:</strong><br>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="report-section" id="reportSection">
|
<section class="report-section" id="reportSection">
|
||||||
<div class="privacy-note">
|
<div class="privacy-note">
|
||||||
🔒 **Privacy**: All analyse skjer lokalt i nettlesaren. Ingen data blir sende til serverar.
|
🔒 Alle data blir handtert lokalt i nettlesaren din. Ingen data blir sende ut.
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2>📊 Sammendrag</h2>
|
<h2>📊 Sammendrag</h2>
|
||||||
<div id="summaryMetrics"></div>
|
<div id="summaryMetrics"></div>
|
||||||
|
|
||||||
<h2>💰 Kostnad per modell</h2>
|
<h2>💰 Kostnad per modell</h2>
|
||||||
<table id="modelTable"></table>
|
<div id="modelTableContainer"></div>
|
||||||
|
|
||||||
<h2>📅 Dagleg fordeling</h2>
|
<h2>📅 Dagleg fordeling</h2>
|
||||||
<table id="dailyTable"></table>
|
<div id="dailyTableContainer"></div>
|
||||||
|
|
||||||
<h2>⚠️ Anomalier</h2>
|
<h2>⚠️ Anomalier</h2>
|
||||||
<div id="anomalies"></div>
|
<div id="anomalies"></div>
|
||||||
|
|
||||||
<h2>🕐 Timefordeling (aktivitet)</h2>
|
|
||||||
<table id="hourlyTable"></table>
|
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script>
|
|
||||||
<script>
|
<script>
|
||||||
|
// Debug-funksjon
|
||||||
|
function log(msg) {
|
||||||
|
const debugLog = document.getElementById('debugLog');
|
||||||
|
debugLog.style.display = 'block';
|
||||||
|
debugLog.innerHTML += `[${new Date().toLocaleTimeString()}] ${msg}<br>`;
|
||||||
|
debugLog.scrollTop = debugLog.scrollHeight;
|
||||||
|
console.log('[PPQ Analyzer]', msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
function showStatus(msg, isError = false) {
|
||||||
|
const statusEl = document.getElementById('statusMsg');
|
||||||
|
statusEl.style.display = 'block';
|
||||||
|
statusEl.className = 'status-msg ' + (isError ? 'status-error' : 'status-success');
|
||||||
|
statusEl.textContent = msg;
|
||||||
|
}
|
||||||
|
|
||||||
// Globale variablar
|
// Globale variablar
|
||||||
let csvData = [];
|
let csvData = [];
|
||||||
|
let rawData = '';
|
||||||
|
|
||||||
const uploadArea = document.getElementById('uploadArea');
|
const uploadArea = document.getElementById('uploadArea');
|
||||||
const fileInput = document.getElementById('fileInput');
|
const fileInput = document.getElementById('fileInput');
|
||||||
const fileInfo = document.getElementById('fileInfo');
|
const fileInfo = document.getElementById('fileInfo');
|
||||||
@@ -264,71 +211,157 @@
|
|||||||
const reportSection = document.getElementById('reportSection');
|
const reportSection = document.getElementById('reportSection');
|
||||||
const uploadSection = document.getElementById('uploadSection');
|
const uploadSection = document.getElementById('uploadSection');
|
||||||
|
|
||||||
// Drag & drop eventar
|
log('Init start...');
|
||||||
uploadArea.addEventListener('click', () => fileInput.click());
|
|
||||||
|
|
||||||
uploadArea.addEventListener('dragover', (e) => {
|
// Klikk for å open filveljar
|
||||||
e.preventDefault();
|
uploadArea.addEventListener('click', () => {
|
||||||
uploadArea.classList.add('dragover');
|
log('Upload area clicked');
|
||||||
|
fileInput.click();
|
||||||
});
|
});
|
||||||
|
|
||||||
uploadArea.addEventListener('dragleave', () => {
|
// Drag & drop
|
||||||
|
uploadArea.addEventListener('dragover', (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
uploadArea.classList.add('dragover');
|
||||||
|
log('Drag over');
|
||||||
|
});
|
||||||
|
|
||||||
|
uploadArea.addEventListener('dragleave', (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
uploadArea.classList.remove('dragover');
|
uploadArea.classList.remove('dragover');
|
||||||
|
log('Drag leave');
|
||||||
});
|
});
|
||||||
|
|
||||||
uploadArea.addEventListener('drop', (e) => {
|
uploadArea.addEventListener('drop', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
uploadArea.classList.remove('dragover');
|
uploadArea.classList.remove('dragover');
|
||||||
|
log('Drop event');
|
||||||
|
|
||||||
const files = e.dataTransfer.files;
|
const files = e.dataTransfer.files;
|
||||||
if (files.length > 0) handleFile(files[0]);
|
log(`Dropped ${files.length} file(s)`);
|
||||||
|
|
||||||
|
if (files.length > 0) {
|
||||||
|
handleFile(files[0]);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Filveljar
|
||||||
fileInput.addEventListener('change', (e) => {
|
fileInput.addEventListener('change', (e) => {
|
||||||
if (e.target.files.length > 0) handleFile(e.target.files[0]);
|
log(`File input change, ${e.target.files.length} file(s)`);
|
||||||
|
if (e.target.files.length > 0) {
|
||||||
|
handleFile(e.target.files[0]);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
analyzeBtn.addEventListener('click', generateReport);
|
// Analyse-knapp
|
||||||
|
analyzeBtn.addEventListener('click', () => {
|
||||||
|
log('Analyze button clicked');
|
||||||
|
generateReport();
|
||||||
|
});
|
||||||
|
|
||||||
function handleFile(file) {
|
function handleFile(file) {
|
||||||
if (!file.name.endsWith('.csv')) {
|
log(`Handling file: ${file.name} (${formatSize(file.size)} bytes)`);
|
||||||
alert('Vennligst last opp ei .csv-fil');
|
|
||||||
|
if (!file.name.toLowerCase().endsWith('.csv')) {
|
||||||
|
showStatus('Feil! Vennligst last opp ei .csv-fil', true);
|
||||||
|
log('Error: Not a CSV file');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fileInfo.style.display = 'block';
|
|
||||||
fileInfo.innerHTML = `✅ <strong>${file.name}</strong> (${formatSize(file.size)})`;
|
|
||||||
analyzeBtn.style.display = 'inline-block';
|
|
||||||
|
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.onload = (e) => {
|
|
||||||
csvData = parseCSV(e.target.result);
|
reader.onload = (event) => {
|
||||||
|
rawData = event.target.result;
|
||||||
|
log(`File read successfully, ${rawData.length} characters`);
|
||||||
|
|
||||||
|
// Sjekk første raden for debugging
|
||||||
|
const firstLines = rawData.split('\n').slice(0, 3);
|
||||||
|
log('First 3 lines:');
|
||||||
|
firstLines.forEach((line, i) => log(` Line ${i}: ${line.substring(0, 100)}`));
|
||||||
|
|
||||||
|
fileInfo.style.display = 'block';
|
||||||
|
fileInfo.innerHTML = `✅ <strong>${file.name}</strong><br>Storleik: ${formatSize(file.size)} | Ready to analyze`;
|
||||||
|
|
||||||
|
analyzeBtn.style.display = 'inline-block';
|
||||||
|
analyzeBtn.disabled = false;
|
||||||
|
|
||||||
|
showStatus('Filen er lasta opp! Trykk på "Analyser data" for å starte.', false);
|
||||||
};
|
};
|
||||||
reader.readAsText(file);
|
|
||||||
|
reader.onerror = (error) => {
|
||||||
|
log('FileReader error: ' + error);
|
||||||
|
showStatus('Feil ved lesing av fil', true);
|
||||||
|
};
|
||||||
|
|
||||||
|
log('Starting file read...');
|
||||||
|
reader.readAsText(file, 'UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseCSV(csvText) {
|
function parseCSV(csvText) {
|
||||||
const lines = csvText.trim().split('\n');
|
log('Parsing CSV...');
|
||||||
const headers = lines[0].split(',').map(h => h.trim());
|
const lines = csvText.trim().split('\n').filter(line => line.trim());
|
||||||
|
log(`Found ${lines.length} lines total`);
|
||||||
|
|
||||||
|
if (lines.length < 2) {
|
||||||
|
log('Error: Not enough lines in CSV');
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const headers = lines[0].split(',').map(h => h.trim().replace(/"/g, ''));
|
||||||
|
log(`Headers: ${JSON.stringify(headers)}`);
|
||||||
|
|
||||||
const data = [];
|
const data = [];
|
||||||
|
let errors = 0;
|
||||||
|
|
||||||
|
for (let i = 1; i < lines.length; i++) {
|
||||||
|
const line = lines[i];
|
||||||
|
|
||||||
|
// Skip total row
|
||||||
|
if (line.includes('Total Records') || line.trim() === '') continue;
|
||||||
|
|
||||||
|
// Handle quoted fields
|
||||||
|
const values = [];
|
||||||
|
let inQuotes = false;
|
||||||
|
let current = '';
|
||||||
|
|
||||||
|
for (let char of line) {
|
||||||
|
if (char === '"') {
|
||||||
|
inQuotes = !inQuotes;
|
||||||
|
} else if (char === ',' && !inQuotes) {
|
||||||
|
values.push(current.trim().replace(/"/g, ''));
|
||||||
|
current = '';
|
||||||
|
} else {
|
||||||
|
current += char;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
values.push(current.trim().replace(/"/g, ''));
|
||||||
|
|
||||||
for (let i = 1; i < lines.length && !lines[i].includes('Total Records'); i++) {
|
|
||||||
const values = lines[i].split(',');
|
|
||||||
if (values.length === headers.length) {
|
if (values.length === headers.length) {
|
||||||
const row = {};
|
const row = {};
|
||||||
headers.forEach((header, idx) => {
|
headers.forEach((header, idx) => {
|
||||||
let val = values[idx]?.trim();
|
let val = values[idx];
|
||||||
|
|
||||||
// Konverter tall
|
// Konverter tallfelt
|
||||||
if (header.includes('Tokens') || header.includes('Price')) {
|
if (header.includes('Tokens') || header === 'Price (USD)') {
|
||||||
val = parseFloat(val) || 0;
|
val = parseFloat(val) || 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
row[header] = val;
|
row[header] = val;
|
||||||
});
|
});
|
||||||
|
|
||||||
data.push(row);
|
data.push(row);
|
||||||
|
} else {
|
||||||
|
errors++;
|
||||||
|
if (errors < 3) {
|
||||||
|
log(`Parse error line ${i}: expected ${headers.length} fields, got ${values.length}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log(`Parsed ${data.length} rows, ${errors} errors`);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,83 +372,73 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function formatNumber(num) {
|
function formatNumber(num) {
|
||||||
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ' ');
|
return Math.floor(num).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateReport() {
|
function generateReport() {
|
||||||
|
log('Generating report...');
|
||||||
|
|
||||||
|
if (!rawData || rawData.length === 0) {
|
||||||
|
log('No data loaded!');
|
||||||
|
showStatus('Ingen data funnen. Last opp ei CSV-fil først.', true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
csvData = parseCSV(rawData);
|
||||||
|
log(`Loaded ${csvData.length} data rows`);
|
||||||
|
|
||||||
if (csvData.length === 0) {
|
if (csvData.length === 0) {
|
||||||
alert('Ingen data funnen');
|
showStatus('Kunne ikkje lese data frå fila', true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Beregn statistsikar
|
|
||||||
const stats = calculateStats(csvData);
|
const stats = calculateStats(csvData);
|
||||||
|
log('Stats calculated');
|
||||||
|
|
||||||
// Render summary
|
|
||||||
renderSummary(stats);
|
renderSummary(stats);
|
||||||
|
|
||||||
// Render modell-tabell
|
|
||||||
renderModelTable(stats.models);
|
renderModelTable(stats.models);
|
||||||
|
|
||||||
// Render dagleg tabell
|
|
||||||
renderDailyTable(stats.daily);
|
renderDailyTable(stats.daily);
|
||||||
|
|
||||||
// Render anomalier
|
|
||||||
renderAnomalies(csvData);
|
renderAnomalies(csvData);
|
||||||
|
|
||||||
// Render timefordeling
|
|
||||||
renderHourlyTable(csvData);
|
|
||||||
|
|
||||||
// Vis rapport
|
|
||||||
uploadSection.style.display = 'none';
|
uploadSection.style.display = 'none';
|
||||||
reportSection.classList.add('active');
|
reportSection.classList.add('active');
|
||||||
|
|
||||||
// Scroll to top
|
log('Report rendered successfully');
|
||||||
window.scrollTo(0, 0);
|
window.scrollTo(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function calculateStats(data) {
|
function calculateStats(data) {
|
||||||
const models = {};
|
const models = {};
|
||||||
const daily = {};
|
const daily = {};
|
||||||
const hourly = {};
|
|
||||||
|
|
||||||
data.forEach(row => {
|
data.forEach(row => {
|
||||||
// Per modell
|
// Per modell
|
||||||
const model = row.Model;
|
const model = row.Model || 'unknown';
|
||||||
if (!models[model]) {
|
if (!models[model]) {
|
||||||
models[model] = { count: 0, totalCost: 0, totalInput: 0, totalOutput: 0 };
|
models[model] = { count: 0, totalCost: 0, totalInput: 0, totalOutput: 0 };
|
||||||
}
|
}
|
||||||
models[model].count++;
|
models[model].count++;
|
||||||
models[model].totalCost += row['Price (USD)'];
|
models[model].totalCost += row['Price (USD)'] || 0;
|
||||||
models[model].totalInput += row['Input Tokens'];
|
models[model].totalInput += row['Input Tokens'] || 0;
|
||||||
models[model].totalOutput += row['Output Tokens'];
|
models[model].totalOutput += row['Output Tokens'] || 0;
|
||||||
|
|
||||||
// Per dag
|
// Per dag
|
||||||
const date = row.Date;
|
const date = row.Date || 'unknown';
|
||||||
if (!daily[date]) {
|
if (!daily[date]) {
|
||||||
daily[date] = { cost: 0, count: 0 };
|
daily[date] = { cost: 0, count: 0 };
|
||||||
}
|
}
|
||||||
daily[date].cost += row['Price (USD)'];
|
daily[date].cost += row['Price (USD)'] || 0;
|
||||||
daily[date].count++;
|
daily[date].count++;
|
||||||
|
|
||||||
// Per time
|
|
||||||
const hour = parseInt(row.Time.split(':')[0]);
|
|
||||||
if (!hourly[hour]) {
|
|
||||||
hourly[hour] = { cost: 0, count: 0 };
|
|
||||||
}
|
|
||||||
hourly[hour].cost += row['Price (USD)'];
|
|
||||||
hourly[hour].count++;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
totalCost: data.reduce((sum, r) => sum + r['Price (USD)'], 0),
|
totalCost: data.reduce((sum, r) => sum + (r['Price (USD)'] || 0), 0),
|
||||||
totalRequests: data.length,
|
totalRequests: data.length,
|
||||||
totalInput: data.reduce((sum, r) => sum + r['Input Tokens'], 0),
|
totalInput: data.reduce((sum, r) => sum + (r['Input Tokens'] || 0), 0),
|
||||||
totalOutput: data.reduce((sum, r) => sum + r['Output Tokens'], 0),
|
totalOutput: data.reduce((sum, r) => sum + (r['Output Tokens'] || 0), 0),
|
||||||
uniqueDates: new Set(data.map(r => r.Date)).size,
|
uniqueDates: new Set(data.map(r => r.Date)).size,
|
||||||
models,
|
models,
|
||||||
daily,
|
daily
|
||||||
hourly
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -431,7 +454,7 @@
|
|||||||
<div class="metric-label">Førespurnadar</div>
|
<div class="metric-label">Førespurnadar</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="metric-card">
|
<div class="metric-card">
|
||||||
<div class="metric-value">${formatNumber(stats.totalInput / 1000000).replace(/\.00$/, '')}M</div>
|
<div class="metric-value">${formatNumber(Math.round(stats.totalInput / 1000000))}M</div>
|
||||||
<div class="metric-label">Input-tokenar</div>
|
<div class="metric-label">Input-tokenar</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="metric-card">
|
<div class="metric-card">
|
||||||
@@ -439,16 +462,16 @@
|
|||||||
<div class="metric-label">Per dag</div>
|
<div class="metric-label">Per dag</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
log('Summary rendered');
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderModelTable(models) {
|
function renderModelTable(models) {
|
||||||
const sorted = Object.entries(models)
|
const sorted = Object.entries(models).sort((a, b) => b[1].totalCost - a[1].totalCost);
|
||||||
.sort((a, b) => b[1].totalCost - a[1].totalCost);
|
|
||||||
|
|
||||||
let html = '<tr><th>Modell</th><th>Føresp.</th><th>Total ($)</th><th>Gj.snitt ($)</th></tr>';
|
let html = '<table><tr><th>Modell</th><th>Føresp.</th><th>Total ($)</th><th>Gj.snitt ($)</th></tr>';
|
||||||
|
|
||||||
sorted.forEach(([name, stats]) => {
|
sorted.forEach(([name, stats]) => {
|
||||||
const avg = stats.totalCost / stats.count;
|
const avg = stats.count > 0 ? stats.totalCost / stats.count : 0;
|
||||||
html += `<tr>
|
html += `<tr>
|
||||||
<td><strong>${name}</strong></td>
|
<td><strong>${name}</strong></td>
|
||||||
<td>${formatNumber(stats.count)}</td>
|
<td>${formatNumber(stats.count)}</td>
|
||||||
@@ -457,13 +480,15 @@
|
|||||||
</tr>`;
|
</tr>`;
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById('modelTable').innerHTML = html;
|
html += '</table>';
|
||||||
|
document.getElementById('modelTableContainer').innerHTML = html;
|
||||||
|
log(`Model table rendered with ${sorted.length} models`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderDailyTable(daily) {
|
function renderDailyTable(daily) {
|
||||||
const sorted = Object.entries(daily).sort((a, b) => a[0].localeCompare(b[0]));
|
const sorted = Object.entries(daily).sort((a, b) => a[0].localeCompare(b[0]));
|
||||||
|
|
||||||
let html = '<tr><th>Dato</th><th>Kostnad ($)</th><th>Førespurnadar</th></tr>';
|
let html = '<table><tr><th>Dato</th><th>Kostnad ($)</th><th>Førespurnadar</th></tr>';
|
||||||
|
|
||||||
sorted.forEach(([date, stats]) => {
|
sorted.forEach(([date, stats]) => {
|
||||||
html += `<tr>
|
html += `<tr>
|
||||||
@@ -473,7 +498,9 @@
|
|||||||
</tr>`;
|
</tr>`;
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById('dailyTable').innerHTML = html;
|
html += '</table>';
|
||||||
|
document.getElementById('dailyTableContainer').innerHTML = html;
|
||||||
|
log('Daily table rendered');
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderAnomalies(data) {
|
function renderAnomalies(data) {
|
||||||
@@ -481,37 +508,37 @@
|
|||||||
const boxes = [];
|
const boxes = [];
|
||||||
|
|
||||||
// Gratis førespurnadar
|
// Gratis førespurnadar
|
||||||
const free = data.filter(r => r['Price (USD)'] === 0);
|
const free = data.filter(r => (r['Price (USD)'] || 0) === 0);
|
||||||
if (free.length > 0) {
|
if (free.length > 0) {
|
||||||
boxes.push({
|
boxes.push({
|
||||||
type: 'success-box',
|
type: 'success-box',
|
||||||
title: `${free.length} gratis førespurnadar`,
|
title: `${free.length} gratis førespurnadar`,
|
||||||
items: free.slice(0, 5).map(r => `${r.Model} (${r.Input Tokens} tokens)`)
|
items: free.slice(0, 5).map(r => `${r.Model} (${formatNumber(r['Input Tokens'])} tokens)`)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Monsterkontekstar
|
// Monsterkontekstar (>100k input)
|
||||||
const big = data.filter(r => r['Input Tokens'] > 100000);
|
const big = data.filter(r => (r['Input Tokens'] || 0) > 100000);
|
||||||
if (big.length > 0) {
|
if (big.length > 0) {
|
||||||
boxes.push({
|
boxes.push({
|
||||||
type: 'warning-box',
|
type: 'warning-box',
|
||||||
title: `${big.length} "monsterkontekstar" (>100k tokens)`,
|
title: `${big.length} "monsterkontekstar" (>100k tokens)`,
|
||||||
items: big.sort((a,b) => b['Input Tokens'] - a['Input Tokens'])
|
items: big.sort((a,b) => (b['Input Tokens']||0) - (a['Input Tokens']||0))
|
||||||
.slice(0, 5)
|
.slice(0, 5)
|
||||||
.map(r => `${r.Model}: ${r['Input Tokens']} tokens, $${r['Price (USD)'].toFixed(2)}`)
|
.map(r => `${r.Model}: ${formatNumber(r['Input Tokens'])} tokens, $${(r['Price (USD)']||0).toFixed(2)}`)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Høgaste kostnadar
|
// Høgaste kostnadar
|
||||||
const topCosts = [...data].sort((a,b) => b['Price (USD)'] - a['Price (USD)']).slice(0, 3);
|
const topCosts = [...data].sort((a,b) => (b['Price (USD)']||0) - (a['Price (USD)']||0)).slice(0, 3);
|
||||||
boxes.push({
|
boxes.push({
|
||||||
type: 'finding-box',
|
type: 'finding-box',
|
||||||
title: 'Topp 3 dyraste enkeltforespurnadar',
|
title: 'Topp 3 dyraste enkeltforespurnadar',
|
||||||
items: topCosts.map(r => `${r.Model} den ${r.Date} kl. ${r.Time}: $${r['Price (USD)'].toFixed(2)}`)
|
items: topCosts.map(r => `${r.Model} den ${r.Date} kl. ${r.Time}: $${(r['Price (USD)']||0).toFixed(2)}`)
|
||||||
});
|
});
|
||||||
|
|
||||||
// Tomme førespurnadar
|
// Tomme førespurnadar
|
||||||
const empty = data.filter(r => r['Input Tokens'] === 0 || r['Output Tokens'] === 0);
|
const empty = data.filter(r => (r['Input Tokens'] || 0) === 0 || (r['Output Tokens'] || 0) === 0);
|
||||||
if (empty.length > 0) {
|
if (empty.length > 0) {
|
||||||
boxes.push({
|
boxes.push({
|
||||||
type: 'warning-box',
|
type: 'warning-box',
|
||||||
@@ -522,6 +549,7 @@
|
|||||||
|
|
||||||
if (boxes.length === 0) {
|
if (boxes.length === 0) {
|
||||||
anomaliesContainer.innerHTML = '<div class="success-box">Ingen anomaliar funne ✨</div>';
|
anomaliesContainer.innerHTML = '<div class="success-box">Ingen anomaliar funne ✨</div>';
|
||||||
|
log('No anomalies detected');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -536,46 +564,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
anomaliesContainer.innerHTML = html;
|
anomaliesContainer.innerHTML = html;
|
||||||
}
|
log(`Anomalies rendered: ${boxes.length} sections`);
|
||||||
|
|
||||||
function renderHourlyTable(data) {
|
|
||||||
const hourly = {};
|
|
||||||
data.forEach(r => {
|
|
||||||
const hour = parseInt(r.Time.split(':')[0]);
|
|
||||||
if (!hourly[hour]) {
|
|
||||||
hourly[hour] = { cost: 0, count: 0 };
|
|
||||||
}
|
|
||||||
hourly[hour].cost += r['Price (USD)'];
|
|
||||||
hourly[hour].count++;
|
|
||||||
});
|
|
||||||
|
|
||||||
const sorted = Object.entries(hourly).sort((a, b) => parseInt(a[0]) - parseInt(b[0]));
|
|
||||||
|
|
||||||
let html = '<tr><th>Time</th><th>Kostnad ($)</th><th>Førespurnadar</th></tr>';
|
|
||||||
let peakHour = null, peakCost = 0;
|
|
||||||
|
|
||||||
sorted.forEach(([hour, stats]) => {
|
|
||||||
if (stats.cost > peakCost) {
|
|
||||||
peakCost = stats.cost;
|
|
||||||
peakHour = hour;
|
|
||||||
}
|
|
||||||
html += `<tr>
|
|
||||||
<td>${parseInt(hour):02d}:00</td>
|
|
||||||
<td>$${stats.cost.toFixed(2)}</td>
|
|
||||||
<td>${formatNumber(stats.count)}</td>
|
|
||||||
</tr>`;
|
|
||||||
});
|
|
||||||
|
|
||||||
document.getElementById('hourlyTable').innerHTML = html;
|
|
||||||
|
|
||||||
if (peakHour !== null) {
|
|
||||||
const peakBox = document.createElement('div');
|
|
||||||
peakBox.className = 'success-box';
|
|
||||||
peakBox.innerHTML = `
|
|
||||||
<strong>Høgaste kostnad:</strong> ${(parseInt(peakHour)):02d}:00 med $${peakCost.toFixed(2)}
|
|
||||||
`;
|
|
||||||
document.getElementById('hourlyTable').appendChild(peakBox);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in new issue
Block a user