forked from opensource-sw-project-OS/project-OS-front
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.html
More file actions
670 lines (583 loc) · 21.3 KB
/
dashboard.html
File metadata and controls
670 lines (583 loc) · 21.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>대시보드</title>
<style>
header{
position: fixed;
/* 하위요소는 투명도 적용되지 않도록 opacity아닌 rgba */
background-color: rgb(255, 255, 255, 0.4);
/* 화면 너비에 꽉차도록 */
width: 100%;
/* 갭 없애주기 */
top: 0;
left: 0;
right: 0;
height: 70px;
/* 그림자 생성 */
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
align-items: center;
padding:0 150px;
/* 지정한 사이즈 내에 padding도 포함 */
box-sizing: border-box;
display: flex;
/* 두 요소가 양끝으로 가도록 */
/* justify-content: space-between; */
}
.title{
white-space: nowrap;
font-size:22px;
font-weight: bold;
}
@font-face {
font-family: 'SUIT';
font-style: normal;
font-weight: 400;
src: url('https://cdn.jsdelivr.net/gh/sunn-us/SUIT/fonts/static/woff2/SUIT-Regular.woff2') format('woff2');
}
* { box-sizing: border-box; }
body {
margin: 0;
font-family: 'SUIT', sans-serif;
display: flex;
height: 100vh;
background: linear-gradient(to bottom, #d7dadd 0%, #c4c9d6 60%, #b0c4db 100%);
}
.side-menu {
width: 220px;
display: flex;
flex-direction: column;
align-items: center;
padding: 100px 0;
gap: 20px;
}
.pill-menu {
margin-top: 13px;
margin-left: 100px;
display: flex;
align-items: center;
gap: 30px;
background: rgba(255, 255, 255, 0.3);
width: 250px;
padding: 12px 25px;
border-radius: 9999px;
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
color: #333;
font-size: 17px;
font-weight: 600;
cursor: pointer;
backdrop-filter: blur(10px);
}
.pill-menu:hover {
background: rgba(255, 255, 255, 0.6);
}
.pill-menu img {
margin-left: 20px;
width: 33px;
height: 33px;
}
.main-content {
flex: 1;
padding: 40px;
display: flex;
flex-direction: column;
align-items: center;
overflow-y: auto;
gap: 20px;
margin-top: 70px;
}
.glass-box {
max-width: 600px;
width: 100%;
padding: 20px;
background: rgba(255, 255, 255, 0.5);
border-radius: 20px;
backdrop-filter: blur(15px);
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
text-align: center;
}
.glass-row-2 {
display: flex;
gap: 20px;
width: 90%;
}
.glass-col {
flex: 1;
background: rgba(255, 255, 255, 0.5);
border-radius: 20px;
padding: 20px;
backdrop-filter: blur(15px);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}
.glass-wrapper {
width: 100%;
max-width: 600px;
display: flex;
flex-direction: column;
gap: 20px;
align-items: center;
}
canvas {
margin-top: 20px;
background: transparent;
border-radius: 10px;
}
#map {
width: 100%;
height: 400px;
border-radius: 10px;
margin-top: 20px;
}
#preview, #croppedResult {
max-width: 100%;
max-height: 250px;
margin-top: 10px;
border: 1px solid #ccc;
display: none;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="apikey.js"></script>
<script>
// GOOGLE_API_KEY 변수가 전역(global)으로 등록됨
console.log(GOOGLE_API_KEY);
const script = document.createElement('script');
script.src = `https://maps.googleapis.com/maps/api/js?key=${GOOGLE_API_KEY}&libraries=places`;
script.async = true;
script.defer = true;
document.head.appendChild(script);
</script>
<script src="https://cdn.jsdelivr.net/npm/three@0.140.2/build/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.140.2/examples/js/loaders/GLTFLoader.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.140.2/examples/js/controls/OrbitControls.js"></script>
<script src="https://cdn.jsdelivr.net/npm/cropperjs@1.5.13/dist/cropper.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/cropperjs@1.5.13/dist/cropper.min.css" />
<script src="https://cdn.jsdelivr.net/npm/tesseract.js@4.0.2/dist/tesseract.min.js"></script>
</head>
<body>
<header>
<div class="title">Project OS</div>
</header>
<aside class="side-menu">
<div class="pill-menu" onclick="showReceiptInput()">
<img src="image/money2.png" alt="지출입력"> 지출 입력
</div>
<div class="pill-menu" onclick="showSpending()">
<img src="image/graph.png" alt="지출 그래프"> 지출 그래프
</div>
<div class="pill-menu" onclick="showEmotion()">
<img src="image/emotion.png" alt="감정"> 감정
</div>
<div class="pill-menu" onclick="showBudget()">
<img src="image/budget.png" alt="예산"> 예산
</div>
<div class="pill-menu" onclick="showLunchMap()">
<img src="image/dish.png" alt="점메추"> 점메추
</div>
</aside>
<main class="main-content" id="main"></main>
<script>
function showReceiptInput() {
document.getElementById("main").innerHTML = `
<div class="glass-row-2">
<div class="glass-col">
<h3>사진 업로드 및 분석</h3>
<input type="file" id="upload" accept="image/*" / >
<img id="preview" />
<img id="croppedResult" />
<br>
<label>분야 선택:</label>
<select id="category">
<option value="식비">식비</option>
<option value="교통">교통</option>
<option value="쇼핑">쇼핑</option>
<option value="구독">구독</option>
<option value="기타">기타</option>
</select>
<br><br>
<button id="confirmCrop" style="margin-top:10px; padding:8px 16px; border:none; background:#83A2DB; color:white; border-radius:8px;"> 크롭 </button>
<button onclick="runOCR()" style="margin-top:10px; padding:8px 16px; border:none; background:#83A2DB; color:white; border-radius:8px;"> OCR 실행 </button>
</div>
<div class="glass-col" >
<h3> OCR 결과</h3>
<div id="result">OCR 결과 영역</div>
</div>
</div>
<div class="glass-row-2">
<div class="glass-col" style="width: 100%;">
<h3>날짜 / 금액 추출</h3>
<div id="extracted">날짜 : <br>금액 :
</div>
</div>`;
const upload = document.getElementById('upload');
const preview = document.getElementById('preview');
const croppedResult = document.getElementById('croppedResult');
const result = document.getElementById('result');
const extracted = document.getElementById('extracted');
let cropper = null;
let croppedBlob = null;
upload.addEventListener('change', () => {
const file = upload.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = () => {
preview.src = reader.result;
preview.style.display = 'block';
croppedResult.style.display = 'none';
if (cropper) cropper.destroy();
cropper = new Cropper(preview, {
aspectRatio: NaN,
viewMode: 1
});
};
reader.readAsDataURL(file);
});
document.getElementById('confirmCrop').addEventListener('click', () => {
if (!cropper) return;
const canvas = cropper.getCroppedCanvas();
canvas.toBlob(blob => {
croppedBlob = blob;
croppedResult.src = URL.createObjectURL(blob);
croppedResult.style.display = 'block';
preview.style.display = 'none';
cropper.destroy();
cropper = null;
}, 'image/png');
});
window.runOCR = function() {
if (!croppedBlob) {
alert("크롭 후 버튼을 눌러주세요");
return;
}
result.innerText = "OCR 인식 중...";
extracted.innerText = "추출 중...";
Tesseract.recognize(
croppedBlob,
'kor',
{
langPath: 'https://tessdata.projectnaptha.com/4.0.0/',
logger: m => console.log(m)
}
).then(({ data: { text } }) => {
result.innerText = text;
const dateMatch = text.match(/\d{4}[.\-/]\d{1,2}[.\-/]\d{1,2}/);
const date = dateMatch ? dateMatch[0] : '날짜 미인식';
const totalMatch = text.match(/(합계|총액|총합계)[^\d]*(₩?\s?\d{1,3}(,\d{3})*(원)?)/);
const amount = totalMatch ? totalMatch[2] : '금액 미인식';
extracted.innerHTML = `날짜 : ${date}<br>합계 금액 : ${amount}`;
}).catch(err => {
result.innerText = `오류 발생: ${err.message}`;
extracted.innerText = '추출 실패';
});
}
}
function showBudget() {
document.getElementById("main").innerHTML = `
<div class="glass-box">
<h2>이번 달 예산</h2>
<input type="number" id="totalBudget" placeholder="총 예산 입력 (₩)" />
<input type="number" id="usedBudget" placeholder="사용한 금액 입력 (₩)" />
<button onclick="drawChart()" style="margin-top:10px; padding:8px 16px; border:none; background:#83A2DB; color:white; border-radius:8px;">한눈에 확인</button>
<canvas id="budgetChart" width="300" height="300"></canvas>
</div>
`;
}
function drawChart() {
const total = parseInt(document.getElementById("totalBudget").value);
const used = parseInt(document.getElementById("usedBudget").value);
const remain = total - used;
const ctx = document.getElementById('budgetChart').getContext('2d');
new Chart(ctx, {
type: 'doughnut',
data: {
labels: ['사용한 금액', '남은 금액'],
datasets: [{
data: [used, remain],
backgroundColor: ['#CE6969', '#83A2DB'],
borderWidth: 1
}]
},
options: {
responsive: true,
plugins: {
legend: {
position: 'bottom',
labels: {
font: {
family: 'SUIT',
size: 14
}
}
}
}
}
});
}
function showLunchMap() {
const lunchBudget = 8000; // 예시 값
document.getElementById("main").innerHTML = `
<div class="glass-box">
<h2>점심 메뉴 추천 🍱</h2>
<p>1인당 점심 예산: 약 ₩${lunchBudget.toLocaleString()}원</p>
<div id="map" style="width:100%; height:400px; border-radius:10px;"></div>
</div>
`;
const dankookDujon = { lat: 37.321877, lng: 127.126471 };
const map = new google.maps.Map(document.getElementById("map"), {
center: dankookDujon,
zoom: 15,
});
// 예시 마커 (단국대 위치)
new google.maps.Marker({
map,
position: dankookDujon,
title: "단국대학교 죽전캠퍼스",
});
}
function showSpending() {
document.getElementById("main").innerHTML = `
<div class="glass-row-2">
<div class="glass-col">
<h3>분야별 총 지출</h3>
<canvas id="categoryTotalChart"></canvas>
</div>
<div class="glass-col">
<h3>하루 지출 총합 변화</h3>
<canvas id="dailyTotalChart"></canvas>
</div>
</div>
<div class="glass-row-2">
<div class="glass-col" style="width: 100%;">
<h3>분야별 일별 지출 변화</h3>
<canvas id="categoryDailyChart"></canvas>
</div>
</div>
`;
new Chart(document.getElementById("categoryTotalChart"), {
type: 'bar',
data: {
labels: ['식비', '교통', '쇼핑', '구독', '기타'],
datasets: [{
label: '지출 금액',
data: [60000, 11500, 38500, 10000, 15000],
backgroundColor: '#83A2DB',
borderRadius: 8
}]
},
options: {
responsive: true,
plugins: { legend: { display: false } },
scales: { y: { beginAtZero: true } }
}
});
new Chart(document.getElementById("dailyTotalChart"), {
type: 'line',
data: {
labels: ['5/1', '5/2', '5/3', '5/4', '5/5'],
datasets: [{
label: '총 지출 금액',
data: [19000, 15000, 19500, 13000, 34500],
backgroundColor: 'rgba(131, 162, 219, 0.3)',
borderColor: '#83A2DB',
tension: 0.4,
fill: true
}]
},
options: {
responsive: true,
plugins: { legend: { position: 'bottom' } },
scales: { y: { beginAtZero: true } }
}
});
new Chart(document.getElementById("categoryDailyChart"), {
type: 'line',
data: {
labels: ['5/1', '5/2', '5/3', '5/4', '5/5'],
datasets: [
{ label: '식비', data: [10000, 12000, 9000, 6000, 23000], borderColor: '#FF6384', fill: false },
{ label: '교통', data: [3000, 2000, 2500, 1500, 2500], borderColor: '#36A2EB', fill: false },
{ label: '쇼핑', data: [6000, 10000, 8000, 5500, 9000], borderColor: '#FFCE56', fill: false },
]
},
options: {
responsive: true,
plugins: { legend: { position: 'bottom' } },
scales: { y: { beginAtZero: true } }
}
});
}
let scene, camera, renderer, model,controls;
function showEmotion() {
document.getElementById("main").innerHTML = `
<div class="glass-row-2" style="max-width: 800px; width: 100%;">
<div class="glass-col" style="flex: 1;">
<h3>감정을 입력하세요</h3>
<input type="text" id="emotionInput" placeholder="행복, 슬픔, 불안, 분노"
style="width: 100%; padding: 10px; border-radius: 8px;" />
<button onclick="loadEmotionModel()"
style="margin-top:10px; padding:8px 16px; border:none; background:#83A2DB; color:white; border-radius:8px;">
적용
</button>
</div>
<div class="glass-col" style="flex: 1;">
<h3>감정 캐릭터</h3>
<canvas id="threeCanvas" style="width: 100%; height: 300px;"></canvas>
</div>
</div>
<!-- 긍정 문구 박스는 처음엔 비워두고 나중에 조건에 따라 삽입 -->
<div class="glass-box" id="affirmationBox" style="max-width: 800px; display: none;">
</div>
`;
init3D(); // 3D 설정
}
function init3D() {
const canvas = document.getElementById('threeCanvas');
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(45, canvas.clientWidth / canvas.clientHeight, 0.1, 1000);
camera.position.set(0, 1.5,80); // 멀리서 보기
renderer = new THREE.WebGLRenderer({ canvas, alpha: true, antialias: true });
renderer.setSize(canvas.clientWidth, canvas.clientHeight);
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setClearColor(0x000000, 0); // 투명 배경
// 조명
const ambientLight = new THREE.AmbientLight(0xffffff, 1.2);
const directionalLight = new THREE.DirectionalLight(0xffffff, 1.5);
directionalLight.position.set(5, 10, 7.5);
scene.add(ambientLight, directionalLight);
controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.enablePan = false;
controls.enableZoom = false;
controls.target.set(0, 0, 0); // 모델 중심
controls.update();
// 리사이즈 대응
window.addEventListener('resize', () => {
const width = canvas.clientWidth;
const height = canvas.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
});
animate(); // 애니메이션 시작
}
function loadEmotionModel() {
const input = document.getElementById("emotionInput").value.trim();
const map = {
'행복': 'happy.glb',
'슬픔': 'sad.glb',
'불안': 'anxious.glb',
'분노': 'angry.glb'
};
const fileName = map[input];
if (!fileName) {
alert("감정은 '행복', '슬픔', '불안', '분노' 중에서 입력해주세요.");
return;
}
const loader = new THREE.GLTFLoader();
loader.load(`models/${fileName}`, (gltf) => {
if (model) scene.remove(model);
model = gltf.scene;
// 크기와 위치 조정
model.scale.set(0.06,0.06,0.06); // 캐릭터 사이즈 조절
model.position.set(0, -20, 0); // 아래로
model.rotation.y = 0; // 캐릭터가 앞을 보도록
// 모델 내부 구조 확인
model.traverse((child) => {
if (child.isMesh) {
child.castShadow = true;
child.receiveShadow = true;
console.log("Mesh:", child.name);
}
});
scene.add(model);
console.log("모델 씬에 추가");
});
// 감정에 따라 긍정 문구 박스를 보여주기
const negativeEmotions = ['슬픔', '분노', '불안'];
if (negativeEmotions.includes(input)) {
document.getElementById("affirmationBox").style.display = "block";
document.getElementById("affirmationBox").innerHTML = `
<div class="glass-box" id="affirmationBox" style="width: 100%; style="max-width: 800px;">
긍정 문구 불러오는 중...
</div>
`;
loadAffirmation();
} else {
document.getElementById("affirmationBox").style.display = "none";
document.getElementById("affirmationBox").innerHTML = '';
}
}
function animate() {
requestAnimationFrame(animate);
if (model) model.rotation.y += 0.005; // 천천히 회전
if (controls) controls.update(); // 마우스 회전 적용
renderer.render(scene, camera);
}
// function loadAffirmation() {
// fetch("https://cors-anywhere.herokuapp.com/https://zenquotes.io/api/random")
// .then(res => res.json())
// .then(data => {
// const quote = data[0].q;
// const author = data[0].a;
// document.getElementById("affirmationBox").innerHTML = `
// <h2>오늘의 긍정 문구 🌼</h2>
// <p style="font-size:18px;">"${quote}"</p>
// <p style="font-size:14px;color:gray;">— ${author}</p>
// `;
// })
// .catch(err => {
// document.getElementById("affirmationBox").innerHTML = `<p>긍정 문구를 불러오지 못했습니다.</p>`;
// });
// }
// affirmation.js
async function loadAffirmation() {
try {
const res = await fetch("https://cors-anywhere.herokuapp.com/https://www.affirmations.dev/");
if (!res.ok) throw new Error("리소스 요청 실패");
const data = await res.json();
const quote = data.affirmation;
document.getElementById("affirmationBox").innerHTML = `
<h2>오늘의 긍정 문구 🌼</h2>
<p style="font-size:18px;">"${quote}"</p>
`;
} catch (err) {
document.getElementById("affirmationBox").innerHTML = `<p>긍정 문구를 불러오지 못했습니다.</p>`;
console.error("오류 발생:", err);
}
}
// async function loadAffirmation() {
// try {
// // 1. 긍정 문구 가져오기 (영어)
// const res = await fetch("https://cors-anywhere.herokuapp.com/https://www.affirmations.dev/");
// if (!res.ok) throw new Error("리소스 요청 실패");
// const data = await res.json();
// const quote = data.affirmation;
// // 2. 영어 문구를 한국어로 번역 (LibreTranslate API 사용)
// const translateRes = await fetch("https://cors-anywhere.herokuapp.com/https://libretranslate.de/translate", {
// method: "POST",
// headers: {
// "Content-Type": "application/json"
// },
// body: JSON.stringify({
// q: quote,
// source: "en",
// target: "ko",
// format: "text"
// })
// });
// const translatedData = await translateRes.json();
// const translated = translatedData.translatedText;
// // 3. HTML에 출력
// document.getElementById("affirmationBox").innerHTML = `
// <h2>오늘의 긍정 문구 🌼</h2>
// <p style="font-size:18px;">"${quote}"</p>
// <p style="font-size:14px; color:gray;">→ ${translated}</p>
// `;
// } catch (err) {
// document.getElementById("affirmationBox").innerHTML = `<p>긍정 문구를 불러오지 못했습니다.</p>`;
// console.error("오류 발생:", err);
// }
// }
</script>
</body>
</html>