Skip to content
Snippets Groups Projects
Commit 380b3850 authored by tolgayurt's avatar tolgayurt
Browse files

initialisierung des Projektes

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 548 additions and 0 deletions
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6 virtualenv at C:\Users\tolga yurtseven\PycharmProjects\mysite\venv" project-jdk-type="Python SDK" />
<component name="PyCharmProfessionalAdvertiser">
<option name="shown" value="true" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/mysite.iml" filepath="$PROJECT_DIR$/.idea/mysite.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.6 virtualenv at C:\Users\tolga yurtseven\PycharmProjects\mysite\venv" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
File added
#!/usr/bin/env python
import os
import sys
if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.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)
"""
Django settings for mysite project.
Generated by 'django-admin startproject' using Django 2.1.2.
For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""
import os
import sys
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'um7ld8n$bvygoj-_))z9+yv@*)*ivk=o)!=sl^rkwbmny+7j4h'
# 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',
'plots',
'numpy',
'shapely',
'path',
'mplcursors',
'mpld3'
]
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 = 'mysite.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 = 'mysite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/2.1/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/2.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/
STATIC_URL = '/static/'
DATA_UPLOAD_MAX_NUMBER_FIELDS = 10000
\ No newline at end of file
"""mysite URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('', include('plots.urls')),
path('admin/', admin.site.urls),
]
"""
WSGI config for mysite 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/2.1/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
application = get_wsgi_application()
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class PlotsConfig(AppConfig):
name = 'plots'
# AVl Quelle:https://www.programiz.com/dsa/avl-tree
# AVL tree implementation in Python
import sys
# Create a tree node
class TreeNode(object):
def __init__(self, key, vertice, vertice_neighbour):
self.key = key
self.vertice = vertice
self.vertice_neighbour = vertice_neighbour
self.left = None
self.right = None
self.height = 1
class AVLTree(object):
def find_edges(self, root, key, vertice_top):
if not root:
return vertice_top
elif key < root.key:
vertice_top = root
return self.find_edges(root.left, key, vertice_top)
elif key == root.key:
return root
else:
if vertice_top.key < key: # falls wir irgendwann im Buam nach links gegangen sind ist dieser Node der Nachfolger, ansonsten gibt es kein Nachfolger und die Ecke berührt den Container rand
vertice_top = TreeNode(key, (0, key), (0, 0))
return self.find_edges(root.right, key, vertice_top)
# return ("test",vertice_top)
# Function to insert a node
def insert_node(self, root, key, vertice, vertice_neighbour):
# Find the correct location and insert the node
if not root:
return TreeNode(key, vertice, vertice_neighbour)
elif key < root.key:
root.left = self.insert_node(root.left, key, vertice, vertice_neighbour)
else:
root.right = self.insert_node(root.right, key, vertice, vertice_neighbour)
root.height = 1 + max(self.getHeight(root.left),
self.getHeight(root.right))
# Update the balance factor and balance the tree
balanceFactor = self.getBalance(root)
if balanceFactor > 1:
if key < root.left.key:
return self.rightRotate(root)
else:
root.left = self.leftRotate(root.left)
return self.rightRotate(root)
if balanceFactor < -1:
if key > root.right.key:
return self.leftRotate(root)
else:
root.right = self.rightRotate(root.right)
return self.leftRotate(root)
return root
# Function to delete a node
def delete_node(self, root, key):
# Find the node to be deleted and remove it
if not root:
return root
elif key < root.key:
root.left = self.delete_node(root.left, key)
elif key > root.key:
root.right = self.delete_node(root.right, key)
else:
if root.left is None:
temp = root.right
root = None
return temp
elif root.right is None:
temp = root.left
root = None
return temp
temp = self.getMinValueNode(root.right)
root.key = temp.key
root.vertice = temp.vertice
root.vertice_neighbour = temp.vertice_neighbour
root.right = self.delete_node(root.right,
temp.key)
if root is None:
return root
# Update the balance factor of nodes
root.height = 1 + max(self.getHeight(root.left),
self.getHeight(root.right))
balanceFactor = self.getBalance(root)
# Balance the tree
if balanceFactor > 1:
if self.getBalance(root.left) >= 0:
return self.rightRotate(root)
else:
root.left = self.leftRotate(root.left)
return self.rightRotate(root)
if balanceFactor < -1:
if self.getBalance(root.right) <= 0:
return self.leftRotate(root)
else:
root.right = self.rightRotate(root.right)
return self.leftRotate(root)
return root
# Function to perform left rotation
def leftRotate(self, z):
y = z.right
T2 = y.left
y.left = z
z.right = T2
z.height = 1 + max(self.getHeight(z.left),
self.getHeight(z.right))
y.height = 1 + max(self.getHeight(y.left),
self.getHeight(y.right))
return y
# Function to perform right rotation
def rightRotate(self, z):
y = z.left
T3 = y.right
y.right = z
z.left = T3
z.height = 1 + max(self.getHeight(z.left),
self.getHeight(z.right))
y.height = 1 + max(self.getHeight(y.left),
self.getHeight(y.right))
return y
# Get the height of the node
def getHeight(self, root):
if not root:
return 0
return root.height
# Get balance factore of the node
def getBalance(self, root):
if not root:
return 0
return self.getHeight(root.left) - self.getHeight(root.right)
def getMinValueNode(self, root):
if root is None or root.left is None:
return root
return self.getMinValueNode(root.left)
def preOrder(self, root):
if not root:
return
print("{0} ".format(root.key), end="")
self.preOrder(root.left)
self.preOrder(root.right)
def preOrder_array(self, root, array, key):
if not root:
return
# print("{0} ".format(root.key), end="")
if root.key <= key:
array.append((root.vertice))
self.preOrder_array(root.left, array, key)
self.preOrder_array(root.right, array, key)
return array
# Print the tree
def printHelper(self, currPtr, indent, last):
if currPtr != None:
sys.stdout.write(indent)
if last:
sys.stdout.write("R----")
indent += " "
else:
sys.stdout.write("L----")
indent += "| "
print(currPtr.key)
self.printHelper(currPtr.left, indent, False)
self.printHelper(currPtr.right, indent, True)
\ No newline at end of file
from django.db import models
# Create your models here.
import math
from django.shortcuts import render
from plotly.offline import plot
import plots.polygon as poly
from django.http import JsonResponse
from plotly.graph_objs import Scatter
import plotly.graph_objects as go
from django.http import HttpResponse
import pdb; pdb.set_trace
from plotly.subplots import make_subplots
import math
def polygon_plot(polygons):
plot_polygon_list = []
polygon_count = len(polygons)
cols = 4
rows = math.ceil(polygon_count / cols)
number = 0
sub_plot_titles = ['{} height:{} slope:{}'.format(number,
(int(polygons[number].height * 10)) / 10,
(int(polygons[number].slope * 10)) / 10)
for number in range(0, polygon_count)]
fig = make_subplots(rows=rows, cols=cols, subplot_titles=sub_plot_titles)
fig.update_layout(title="Convex Polygons")
counter = 0
for polygon in polygons:
x_data = polygon.x_values
y_data = polygon.y_values
scatter = go.Scatter(x=x_data, y=y_data,
mode='lines', name='{}'.format(counter),
opacity=0.8, marker_color='green')
spine_x_values = [x[0] for x in polygon.spine]
spine_y_values = [x[1] for x in polygon.spine]
scatter_spine = go.Scatter(x=spine_x_values, y=spine_y_values,
mode='lines', name='{} Spine'.format(counter),
opacity=0.8, marker_color='red')
row = math.ceil((counter + 1) / cols)
col = (counter % cols) + 1
fig.add_trace(scatter, row=row, col=col)
fig.add_trace(scatter_spine, row=row, col=col)
counter += 1
plot_polygons_div = plot(fig, output_type='div')
return plot_polygons_div
def high_class_plot(high_classes):
plot_high_class_list = []
polygon_number = 0
polygon_title_number = 0
for hc in high_classes:
polygon_count = len(hc.polygons)
cols = 4
rows = math.ceil(polygon_count / cols)
# sub_plot_titles = ['{} height:{} slope:{}'.format(number,
# (int(hc.spine_ordered_polygons[number].height * 10)) / 10,
# (int(hc.spine_ordered_polygons[number].slope * 10)) / 10)
# for number in range(0, polygon_count)]
sub_plot_titles=[]
for polygon in hc.spine_ordered_polygons:
sub_plot_titles.append('{} height:{} slope:{}'.format(polygon_title_number, (int(polygon.height*10))/10,(int(polygon.slope * 10)) / 10))
polygon_title_number += 1
fig = make_subplots(rows=rows, cols=cols, subplot_titles=sub_plot_titles)
fig.update_layout(title="Highclass {} heights: {}-{}".format(hc.i, int(hc.min_border), int(hc.max_border)))
counter = 0
for polygon in hc.spine_ordered_polygons:
x_data = polygon.x_values
y_data = polygon.y_values
scatter = go.Scatter(x=x_data, y=y_data,
mode='lines', name='{}'.format(polygon_number),
opacity=0.8, marker_color='green')
spine_x_values = [x[0] for x in polygon.spine]
spine_y_values = [x[1] for x in polygon.spine]
scatter_spine = go.Scatter(x=spine_x_values, y=spine_y_values,
mode='lines', name='{} Spine'.format(polygon_number),
opacity=0.8, marker_color='red')
row = math.ceil((counter + 1) / cols)
col = (counter % cols) + 1
fig.add_trace(scatter, row=row, col=col)
fig.add_trace(scatter_spine, row=row, col=col)
counter += 1
polygon_number += 1
plt_div = plot(fig, output_type='div')
plot_high_class_list.append(plt_div)
return plot_high_class_list
This diff is collapsed.
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
{%for container_plots in containers %}
<h1>Container</h1>
{%for plot in container_plots%}
{{plot|safe}}
{%endfor%}
<hr>
{%endfor%}
</body>
</html>
\ No newline at end of file
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>test</title>
</head>
<body>
{% autoescape off %}
<h1>Convex Polygons</h1>
{{ polygons_plot }}
<h1>Highclasses</h1>
{% for high_class in high_classes %}
{{ high_class }}
<hr>
{% endfor %}
{% endautoescape %}
</body>
</html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment