From 62d2efbc98eb33f423c6e5e3f7b2352f1f39a881 Mon Sep 17 00:00:00 2001 From: Ananya Gupta <145869907+ananyag309@users.noreply.github.com> Date: Thu, 27 Jun 2024 12:10:42 +0530 Subject: [PATCH 1/7] added Dream Journal Calculator --- Dream Journal Calculator/index.html | 37 ++++++++++++++++++++++ Dream Journal Calculator/script.js | 46 +++++++++++++++++++++++++++ Dream Journal Calculator/styles.css | 48 +++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 Dream Journal Calculator/index.html create mode 100644 Dream Journal Calculator/script.js create mode 100644 Dream Journal Calculator/styles.css diff --git a/Dream Journal Calculator/index.html b/Dream Journal Calculator/index.html new file mode 100644 index 00000000..01005e46 --- /dev/null +++ b/Dream Journal Calculator/index.html @@ -0,0 +1,37 @@ + + + + + + Dream Journal Calculator + + + +
+

Dream Journal Calculator

+
+ + + + + + + + + + + + + +
+ +

Word Cloud

+
+ +

Analysis

+
+
+ + + + diff --git a/Dream Journal Calculator/script.js b/Dream Journal Calculator/script.js new file mode 100644 index 00000000..ca3b3f3f --- /dev/null +++ b/Dream Journal Calculator/script.js @@ -0,0 +1,46 @@ +document.getElementById('dreamForm').addEventListener('submit', function(event) { + event.preventDefault(); + + const title = document.getElementById('dreamTitle').value; + const date = document.getElementById('dreamDate').value; + const entry = document.getElementById('dreamEntry').value; + const emotions = document.getElementById('dreamEmotions').value.split(',').map(e => e.trim()); + + const words = extractKeywords(entry); + displayWordCloud(words); + displayAnalysis(words, emotions); +}); + +function extractKeywords(text) { + const stopwords = ["I", "was", "and", "the", "a", "to", "in", "of", "that", "it"]; + const words = text.split(/\W+/).filter(word => !stopwords.includes(word.toLowerCase())); + const wordCount = {}; + + words.forEach(word => { + word = word.toLowerCase(); + wordCount[word] = (wordCount[word] || 0) + 1; + }); + + return Object.entries(wordCount).map(([word, size]) => ({ word, size })); +} + +function displayWordCloud(words) { + const wordCloudData = words.map(({ word, size }) => [word, size * 10]); + WordCloud(document.getElementById('wordCloud'), { list: wordCloudData }); +} + +function displayAnalysis(words, emotions) { + const analysisDiv = document.getElementById('analysis'); + analysisDiv.innerHTML = ''; + + const recurringWords = words.filter(({ size }) => size > 1).map(({ word }) => word); + const emotionList = emotions.join(', '); + + const recurringWordsElement = document.createElement('p'); + recurringWordsElement.textContent = `Recurring words: ${recurringWords.join(', ')}`; + analysisDiv.appendChild(recurringWordsElement); + + const emotionElement = document.createElement('p'); + emotionElement.textContent = `Emotions: ${emotionList}`; + analysisDiv.appendChild(emotionElement); +} diff --git a/Dream Journal Calculator/styles.css b/Dream Journal Calculator/styles.css new file mode 100644 index 00000000..0ad3b43e --- /dev/null +++ b/Dream Journal Calculator/styles.css @@ -0,0 +1,48 @@ +body { + font-family: Arial, sans-serif; + background-color: #f0f0f0; + color: #333; +} + +.container { + width: 80%; + margin: 0 auto; + padding: 20px; + background-color: #fff; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); +} + +h1, h2 { + text-align: center; +} + +form { + display: flex; + flex-direction: column; + margin-bottom: 20px; +} + +label { + margin-top: 10px; +} + +input, textarea, button { + padding: 10px; + margin-top: 5px; +} + +button { + background-color: #007BFF; + color: white; + border: none; + cursor: pointer; + margin-top: 20px; +} + +button:hover { + background-color: #0056b3; +} + +#wordCloud { + margin: 0 auto; +} From 230173f92110c2c47024d6a72a590c9c20597e3a Mon Sep 17 00:00:00 2001 From: Ananya Gupta <145869907+ananyag309@users.noreply.github.com> Date: Fri, 28 Jun 2024 10:25:51 +0530 Subject: [PATCH 2/7] Update index.html --- Dream Journal Calculator/index.html | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Dream Journal Calculator/index.html b/Dream Journal Calculator/index.html index 01005e46..d5bacd47 100644 --- a/Dream Journal Calculator/index.html +++ b/Dream Journal Calculator/index.html @@ -5,6 +5,7 @@ Dream Journal Calculator +
@@ -12,22 +13,16 @@

Dream Journal Calculator

- - - -
-

Word Cloud

-

Analysis

From c0530300023b91dfed113f795a20407696e1c0ca Mon Sep 17 00:00:00 2001 From: Ananya Gupta <145869907+ananyag309@users.noreply.github.com> Date: Fri, 28 Jun 2024 10:26:31 +0530 Subject: [PATCH 3/7] added manifest file --- Dream Journal Calculator/manifest.json | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Dream Journal Calculator/manifest.json diff --git a/Dream Journal Calculator/manifest.json b/Dream Journal Calculator/manifest.json new file mode 100644 index 00000000..0c4027c3 --- /dev/null +++ b/Dream Journal Calculator/manifest.json @@ -0,0 +1,21 @@ +{ + "name": "Dream Journal Calculator", + "short_name": "DreamCalc", + "start_url": "/", + "display": "standalone", + "background_color": "#ffffff", + "theme_color": "#007BFF", + "description": "A web app for analyzing dream journal entries.", + "icons": [ + { + "src": "images/icon-192x192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "images/icon-512x512.png", + "sizes": "512x512", + "type": "image/png" + } + ] +} From f57e3d81cb4271855238070c0a8af678cca427d5 Mon Sep 17 00:00:00 2001 From: Ananya Gupta <145869907+ananyag309@users.noreply.github.com> Date: Fri, 28 Jun 2024 16:03:15 +0530 Subject: [PATCH 4/7] Update index.html --- Dream Journal Calculator/index.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dream Journal Calculator/index.html b/Dream Journal Calculator/index.html index d5bacd47..bd3a7592 100644 --- a/Dream Journal Calculator/index.html +++ b/Dream Journal Calculator/index.html @@ -20,11 +20,14 @@

Dream Journal Calculator

+

Word Cloud

Analysis

+

Past Dreams

+
From 8095453125ae4ae5e54529896adacd8b35b5ed74 Mon Sep 17 00:00:00 2001 From: Ananya Gupta <145869907+ananyag309@users.noreply.github.com> Date: Fri, 28 Jun 2024 16:03:45 +0530 Subject: [PATCH 5/7] Update script.js --- Dream Journal Calculator/script.js | 116 ++++++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 2 deletions(-) diff --git a/Dream Journal Calculator/script.js b/Dream Journal Calculator/script.js index ca3b3f3f..d95b95a4 100644 --- a/Dream Journal Calculator/script.js +++ b/Dream Journal Calculator/script.js @@ -8,7 +8,16 @@ document.getElementById('dreamForm').addEventListener('submit', function(event) const words = extractKeywords(entry); displayWordCloud(words); - displayAnalysis(words, emotions); + displayAnalysis(words, emotions, entry); + + storeDream({ title, date, entry, emotions }); + displayPastDreams(); +}); + +document.getElementById('resetButton').addEventListener('click', function() { + document.getElementById('dreamForm').reset(); + document.getElementById('wordCloud').innerHTML = ''; + document.getElementById('analysis').innerHTML = ''; }); function extractKeywords(text) { @@ -29,7 +38,7 @@ function displayWordCloud(words) { WordCloud(document.getElementById('wordCloud'), { list: wordCloudData }); } -function displayAnalysis(words, emotions) { +function displayAnalysis(words, emotions, entry) { const analysisDiv = document.getElementById('analysis'); analysisDiv.innerHTML = ''; @@ -43,4 +52,107 @@ function displayAnalysis(words, emotions) { const emotionElement = document.createElement('p'); emotionElement.textContent = `Emotions: ${emotionList}`; analysisDiv.appendChild(emotionElement); + + const sentiment = analyzeSentiment(entry); + const sentimentElement = document.createElement('p'); + sentimentElement.textContent = `Sentiment: ${sentiment.text}`; + analysisDiv.appendChild(sentimentElement); + + const category = categorizeDream(entry); + const categoryElement = document.createElement('p'); + categoryElement.textContent = `Category: ${category}`; + analysisDiv.appendChild(categoryElement); + + const sentimentBar = document.createElement('div'); + sentimentBar.className = 'sentiment-bar'; + sentimentBar.innerHTML = `
+ ${sentiment.positivePercentage.toFixed(1)}% +
+
+ ${sentiment.negativePercentage.toFixed(1)}% +
`; + analysisDiv.appendChild(sentimentBar); +} + +function analyzeSentiment(text) { + const positiveWords = ["happy", "joy", "excited", "love"]; + const negativeWords = ["sad", "angry", "fear", "hate"]; + let score = 0; + let positiveCount = 0; + let negativeCount = 0; + + text.split(/\W+/).forEach(word => { + if (positiveWords.includes(word.toLowerCase())) { + score++; + positiveCount++; + } + if (negativeWords.includes(word.toLowerCase())) { + score--; + negativeCount++; + } + }); + + const total = positiveCount + negativeCount; + const positivePercentage = total ? (positiveCount / total) * 100 : 0; + const negativePercentage = total ? (negativeCount / total) * 100 : 0; + + return { + text: score > 0 ? 'Positive' : score < 0 ? 'Negative' : 'Neutral', + positivePercentage, + negativePercentage + }; +} + +function categorizeDream(text) { + const keywords = { + "Adventure": ["explore", "travel", "journey"], + "Nightmare": ["chase", "fear", "dark"], + "Fantasy": ["magic", "fly", "unicorn"], + }; + + for (const [category, words] of Object.entries(keywords)) { + if (words.some(word => text.toLowerCase().includes(word))) { + return category; + } + } + + return "Uncategorized"; +} + +function storeDream(dream) { + const dreams = JSON.parse(localStorage.getItem('dreams')) || []; + dreams.push(dream); + localStorage.setItem('dreams', JSON.stringify(dreams)); +} + +function displayPastDreams() { + const dreams = JSON.parse(localStorage.getItem('dreams')) || []; + const pastDreamsDiv = document.getElementById('pastDreams'); + pastDreamsDiv.innerHTML = ''; + + dreams.forEach(dream => { + const dreamElement = document.createElement('div'); + dreamElement.classList.add('dream'); + + const titleElement = document.createElement('h3'); + titleElement.textContent = dream.title; + dreamElement.appendChild(titleElement); + + const dateElement = document.createElement('p'); + dateElement.textContent = `Date: ${dream.date}`; + dreamElement.appendChild(dateElement); + + const entryElement = document.createElement('p'); + entryElement.textContent = dream.entry; + dreamElement.appendChild(entryElement); + + const emotionsElement = document.createElement('p'); + emotionsElement.textContent = `Emotions: ${dream.emotions.join(', ')}`; + dreamElement.appendChild(emotionsElement); + + pastDreamsDiv.appendChild(dreamElement); + }); } + +// Load past dreams on page load +document.addEventListener('DOMContentLoaded', displayPastDreams); From cdac407c933ff5f58fb8e9344fd2b2c2587fe909 Mon Sep 17 00:00:00 2001 From: Ananya Gupta <145869907+ananyag309@users.noreply.github.com> Date: Fri, 28 Jun 2024 16:04:11 +0530 Subject: [PATCH 6/7] Update styles.css --- Dream Journal Calculator/styles.css | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Dream Journal Calculator/styles.css b/Dream Journal Calculator/styles.css index 0ad3b43e..d9d2446c 100644 --- a/Dream Journal Calculator/styles.css +++ b/Dream Journal Calculator/styles.css @@ -46,3 +46,38 @@ button:hover { #wordCloud { margin: 0 auto; } + +.dream { + border-bottom: 1px solid #ccc; + padding: 10px 0; +} + +.dream h3 { + margin: 0; +} + +.dream p { + margin: 5px 0; +} + +.sentiment-bar { + display: flex; + height: 20px; + margin-top: 10px; + position: relative; + background-color: #e0e0e0; +} + +.sentiment-positive { + background-color: green; + text-align: center; + color: white; + line-height: 20px; +} + +.sentiment-negative { + background-color: red; + text-align: center; + color: white; + line-height: 20px; +} From c705717b7667521d5d5160e71dc412652a55ec71 Mon Sep 17 00:00:00 2001 From: Ananya Gupta <145869907+ananyag309@users.noreply.github.com> Date: Fri, 28 Jun 2024 16:04:48 +0530 Subject: [PATCH 7/7] Add files via upload --- Dream Journal Calculator/README.md | 58 ++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Dream Journal Calculator/README.md diff --git a/Dream Journal Calculator/README.md b/Dream Journal Calculator/README.md new file mode 100644 index 00000000..1969c52b --- /dev/null +++ b/Dream Journal Calculator/README.md @@ -0,0 +1,58 @@ +# Dream Journal Calculator + +The Dream Journal Calculator is a web application that allows users to record their dreams, analyze the content, and visualize the emotions associated with the dream. It also provides a sentiment analysis to determine whether the dream was positive or negative. + +## Features + +- Record dream entries with title, date, description, and emotions. +- Generate a word cloud from the dream description. +- Analyze and display recurring words and emotions. +- Sentiment analysis to determine the positivity or negativity of the dream. +- Categorize the dream based on specific keywords. +- Store and display past dreams. +- Reset button to clear the form and results. + +## Input Fields + +1. **Dream Title**: A short title for the dream. +2. **Date**: The date when the dream occurred. +3. **Dream Entry**: A detailed description of the dream. +4. **Emotions**: Comma-separated list of emotions felt during the dream. + +## Output + +1. **Word Cloud**: Visual representation of the most frequently occurring words in the dream description. +2. **Recurring Words**: List of words that appear multiple times in the dream description. +3. **Emotions**: List of emotions associated with the dream. +4. **Sentiment Analysis**: Displays whether the dream is positive, negative, or neutral. +5. **Sentiment Bar**: Visual bar showing the percentage of positive and negative words in the dream. +6. **Category**: Categorization of the dream based on specific keywords. +7. **Past Dreams**: List of previously recorded dreams with details. + +## How to Use + +1. Fill in the form with your dream details: + - **Dream Title**: Enter a title for your dream. + - **Date**: Select the date of the dream. + - **Dream Entry**: Write a detailed description of your dream. + - **Emotions**: List the emotions you felt during the dream, separated by commas. + +2. Click the "Analyze Dream" button to analyze your dream. + +3. View the results: + - The word cloud will display the most frequently occurring words in your dream description. + - Recurring words and emotions will be listed below the word cloud. + - Sentiment analysis will show whether the dream is positive, negative, or neutral. + - A sentiment bar will visually represent the percentage of positive and negative words. + - The category of the dream will be displayed based on specific keywords. + - Past dreams will be listed below the analysis. + +4. Click the "Reset" button to clear the form and results. + +## Technologies Used + +- HTML +- CSS +- JavaScript +- WordCloud2.js (for generating word clouds) +