Skip to content

Commit

Permalink
Merge pull request #79 from Azazel-h/develop
Browse files Browse the repository at this point in the history
v0.2
  • Loading branch information
Azazel-h authored Dec 20, 2023
2 parents a610ff1 + 683126c commit cca1df4
Show file tree
Hide file tree
Showing 17 changed files with 203 additions and 121 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ RUN apt-get update && apt-get -y install gettext-base libsasl2-dev python3-dev l

WORKDIR /app
COPY . /app

RUN python3 -m pip install -r /app/requirements.txt
1 change: 1 addition & 0 deletions accounts/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def init_ldap_server(self) -> None:

try:
self.connection = ldap.initialize(self.server_uri)
self.connection.set_option(ldap.OPT_NETWORK_TIMEOUT, 3)
self.connection.simple_bind_s(self.bind_dn, self.bind_password)
except (ldap.LDAPError, ldap.SERVER_DOWN) as error:
self.connection = None
Expand Down
5 changes: 2 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ services:
environment:
- DJANGO_PORT
command: >
sh -c "python3 -m pip install -r /app/requirements.txt &&
python3 /app/manage.py makemigrations accounts fabry_perot michelson &&
sh -c "python3 /app/manage.py makemigrations accounts fabry_perot michelson &&
python3 /app/manage.py migrate &&
python3 /app/manage.py collectstatic --no-input &&
python3 /app/manage.py runserver --noreload 0.0.0.0:${DJANGO_PORT}"
gunicorn -b :${DJANGO_PORT} interferometers.wsgi"
profiles:
- prod
depends_on:
Expand Down
10 changes: 10 additions & 0 deletions fabry_perot/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@
class VisualizationConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'fabry_perot'
column_names = (
"Длина волны",
"Разница длин волн",
"Расстояние между зеркалами",
"Фокусное расстояние линзы",
"Коэффициент отражения",
"Показатель преломления",
"Размер рисунка",
"Разрешение",
)
19 changes: 12 additions & 7 deletions fabry_perot/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,34 @@

class GraphForm(forms.Form):
wave_length = forms.FloatField(
label='Длина волны [нм]',
label='Длина волны \\(\\lambda\\) [нм]',
min_value=380,
max_value=780,
step_size=0.1,
initial=630,
widget=RangeInput(min_value=380, max_value=780, step=0.1)
)
wave_length_diff = forms.FloatField(
label='Разница длин волн \\(\\Delta\\lambda\\) [нм]',
min_value=0,
step_size=0.000001,
initial=0
)
glasses_distance = forms.FloatField(
label='Расстояние между зеркалами [мм]',
label='Расстояние между зеркалами \\(d\\) [мм]',
min_value=0,
step_size=0.001,
initial=15,
)
focal_distance = forms.FloatField(label='Фокусное расстояние линзы [мм]', min_value=0, step_size=0.001, initial=100)
stroke_difference = forms.FloatField(label='Разница хода [нм]', min_value=0, step_size=0.001, initial=0)
reflectivity = forms.FloatField(
label='Коэффициент отражения',
focal_distance = forms.FloatField(label='Фокусное расстояние линзы \\(f\\) [мм]', min_value=0, step_size=0.001, initial=100)
reflection_coefficient = forms.FloatField(
label='Коэффициент отражения \\(R\\)',
min_value=0.000001,
max_value=0.999999,
step_size=0.000001,
initial=0.7,
widget=RangeInput(min_value=0.000001, max_value=0.999999, step=0.000001)
)
refractive_index = forms.FloatField(label='Коэффициент преломления', min_value=1, step_size=0.000001, initial=1)
refractive_index = forms.FloatField(label='Показатель преломления \\(n\\)', min_value=1, step_size=0.000001, initial=1)
picture_size = forms.FloatField(label='Размер рисунка [мм]', min_value=0, step_size=0.001, initial=5)
N = forms.IntegerField(label='Разрешение на экране в пикселях', min_value=1, max_value=1000, initial=500)
8 changes: 4 additions & 4 deletions fabry_perot/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
class RequestFP(models.Model):
user = models.CharField(max_length=50)
wave_length = models.FloatField(default=0)
wave_length_diff = models.FloatField(default=0)
glasses_distance = models.FloatField(default=0)
focal_distance = models.FloatField(default=0)
stroke_difference = models.FloatField(default=0)
reflectivity = models.FloatField(default=0)
reflection_coefficient = models.FloatField(default=0)
refractive_index = models.FloatField(default=0)
picture_size = models.FloatField(default=0)
N = models.IntegerField()
Expand All @@ -17,10 +17,10 @@ class RequestFP(models.Model):
class PresetFP(models.Model):
user = models.CharField(max_length=50)
wave_length = models.FloatField(default=0)
wave_length_diff = models.FloatField(default=0)
glasses_distance = models.FloatField(default=0)
focal_distance = models.FloatField(default=0)
stroke_difference = models.FloatField(default=0)
reflectivity = models.FloatField(default=0)
reflection_coefficient = models.FloatField(default=0)
refractive_index = models.FloatField(default=0)
picture_size = models.FloatField(default=0)
N = models.IntegerField()
84 changes: 45 additions & 39 deletions fabry_perot/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,63 @@

class TestPage(TestCase):
def assert_updates_graph(self, data, code, content=None):
url = reverse('index') + 'graph/'
response = self.client.post(url, data)
url = reverse('fp-index') + 'graph/'
response = self.client.post(url, data, 'application/json')
self.assertEqual(response.status_code, code)

if content:
self.assertEqual(response.content, content)

def assert_saves_preset(self, data, code, content=None):
data["preset_operation"] = "save_preset"
url = reverse('index') + 'preset/'
data['preset_operation'] = 'save_preset'
url = reverse('fp-index') + 'preset/'
response = self.client.post(url, data)
self.assertEqual(response.status_code, code)

if content:
self.assertContains(response, content)

def assert_deletes_preset(self, preset_id, code, content=None):
data = {
"delete_preset": preset_id,
"preset_operation": "delete_preset"
'delete_preset': preset_id,
'preset_operation': 'delete_preset'
}
url = reverse('index') + 'preset/'
url = reverse('fp-index') + 'preset/'
response = self.client.post(url, data)
self.assertEqual(response.status_code, code)

if content:
self.assertContains(response, content)

def assert_update_history(self, data, code, content=None):
url = reverse('index') + 'history/'
url = reverse('fp-index') + 'history/'
response = self.client.post(url, data)
self.assertEqual(response.status_code, code)

if content:
self.assertContains(response, content)

def get_data(self, **kwargs):
data = self.basic_data.copy()
data.update(kwargs)

return data

def setUp(self):
self.basic_data = {
"wave_length": "630",
"glasses_distance": "15",
"focal_distance": "100",
"stroke_difference": "0",
"reflectivity": "0.7",
"refractive_index": "1",
"picture_size": "5",
"N": "500"
'wave_length': '630',
'wave_length_diff': '0',
'glasses_distance': '15',
'focal_distance': '100',
'reflection_coefficient': '0.7',
'refractive_index': '1',
'picture_size': '5',
'N': '500'
}
self.client = Client()

def test_index_page(self):
url = reverse('index')
url = reverse('fp-index')
response = self.client.get(url)
self.assertEqual(response.status_code, 200)

Expand All @@ -65,42 +70,43 @@ def test_interferometer_generation(self):

def test_interferometer_generation_with_wrong_wavelength(self):
request_data = self.get_data(wave_length=1000)
self.assert_updates_graph(request_data, 200, b'None')
self.assert_updates_graph(request_data, 200, None)

request_data = self.get_data(wave_length=0)
self.assert_updates_graph(request_data, 200, b'None')
self.assert_updates_graph(request_data, 200, None)

def test_interferometer_generation_with_wrong_wave_length_diff(self):
request_data = self.get_data(wave_length_diff=-1)
self.assert_updates_graph(request_data, 200, None)

def test_interferometer_generation_with_wrong_glasses_distance(self):
request_data = self.get_data(glasses_distance=-1)
self.assert_updates_graph(request_data, 200, b'None')
self.assert_updates_graph(request_data, 200, None)

def test_interferometer_generation_with_wrong_focal_distance(self):
request_data = self.get_data(focal_distance=-1)
self.assert_updates_graph(request_data, 200, b'None')
self.assert_updates_graph(request_data, 200, None)

def test_interferometer_generation_with_wrong_reflectivity(self):
request_data = self.get_data(reflection_coefficient=-1)
self.assert_updates_graph(request_data, 200, None)

def test_interferometer_generation_with_wrong_stroke_difference(self):
request_data = self.get_data(stroke_difference=-1)
self.assert_updates_graph(request_data, 200, b'None')
request_data = self.get_data(reflection_coefficient=1.5)
self.assert_updates_graph(request_data, 200, None)

def test_interferometer_generation_with_wrong_refractive_index(self):
request_data = self.get_data(refractive_index=-1)
self.assert_updates_graph(request_data, 200, None)

def test_interferometer_generation_with_wrong_picture_size(self):
request_data = self.get_data(picture_size=-1)
self.assert_updates_graph(request_data, 200, b'None')
self.assert_updates_graph(request_data, 200, None)

def test_interferometer_generation_with_wrong_n(self):
# N less than 0
request_data = self.get_data(N=-1)
self.assert_updates_graph(request_data, 200, b'None')
self.assert_updates_graph(request_data, 200, None)

# N more than 4000
# N more than 1000
request_data = self.get_data(N=1001)
self.assert_updates_graph(request_data, 200, b'None')

def test_interferometer_generation_with_wrong_reflectivity(self):
request_data = self.get_data(reflectivity=-1)
self.assert_updates_graph(request_data, 200, b'None')

request_data = self.get_data(reflectivity=1.5)
self.assert_updates_graph(request_data, 200, b'None')

def test_interferometer_generation_with_wrong_refractive_index(self):
request_data = self.get_data(refractive_index=-1)
self.assert_updates_graph(request_data, 200, b'None')
self.assert_updates_graph(request_data, 200, None)
2 changes: 1 addition & 1 deletion fabry_perot/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from . import views

urlpatterns = [
path('', views.IndexPage.as_view(), name='index'),
path('', views.IndexPage.as_view(), name='fp-index'),
path('graph/', views.Graph.as_view()),
path('history/', views.HistoryTable.as_view()),
path('preset/', views.PresetsTable.as_view())
Expand Down
Loading

0 comments on commit cca1df4

Please sign in to comment.