Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .env

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ celerybeat.pid
*.sage.py

# Environments

.env
.venv
env/
venv/
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Follow the steps below to run the project locally using Docker or manually.
### ⚙️ Prerequisites

- [Docker](https://www.docker.com/products/docker-desktop) installed and running
- [PostgreSQL](https://www.postgresql.org/) installed.
- Python 3.10+
- (Optional) Live server if running without Docker

Expand All @@ -71,6 +72,8 @@ In your terminal:
```bash
git clone https://github.com/IU-Capstone-Project-2025/Metalytics.git
cd Metalytics
echo "DB_USER=postgres" > .env
echo "DB_PASSWORD=postgres" >> .env
```

### 💻 Step 2 — Run with Docker (Recommended)
Expand Down
10 changes: 10 additions & 0 deletions frontend/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,17 @@ span {

.news__info {
width: 94%;
height: 70%;
text-align: center;
font-size: 24px;
line-height: 120%;
letter-spacing: 1px;
color: var(--white);
overflow-y: scroll;
}

.news__info::-webkit-scrollbar {
display: none;
}

.news__date {
Expand All @@ -305,6 +311,10 @@ span {
right: -21px;
}

.swiper-slide>div {
height: inherit;
}

/* Graph */

.graph {
Expand Down
35 changes: 9 additions & 26 deletions frontend/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,6 @@ document.addEventListener("DOMContentLoaded", () => {
}
}

function shortNumberFormat(num) {
if (selectedMetal === 'zinc') {
return num.toFixed(4);
}

if (Math.abs(num) >= 1e6) return (num / 1e6).toFixed(1) + 'M';
if (Math.abs(num) >= 1e3) return (num / 1e3).toFixed(1) + 'K';
return num.toFixed(1);
}

function getYAxisOptions() {
if (window.innerWidth <= 768) {
return {
Expand All @@ -104,9 +94,7 @@ document.addEventListener("DOMContentLoaded", () => {
else {
return {
ticks: {
callback: function(value) {
return shortNumberFormat(value);
}
display: true
}
};
}
Expand Down Expand Up @@ -327,11 +315,14 @@ document.addEventListener("DOMContentLoaded", () => {
}
}

// Initialize prediction button availability for gold (default metal)
setPredictedButtonAvailability(true);

document.querySelectorAll('[data-metal]').forEach(button => {
button.addEventListener('click', async () => {
selectedMetal = button.dataset.metal;
activeMetal();
if (selectedMetal === 'silver' || selectedMetal === 'zinc') {
if (selectedMetal === 'zinc') {
selectedDate = 'day';
setPredictedButtonAvailability(false);
document.querySelectorAll('.graph__button[data-interval]').forEach(btn => {
Expand All @@ -343,7 +334,7 @@ document.addEventListener("DOMContentLoaded", () => {
fetchData('day');
}

else if (selectedMetal === 'gold') {
else if (selectedMetal === 'gold' || selectedMetal === 'silver') {
selectedDate = 'day';
setPredictedButtonAvailability(true);
document.querySelectorAll('.graph__button[data-interval]').forEach(btn => {
Expand Down Expand Up @@ -543,27 +534,21 @@ function getFallbackNews(metal) {
async function updateNewsContent() {
const swiperWrapper = document.querySelector('.swiper-wrapper');

// Show loading state
swiperWrapper.innerHTML = '<div class="swiper-slide"><div><p class="news__info">Loading news...</p></div></div>';

try {
// Fetch news from backend
const newsData = await fetchNewsFromBackend(selectedMetal);

swiperWrapper.innerHTML = '';

// Helper to render news with ellipsis and link
function renderNewsText(newsItem) {
let text = newsItem.preview || newsItem.title;
if (text && text.trim().endsWith('...') && newsItem.url) {
// Remove the last ... and add link on a new line
text = text.replace(/\.\.\.$/, '...<br><a href="' + newsItem.url + '" target="_blank" style="color:#D3AC49;">More details here</a>');
if (selectedMetal !== 'silver' && newsItem.url) {
text = text + '<br><a href="' + newsItem.url + '" target="_blank" style="color:#D3AC49;">More details</a>';
}
return text;
}

if (newsData.length === 0) {
// Try fallback news for metals without backend data
const fallbackData = getFallbackNews(selectedMetal);
if (fallbackData.length > 0) {
fallbackData.slice(0, 4).forEach(newsItem => {
Expand All @@ -586,7 +571,6 @@ async function updateNewsContent() {
swiperWrapper.appendChild(slide);
});
} else {
// Show no news message
const slide = document.createElement('div');
slide.className = 'swiper-slide';
slide.innerHTML = `
Expand All @@ -602,7 +586,6 @@ async function updateNewsContent() {
swiperWrapper.appendChild(slide);
}
} else {
// Display real news from backend, limit to 4
newsData.slice(0, 4).forEach(newsItem => {
const slide = document.createElement('div');
slide.className = 'swiper-slide';
Expand All @@ -622,7 +605,7 @@ async function updateNewsContent() {

if (swiper) {
swiper.update();
swiper.slideTo(0, 0); // Go to the first slide instantly
swiper.slideTo(0, 0);
}
} catch (error) {
console.error("Error updating news content:", error);
Expand Down