oss2024hnu / coursegraph-js

HTML5로 전공과목 정보 YAML 파일을 전공이수체계도나 표로 시각화하는 프로젝트
MIT License
3 stars 48 forks source link

이전에 올린 이슈에 대한 개선 #217

Closed leeseungho55 closed 2 months ago

leeseungho55 commented 2 months ago

사용자 피드백 시스템 구축에 대한 개선 코드 및 설명

->피드백 통계 및 분석 시스템 구축 제출된 피드백 데이터를 분석하여 과목별 평점, 주요 개선 사항 등을 시각화

html

피드백 통계 및 분석

데이터 시각화 (새로운 JS) document.addEventListener('DOMContentLoaded', function() { fetch('/getFeedbacks') .then(response => response.json()) .then(data => { // 평점 평균 계산 const ratings = {}; data.forEach(feedback => { if (!ratings[feedback.course]) ratings[feedback.course] = []; ratings[feedback.course].push(feedback.rating); }); const avgRatings = {}; for (let course in ratings) { avgRatings[course] = ratings[course].reduce((a, b) => a + b, 0) / ratings[course].length; }

        // 시각화 라이브러리 활용 (예: Chart.js)
        const ctx = document.getElementById('averageRatingsChart').getContext('2d');
        new Chart(ctx, {
            type: 'bar',
            data: {
                labels: Object.keys(avgRatings),
                datasets: [{
                    label: '평균 평점',
                    data: Object.values(avgRatings),
                    backgroundColor: 'rgba(75, 192, 192, 0.2)',
                    borderColor: 'rgba(75, 192, 192, 1)',
                    borderWidth: 1
                }]
            },
            options: {
                scales: {
                    y: { beginAtZero: true }
                }
            }
        });

        // 워드 클라우드 생성
        const comments = data.map(feedback => feedback.comments).join(' ');
        const wordCloud = WordCloud(document.getElementById('commentsWordCloud'), {
            list: comments.split(' ').map(word => [word, Math.random() * 100])
        });

        // 개선 사항 목록 생성
        const suggestions = data.filter(feedback => feedback.comments.includes('개선')).map(feedback => `<li>${feedback.comments}</li>`).join('');
        document.getElementById('improvementSuggestions').innerHTML = `<ul>${suggestions}</ul>`;
    });

});

//피드백 처리 및 통계(새로운 JS)

const express = require('express'); const app = express();

app.use(express.json());

let feedbacks = [];

app.post('/submitFeedback', (req, res) => { const feedback = req.body; feedbacks.push(feedback); res.json({ message: '피드백이 성공적으로 제출되었습니다!' }); });

app.get('/getFeedbacks', (req, res) => { res.json(feedbacks); });

const server = app.listen(3000, () => { console.log('Server is running on port 3000'); });

kyagrd commented 2 months ago

이전에 올린 이슈에 대한 개선이면 이전에 올린 이슈에서 논의해야죠 불필요하게 이슈 가지지키하지 맙시다. 그리고 갑자기 왜 백엔드를 쓰는지도 모르겠고요 ...