From 575d3664970dce0debc182f955ac144a02e01df1 Mon Sep 17 00:00:00 2001 From: IT4MED_Hub <140026184+IT4MED@users.noreply.github.com> Date: Sat, 7 Oct 2023 13:16:54 +0300 Subject: [PATCH 1/6] Update main.py --- BMI_Calc_1/main.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/BMI_Calc_1/main.py b/BMI_Calc_1/main.py index ef6e69c..6742436 100644 --- a/BMI_Calc_1/main.py +++ b/BMI_Calc_1/main.py @@ -1,7 +1,11 @@ -def calculate_bmi(weight, height): +def calculate_bmi(weight, height_cm): try: weight = float(weight) - height = float(height) + height = float(height_cm) / 100 + + if height == 0: + raise ZeroDivisionError + bmi = weight / (height ** 2) return bmi except ValueError: @@ -9,16 +13,24 @@ def calculate_bmi(weight, height): except ZeroDivisionError: return None + def main(): - weight = input("Введите вес (кг): ") - height = input("Введите рост (м): ") + try: + weight = float(input("Введите вес (кг): ")) + height_cm = float(input("Введите рост (см): ")) - bmi = calculate_bmi(weight, height) + if weight <= 0 or height_cm <= 0: + raise ValueError - if bmi is not None: - print(f"Индекс массы тела (BMI): {bmi:.2f}") - else: + bmi = calculate_bmi(weight, height_cm) + + if bmi is not None: + print(f"Индекс массы тела (BMI): {bmi:.2f}") + else: + print("Ошибка: введены некорректные данные!") + except ValueError: print("Ошибка: введены некорректные данные!") + if __name__ == "__main__": main() From a6d11e1053f283f1b4840a74fae321791ce0a805 Mon Sep 17 00:00:00 2001 From: German Kosach Date: Sat, 7 Oct 2023 13:26:27 +0300 Subject: [PATCH 2/6] =?UTF-8?q?=D0=B7=D0=B0=D0=BF=D1=83=D1=88=D0=B8=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BMI_Calc_1/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/BMI_Calc_1/README.md b/BMI_Calc_1/README.md index e69de29..3f05dd0 100644 --- a/BMI_Calc_1/README.md +++ b/BMI_Calc_1/README.md @@ -0,0 +1 @@ +Выполнил \ No newline at end of file From 9f1f5e5fbefb3629bfa4eb9483a28fe61e0b86de Mon Sep 17 00:00:00 2001 From: German Kosach Date: Thu, 12 Oct 2023 19:00:43 +0300 Subject: [PATCH 3/6] Plotly HTML walkthrogh --- interactive_graphic/graphics/__init__.py | 0 interactive_graphic/graphics/admin.py | 3 + interactive_graphic/graphics/apps.py | 6 + .../graphics/migrations/__init__.py | 0 interactive_graphic/graphics/models.py | 3 + .../static/graphics/interactive_graphic.html | 12 ++ .../graphics/interactive_graphic.html | 12 ++ interactive_graphic/graphics/tests.py | 3 + interactive_graphic/graphics/urls.py | 9 ++ interactive_graphic/graphics/views.py | 25 ++++ .../interactive_graphic/__init__.py | 0 .../interactive_graphic/asgi.py | 16 +++ .../interactive_graphic/settings.py | 124 ++++++++++++++++++ .../interactive_graphic/urls.py | 10 ++ .../interactive_graphic/wsgi.py | 16 +++ interactive_graphic/manage.py | 22 ++++ 16 files changed, 261 insertions(+) create mode 100644 interactive_graphic/graphics/__init__.py create mode 100644 interactive_graphic/graphics/admin.py create mode 100644 interactive_graphic/graphics/apps.py create mode 100644 interactive_graphic/graphics/migrations/__init__.py create mode 100644 interactive_graphic/graphics/models.py create mode 100644 interactive_graphic/graphics/static/graphics/interactive_graphic.html create mode 100644 interactive_graphic/graphics/templates/graphics/interactive_graphic.html create mode 100644 interactive_graphic/graphics/tests.py create mode 100644 interactive_graphic/graphics/urls.py create mode 100644 interactive_graphic/graphics/views.py create mode 100644 interactive_graphic/interactive_graphic/__init__.py create mode 100644 interactive_graphic/interactive_graphic/asgi.py create mode 100644 interactive_graphic/interactive_graphic/settings.py create mode 100644 interactive_graphic/interactive_graphic/urls.py create mode 100644 interactive_graphic/interactive_graphic/wsgi.py create mode 100644 interactive_graphic/manage.py diff --git a/interactive_graphic/graphics/__init__.py b/interactive_graphic/graphics/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/interactive_graphic/graphics/admin.py b/interactive_graphic/graphics/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/interactive_graphic/graphics/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/interactive_graphic/graphics/apps.py b/interactive_graphic/graphics/apps.py new file mode 100644 index 0000000..20cbe35 --- /dev/null +++ b/interactive_graphic/graphics/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class GraphicsConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'graphics' diff --git a/interactive_graphic/graphics/migrations/__init__.py b/interactive_graphic/graphics/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/interactive_graphic/graphics/models.py b/interactive_graphic/graphics/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/interactive_graphic/graphics/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/interactive_graphic/graphics/static/graphics/interactive_graphic.html b/interactive_graphic/graphics/static/graphics/interactive_graphic.html new file mode 100644 index 0000000..f65de3f --- /dev/null +++ b/interactive_graphic/graphics/static/graphics/interactive_graphic.html @@ -0,0 +1,12 @@ + + + + + + + Interactive Graph + + + {{ graph_html|safe }} + + \ No newline at end of file diff --git a/interactive_graphic/graphics/templates/graphics/interactive_graphic.html b/interactive_graphic/graphics/templates/graphics/interactive_graphic.html new file mode 100644 index 0000000..f65de3f --- /dev/null +++ b/interactive_graphic/graphics/templates/graphics/interactive_graphic.html @@ -0,0 +1,12 @@ + + + + + + + Interactive Graph + + + {{ graph_html|safe }} + + \ No newline at end of file diff --git a/interactive_graphic/graphics/tests.py b/interactive_graphic/graphics/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/interactive_graphic/graphics/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/interactive_graphic/graphics/urls.py b/interactive_graphic/graphics/urls.py new file mode 100644 index 0000000..d48cbf6 --- /dev/null +++ b/interactive_graphic/graphics/urls.py @@ -0,0 +1,9 @@ +# fmt: off + +from django.urls import path +from . import views + +urlpatterns = [ + path('interactive_graph/', views.interactive_graphic, name='interactive_graphic'), + # Other patterns for your app +] diff --git a/interactive_graphic/graphics/views.py b/interactive_graphic/graphics/views.py new file mode 100644 index 0000000..75d5818 --- /dev/null +++ b/interactive_graphic/graphics/views.py @@ -0,0 +1,25 @@ +# views.py + +from django.shortcuts import render +import plotly.offline as opy +import plotly.graph_objs as go + + +def interactive_graphic(request): + # Данные для оси x (значения от -10 до 10 с шагом 1) + x = list(range(-10, 11)) + + # Данные для оси y (значения функции y = 2x) + y = [2 * val for val in x] + + # Создание интерактивного линейного графика + fig = go.Figure(data=go.Scatter(x=x, y=y, mode='lines+markers')) + + # Добавление подписей осей и заголовка + fig.update_layout(title='Интерактивный график функции y = 2x', + xaxis_title='x', yaxis_title='y') + + # Save the Plotly graph as a standalone HTML file + graph_html = opy.plot(fig, auto_open=False, output_type='div') + + return render(request, 'graphics/interactive_graphic.html', {'graph_html': graph_html}) diff --git a/interactive_graphic/interactive_graphic/__init__.py b/interactive_graphic/interactive_graphic/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/interactive_graphic/interactive_graphic/asgi.py b/interactive_graphic/interactive_graphic/asgi.py new file mode 100644 index 0000000..27ac15d --- /dev/null +++ b/interactive_graphic/interactive_graphic/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for interactive_graphic project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'interactive_graphic.settings') + +application = get_asgi_application() diff --git a/interactive_graphic/interactive_graphic/settings.py b/interactive_graphic/interactive_graphic/settings.py new file mode 100644 index 0000000..090cb07 --- /dev/null +++ b/interactive_graphic/interactive_graphic/settings.py @@ -0,0 +1,124 @@ +""" +Django settings for interactive_graphic project. + +Generated by 'django-admin startproject' using Django 4.2.3. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.2/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-yx74ef%lg-kyl1x^5wn9$1+mt81tpn8%%%i7^$0gj-rtw31e5o' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'graphics', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'interactive_graphic.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'interactive_graphic.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/4.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/4.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.2/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/interactive_graphic/interactive_graphic/urls.py b/interactive_graphic/interactive_graphic/urls.py new file mode 100644 index 0000000..d6449e6 --- /dev/null +++ b/interactive_graphic/interactive_graphic/urls.py @@ -0,0 +1,10 @@ +from django.contrib import admin +from django.urls import path, include + +urlpatterns = [ + path('admin/', admin.site.urls), + # Include the URLs from the graphics app + path('graphics/', include('graphics.urls')), + # Add a direct route to the interactive_graphic view + path('graphics/interactive_graph/', include('graphics.urls')), +] diff --git a/interactive_graphic/interactive_graphic/wsgi.py b/interactive_graphic/interactive_graphic/wsgi.py new file mode 100644 index 0000000..bb9ab64 --- /dev/null +++ b/interactive_graphic/interactive_graphic/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for interactive_graphic project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'interactive_graphic.settings') + +application = get_wsgi_application() diff --git a/interactive_graphic/manage.py b/interactive_graphic/manage.py new file mode 100644 index 0000000..ccde54e --- /dev/null +++ b/interactive_graphic/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'interactive_graphic.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() From 182480a77a5bd53dc9943e7b2343f7bd49b37979 Mon Sep 17 00:00:00 2001 From: German Kosach Date: Thu, 12 Oct 2023 19:25:17 +0300 Subject: [PATCH 4/6] easy mode on --- interactive_graphics/graphics/__init__.py | 0 interactive_graphics/graphics/admin.py | 3 + interactive_graphics/graphics/apps.py | 6 + .../graphics/migrations/__init__.py | 0 interactive_graphics/graphics/models.py | 3 + .../graphics/interactive_graphic.html | 12 ++ interactive_graphics/graphics/tests.py | 3 + interactive_graphics/graphics/urls.py | 8 ++ interactive_graphics/graphics/views.py | 15 +++ .../interactive_graphics/__init__.py | 0 .../interactive_graphics/asgi.py | 16 +++ .../interactive_graphics/settings.py | 124 ++++++++++++++++++ .../interactive_graphics/urls.py | 8 ++ .../interactive_graphics/wsgi.py | 16 +++ interactive_graphics/manage.py | 22 ++++ 15 files changed, 236 insertions(+) create mode 100644 interactive_graphics/graphics/__init__.py create mode 100644 interactive_graphics/graphics/admin.py create mode 100644 interactive_graphics/graphics/apps.py create mode 100644 interactive_graphics/graphics/migrations/__init__.py create mode 100644 interactive_graphics/graphics/models.py create mode 100644 interactive_graphics/graphics/templates/graphics/interactive_graphic.html create mode 100644 interactive_graphics/graphics/tests.py create mode 100644 interactive_graphics/graphics/urls.py create mode 100644 interactive_graphics/graphics/views.py create mode 100644 interactive_graphics/interactive_graphics/__init__.py create mode 100644 interactive_graphics/interactive_graphics/asgi.py create mode 100644 interactive_graphics/interactive_graphics/settings.py create mode 100644 interactive_graphics/interactive_graphics/urls.py create mode 100644 interactive_graphics/interactive_graphics/wsgi.py create mode 100644 interactive_graphics/manage.py diff --git a/interactive_graphics/graphics/__init__.py b/interactive_graphics/graphics/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/interactive_graphics/graphics/admin.py b/interactive_graphics/graphics/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/interactive_graphics/graphics/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/interactive_graphics/graphics/apps.py b/interactive_graphics/graphics/apps.py new file mode 100644 index 0000000..20cbe35 --- /dev/null +++ b/interactive_graphics/graphics/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class GraphicsConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'graphics' diff --git a/interactive_graphics/graphics/migrations/__init__.py b/interactive_graphics/graphics/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/interactive_graphics/graphics/models.py b/interactive_graphics/graphics/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/interactive_graphics/graphics/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/interactive_graphics/graphics/templates/graphics/interactive_graphic.html b/interactive_graphics/graphics/templates/graphics/interactive_graphic.html new file mode 100644 index 0000000..f65de3f --- /dev/null +++ b/interactive_graphics/graphics/templates/graphics/interactive_graphic.html @@ -0,0 +1,12 @@ + + + + + + + Interactive Graph + + + {{ graph_html|safe }} + + \ No newline at end of file diff --git a/interactive_graphics/graphics/tests.py b/interactive_graphics/graphics/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/interactive_graphics/graphics/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/interactive_graphics/graphics/urls.py b/interactive_graphics/graphics/urls.py new file mode 100644 index 0000000..436c1bc --- /dev/null +++ b/interactive_graphics/graphics/urls.py @@ -0,0 +1,8 @@ +# fmt: off + +from django.urls import path +from . import views + +urlpatterns = [ + path('interactive_graph/', views.interactive_graphic, name='interactive_graphic'), +] \ No newline at end of file diff --git a/interactive_graphics/graphics/views.py b/interactive_graphics/graphics/views.py new file mode 100644 index 0000000..faf244e --- /dev/null +++ b/interactive_graphics/graphics/views.py @@ -0,0 +1,15 @@ + +from django.shortcuts import render +import plotly.offline as opy +import plotly.graph_objs as go + + +def interactive_graphic(request): + x = list(range(-10, 11)) + y = [2 * val for val in x] + fig = go.Figure(data=go.Scatter(x=x, y=y, mode='lines+markers')) + fig.update_layout(title='Интерактивный график функции y = 2x', + xaxis_title='x', yaxis_title='y') + + graph_html = opy.plot(fig, auto_open=False, output_type='div') + return render(request, 'graphics/interactive_graphic.html', {'graph_html': graph_html}) diff --git a/interactive_graphics/interactive_graphics/__init__.py b/interactive_graphics/interactive_graphics/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/interactive_graphics/interactive_graphics/asgi.py b/interactive_graphics/interactive_graphics/asgi.py new file mode 100644 index 0000000..e1eb9f8 --- /dev/null +++ b/interactive_graphics/interactive_graphics/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for interactive_graphics project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'interactive_graphics.settings') + +application = get_asgi_application() diff --git a/interactive_graphics/interactive_graphics/settings.py b/interactive_graphics/interactive_graphics/settings.py new file mode 100644 index 0000000..d072a76 --- /dev/null +++ b/interactive_graphics/interactive_graphics/settings.py @@ -0,0 +1,124 @@ +""" +Django settings for interactive_graphics project. + +Generated by 'django-admin startproject' using Django 4.2.3. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.2/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-3siq-_p%th%ser_w$hduek9ep2h4&o^$@w%9i3#1$*ny-ay%l!' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'graphics', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'interactive_graphics.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'interactive_graphics.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/4.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/4.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.2/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/interactive_graphics/interactive_graphics/urls.py b/interactive_graphics/interactive_graphics/urls.py new file mode 100644 index 0000000..c56b4e0 --- /dev/null +++ b/interactive_graphics/interactive_graphics/urls.py @@ -0,0 +1,8 @@ +from django.contrib import admin +from django.urls import path, include + +urlpatterns = [ + path('admin/', admin.site.urls), + path('graphics/', include('graphics.urls')), + path('graphics/interactive_graph/', include('graphics.urls')), +] diff --git a/interactive_graphics/interactive_graphics/wsgi.py b/interactive_graphics/interactive_graphics/wsgi.py new file mode 100644 index 0000000..6d8d2ef --- /dev/null +++ b/interactive_graphics/interactive_graphics/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for interactive_graphics project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'interactive_graphics.settings') + +application = get_wsgi_application() diff --git a/interactive_graphics/manage.py b/interactive_graphics/manage.py new file mode 100644 index 0000000..bf31854 --- /dev/null +++ b/interactive_graphics/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'interactive_graphics.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() From 7d8a7d04ce036efe47edfea766cba5d27e843b6f Mon Sep 17 00:00:00 2001 From: German Kosach Date: Thu, 12 Oct 2023 19:30:42 +0300 Subject: [PATCH 5/6] X --- interactive_graphic/graphics/__init__.py | 0 interactive_graphic/graphics/admin.py | 3 - interactive_graphic/graphics/apps.py | 6 - .../graphics/migrations/__init__.py | 0 interactive_graphic/graphics/models.py | 3 - .../static/graphics/interactive_graphic.html | 12 -- .../graphics/interactive_graphic.html | 12 -- interactive_graphic/graphics/tests.py | 3 - interactive_graphic/graphics/urls.py | 9 -- interactive_graphic/graphics/views.py | 25 ---- .../interactive_graphic/__init__.py | 0 .../interactive_graphic/asgi.py | 16 --- .../interactive_graphic/settings.py | 124 ------------------ .../interactive_graphic/urls.py | 10 -- .../interactive_graphic/wsgi.py | 16 --- interactive_graphic/manage.py | 22 ---- 16 files changed, 261 deletions(-) delete mode 100644 interactive_graphic/graphics/__init__.py delete mode 100644 interactive_graphic/graphics/admin.py delete mode 100644 interactive_graphic/graphics/apps.py delete mode 100644 interactive_graphic/graphics/migrations/__init__.py delete mode 100644 interactive_graphic/graphics/models.py delete mode 100644 interactive_graphic/graphics/static/graphics/interactive_graphic.html delete mode 100644 interactive_graphic/graphics/templates/graphics/interactive_graphic.html delete mode 100644 interactive_graphic/graphics/tests.py delete mode 100644 interactive_graphic/graphics/urls.py delete mode 100644 interactive_graphic/graphics/views.py delete mode 100644 interactive_graphic/interactive_graphic/__init__.py delete mode 100644 interactive_graphic/interactive_graphic/asgi.py delete mode 100644 interactive_graphic/interactive_graphic/settings.py delete mode 100644 interactive_graphic/interactive_graphic/urls.py delete mode 100644 interactive_graphic/interactive_graphic/wsgi.py delete mode 100644 interactive_graphic/manage.py diff --git a/interactive_graphic/graphics/__init__.py b/interactive_graphic/graphics/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/interactive_graphic/graphics/admin.py b/interactive_graphic/graphics/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/interactive_graphic/graphics/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/interactive_graphic/graphics/apps.py b/interactive_graphic/graphics/apps.py deleted file mode 100644 index 20cbe35..0000000 --- a/interactive_graphic/graphics/apps.py +++ /dev/null @@ -1,6 +0,0 @@ -from django.apps import AppConfig - - -class GraphicsConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'graphics' diff --git a/interactive_graphic/graphics/migrations/__init__.py b/interactive_graphic/graphics/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/interactive_graphic/graphics/models.py b/interactive_graphic/graphics/models.py deleted file mode 100644 index 71a8362..0000000 --- a/interactive_graphic/graphics/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/interactive_graphic/graphics/static/graphics/interactive_graphic.html b/interactive_graphic/graphics/static/graphics/interactive_graphic.html deleted file mode 100644 index f65de3f..0000000 --- a/interactive_graphic/graphics/static/graphics/interactive_graphic.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - Interactive Graph - - - {{ graph_html|safe }} - - \ No newline at end of file diff --git a/interactive_graphic/graphics/templates/graphics/interactive_graphic.html b/interactive_graphic/graphics/templates/graphics/interactive_graphic.html deleted file mode 100644 index f65de3f..0000000 --- a/interactive_graphic/graphics/templates/graphics/interactive_graphic.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - Interactive Graph - - - {{ graph_html|safe }} - - \ No newline at end of file diff --git a/interactive_graphic/graphics/tests.py b/interactive_graphic/graphics/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/interactive_graphic/graphics/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/interactive_graphic/graphics/urls.py b/interactive_graphic/graphics/urls.py deleted file mode 100644 index d48cbf6..0000000 --- a/interactive_graphic/graphics/urls.py +++ /dev/null @@ -1,9 +0,0 @@ -# fmt: off - -from django.urls import path -from . import views - -urlpatterns = [ - path('interactive_graph/', views.interactive_graphic, name='interactive_graphic'), - # Other patterns for your app -] diff --git a/interactive_graphic/graphics/views.py b/interactive_graphic/graphics/views.py deleted file mode 100644 index 75d5818..0000000 --- a/interactive_graphic/graphics/views.py +++ /dev/null @@ -1,25 +0,0 @@ -# views.py - -from django.shortcuts import render -import plotly.offline as opy -import plotly.graph_objs as go - - -def interactive_graphic(request): - # Данные для оси x (значения от -10 до 10 с шагом 1) - x = list(range(-10, 11)) - - # Данные для оси y (значения функции y = 2x) - y = [2 * val for val in x] - - # Создание интерактивного линейного графика - fig = go.Figure(data=go.Scatter(x=x, y=y, mode='lines+markers')) - - # Добавление подписей осей и заголовка - fig.update_layout(title='Интерактивный график функции y = 2x', - xaxis_title='x', yaxis_title='y') - - # Save the Plotly graph as a standalone HTML file - graph_html = opy.plot(fig, auto_open=False, output_type='div') - - return render(request, 'graphics/interactive_graphic.html', {'graph_html': graph_html}) diff --git a/interactive_graphic/interactive_graphic/__init__.py b/interactive_graphic/interactive_graphic/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/interactive_graphic/interactive_graphic/asgi.py b/interactive_graphic/interactive_graphic/asgi.py deleted file mode 100644 index 27ac15d..0000000 --- a/interactive_graphic/interactive_graphic/asgi.py +++ /dev/null @@ -1,16 +0,0 @@ -""" -ASGI config for interactive_graphic project. - -It exposes the ASGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ -""" - -import os - -from django.core.asgi import get_asgi_application - -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'interactive_graphic.settings') - -application = get_asgi_application() diff --git a/interactive_graphic/interactive_graphic/settings.py b/interactive_graphic/interactive_graphic/settings.py deleted file mode 100644 index 090cb07..0000000 --- a/interactive_graphic/interactive_graphic/settings.py +++ /dev/null @@ -1,124 +0,0 @@ -""" -Django settings for interactive_graphic project. - -Generated by 'django-admin startproject' using Django 4.2.3. - -For more information on this file, see -https://docs.djangoproject.com/en/4.2/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/4.2/ref/settings/ -""" - -from pathlib import Path - -# Build paths inside the project like this: BASE_DIR / 'subdir'. -BASE_DIR = Path(__file__).resolve().parent.parent - - -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'django-insecure-yx74ef%lg-kyl1x^5wn9$1+mt81tpn8%%%i7^$0gj-rtw31e5o' - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -ALLOWED_HOSTS = [] - - -# Application definition - -INSTALLED_APPS = [ - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'graphics', -] - -MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', -] - -ROOT_URLCONF = 'interactive_graphic.urls' - -TEMPLATES = [ - { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], - 'APP_DIRS': True, - 'OPTIONS': { - 'context_processors': [ - 'django.template.context_processors.debug', - 'django.template.context_processors.request', - 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', - ], - }, - }, -] - -WSGI_APPLICATION = 'interactive_graphic.wsgi.application' - - -# Database -# https://docs.djangoproject.com/en/4.2/ref/settings/#databases - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', - } -} - - -# Password validation -# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators - -AUTH_PASSWORD_VALIDATORS = [ - { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', - }, -] - - -# Internationalization -# https://docs.djangoproject.com/en/4.2/topics/i18n/ - -LANGUAGE_CODE = 'en-us' - -TIME_ZONE = 'UTC' - -USE_I18N = True - -USE_TZ = True - - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/4.2/howto/static-files/ - -STATIC_URL = 'static/' - -# Default primary key field type -# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field - -DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/interactive_graphic/interactive_graphic/urls.py b/interactive_graphic/interactive_graphic/urls.py deleted file mode 100644 index d6449e6..0000000 --- a/interactive_graphic/interactive_graphic/urls.py +++ /dev/null @@ -1,10 +0,0 @@ -from django.contrib import admin -from django.urls import path, include - -urlpatterns = [ - path('admin/', admin.site.urls), - # Include the URLs from the graphics app - path('graphics/', include('graphics.urls')), - # Add a direct route to the interactive_graphic view - path('graphics/interactive_graph/', include('graphics.urls')), -] diff --git a/interactive_graphic/interactive_graphic/wsgi.py b/interactive_graphic/interactive_graphic/wsgi.py deleted file mode 100644 index bb9ab64..0000000 --- a/interactive_graphic/interactive_graphic/wsgi.py +++ /dev/null @@ -1,16 +0,0 @@ -""" -WSGI config for interactive_graphic project. - -It exposes the WSGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/ -""" - -import os - -from django.core.wsgi import get_wsgi_application - -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'interactive_graphic.settings') - -application = get_wsgi_application() diff --git a/interactive_graphic/manage.py b/interactive_graphic/manage.py deleted file mode 100644 index ccde54e..0000000 --- a/interactive_graphic/manage.py +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env python -"""Django's command-line utility for administrative tasks.""" -import os -import sys - - -def main(): - """Run administrative tasks.""" - os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'interactive_graphic.settings') - try: - from django.core.management import execute_from_command_line - except ImportError as exc: - raise ImportError( - "Couldn't import Django. Are you sure it's installed and " - "available on your PYTHONPATH environment variable? Did you " - "forget to activate a virtual environment?" - ) from exc - execute_from_command_line(sys.argv) - - -if __name__ == '__main__': - main() From 8248245f20decca95bd5a16d9e3760da515692d9 Mon Sep 17 00:00:00 2001 From: lssmglv Date: Thu, 7 Mar 2024 21:55:14 +0300 Subject: [PATCH 6/6] change x range --- interactive_graphics/graphics/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interactive_graphics/graphics/views.py b/interactive_graphics/graphics/views.py index faf244e..7eb6d48 100644 --- a/interactive_graphics/graphics/views.py +++ b/interactive_graphics/graphics/views.py @@ -5,7 +5,7 @@ def interactive_graphic(request): - x = list(range(-10, 11)) + x = list(range(-10, 15)) y = [2 * val for val in x] fig = go.Figure(data=go.Scatter(x=x, y=y, mode='lines+markers')) fig.update_layout(title='Интерактивный график функции y = 2x',