Skip to content

Commit

Permalink
Merge pull request #1 from aachintya/my-feature-branch
Browse files Browse the repository at this point in the history
Added next 5 points prediction and added CSS
  • Loading branch information
aachintya authored Oct 21, 2024
2 parents 1d0993b + 7b104b0 commit efa8c1c
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 33 deletions.
33 changes: 32 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
.env
# Python
*.pyc
__pycache__/
*.pyo
*.pyd

# Virtual environment
venv/

# Database
db.sqlite3

# Local settings
local_settings.py

# Media and static files
/media/
/static/

# Log files
*.log

# Environment variables
.env

# IDE files
.vscode/
.idea/

# OS files
.DS_Store
Thumbs.db
21 changes: 20 additions & 1 deletion analyzer/extract_graph_data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import cv2
import numpy as np
from scipy import stats

def extract_graph_data(image_path):
# Read the image
Expand All @@ -26,4 +27,22 @@ def analyze_data(data_points):
maxima = np.argmax(data_points, axis=0)
minima = np.argmin(data_points, axis=0)

return minima, maxima
return minima, maxima

def predict_next_points(data_points, num_predictions=5):
# Convert data points to a time series (assuming equal time intervals)
x = np.arange(len(data_points))
y = data_points[:, 1] # Assuming y-coordinates represent the data values

# Perform linear regression
slope, intercept, _, _, _ = stats.linregress(x, y)

# Predict next points
last_x = len(data_points)
predicted_points = []
for i in range(num_predictions):
next_x = last_x + i + 1
next_y = slope * next_x + intercept
predicted_points.append((next_x, next_y))

return predicted_points
9 changes: 5 additions & 4 deletions analyzer/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.shortcuts import render
from .forms import GraphUploadForm
from .extract_graph_data import extract_graph_data, analyze_data
from .extract_graph_data import extract_graph_data, analyze_data, predict_next_points
import os
from graph_analyzer.settings import BASE_DIR

Expand All @@ -19,13 +19,14 @@ def upload_image(request):
# Process image and get graph data
data_points = extract_graph_data(image_path)
minima, maxima = analyze_data(data_points)
predicted_points = predict_next_points(data_points)

context = {
'minima': minima,
'maxima': maxima
'maxima': maxima,
'predicted_points': predicted_points
}
return render(request, 'analyzer/index.html', context)
else:
form = GraphUploadForm()
return render(request, 'analyzer/index.html', {'form': form})

return render(request, 'analyzer/index.html', {'form': form})
Binary file modified db.sqlite3
Binary file not shown.
2 changes: 1 addition & 1 deletion graph_analyzer/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
ACCOUNT_AUTHENTICATION_METHOD='username_email'
ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS=10
ACCOUNT_EMAIL_REQUIRED=True
ACCOUNT_EMAIL_VERIFICATION='None'
ACCOUNT_EMAIL_VERIFICATION='optional'

ACCOUNT_FORMS = {
'signup': 'stellarledger.forms.CustomSignupForm',
Expand Down
6 changes: 6 additions & 0 deletions graph_analyzer/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@
"""
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
path("admin/", admin.site.urls),
path("", include("analyzer.urls")),
]

if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 17 additions & 17 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
Django==5.0.3
django-admin-sortable2==1.0.4
django-allauth==0.61.1
django-cors-headers==4.3.1
django-countries==7.5.1
django-timezone-field==6.1.0
google-api-core==2.11.0
google-api-python-client==2.37.0
google-auth==2.16.2
google-auth-httplib2==0.1.0
numpy==1.26.4
oauth2client==4.1.3
oauthlib==3.2.2
opencv-python==4.9.0.80
pandas==2.2.1
pip-tools==6.12.1
virtualenv==20.20.0
asgiref==3.8.1
certifi==2024.8.30
cffi==1.17.1
charset-normalizer==3.4.0
cryptography==43.0.3
Django==5.1.2
django-allauth==65.0.2
idna==3.10
numpy==2.1.2
opencv-python==4.10.0.84
pillow==11.0.0
pycparser==2.22
PyJWT==2.9.0
python-dotenv==1.0.1
requests==2.32.3
sqlparse==0.5.1
urllib3==2.2.3
70 changes: 61 additions & 9 deletions templates/analyzer/index.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,71 @@
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<title>Graph Analyzer</title>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="{% static 'css/graph_analyzer_styles.css' %}">
</head>
<body>
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit">
</form>
<h2>Graph Analysis Results</h2>
<p>Minima: {{ minima }}</p>
<p>Maxima: {{ maxima }}</p>
<header>
<div class="container">
<h1>Graph Analyzer</h1>
</div>
</header>

<main class="container">
<section class="form-section">
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
<div class="file-input-wrapper">
<label for="{{ form.image.id_for_label }}">Choose an image file:</label>
<span class="btn">Select File</span>
{{ form.image }}
<span class="file-name">No file chosen</span>
</div>
<button type="submit" class="submit-btn">Upload and Analyze</button>
</form>
</section>

{% if minima is not None and maxima is not None %}
<section class="results">
<h2>Graph Analysis Results</h2>
<div class="result-detail">
<p><span class="result-label">Minima:</span> {{ minima }}</p>
<p><span class="result-label">Maxima:</span> {{ maxima }}</p>
</div>
</section>
{% endif %}

{% if predicted_points %}
<section class="results">
<h2>Predicted Next 5 Points</h2>
<ul class="predicted-points">
{% for point in predicted_points %}
<li>
<span class="result-label">Point {{ forloop.counter }}:</span>
<span>X: {{ point.0 }},</span>
<span>Y: {{ point.1|floatformat:2 }}</span>
</li>
{% endfor %}
</ul>
</section>
{% endif %}
</main>

<footer>
<div class="container">
<p>&copy; 2024 Graph Analyzer. All rights reserved.</p>
</div>
</footer>

<script>
document.querySelector('input[type="file"]').addEventListener('change', function(e) {
var fileName = e.target.files[0].name;
document.querySelector('.file-name').textContent = fileName;
});
</script>
</body>
</html>

0 comments on commit efa8c1c

Please sign in to comment.