Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c4e102e
added basic construct of settings page
ronjakrg Nov 24, 2024
8d76417
added selection of sections and forms for plot settings
ronjakrg Nov 25, 2024
c1fd7d9
moved settings file to own folder, added navigation to sidebar and sm…
ronjakrg Nov 28, 2024
d8653e0
merged dev into this branch
ronjakrg Dec 2, 2024
701b0a7
Added footer and returning to last view after saving or canceling
ronjakrg Dec 10, 2024
7e4aedc
small bugfix and refactoring
ronjakrg Dec 10, 2024
49bb332
Fixed alignment
ronjakrg Dec 19, 2024
33fc8ac
enabled saving and loading settings, split settings into sections and…
ronjakrg Jan 3, 2025
9c4dd4d
connected and enhanced plotly template, added small ui changes
ronjakrg Jan 3, 2025
813bcd1
minor changes
ronjakrg Jan 3, 2025
fc14808
moved plot_template to settings folder
ronjakrg Jan 6, 2025
c3f87f7
restructured plot settings html, enabled choosing a custom font
ronjakrg Jan 7, 2025
b52c7cd
included file format from settings in plot download
ronjakrg Jan 7, 2025
85e0129
added plot height and width into plot template
ronjakrg Jan 8, 2025
8acc7d7
added plot settings preview
ronjakrg Jan 16, 2025
c962278
moved js code from <script> into own js file
ronjakrg Jan 16, 2025
c49b60a
moved plot preview in column, some formatting
ronjakrg Jan 21, 2025
06cade2
adjusted spacing, added convertion from mm to px
ronjakrg Jan 21, 2025
451ce4e
fixed behaviour of unsaved changes modal
ronjakrg Jan 24, 2025
893a935
added default yamls as fallback templates
ronjakrg Jan 27, 2025
7697fe1
removed plot.yaml
ronjakrg Jan 27, 2025
a42961f
adjusted gitignore for ignoring individual settings
ronjakrg Jan 27, 2025
0ffe07b
small bugfix
ronjakrg Jan 28, 2025
1fd2d8c
added check if list of exported plots is empty
ronjakrg Feb 1, 2025
6f0aeaa
enhanced plot download by including scaling to experienced size, adde…
ronjakrg Feb 1, 2025
da9e056
fixed broken tiff & eps download with plotly figures
ronjakrg Feb 1, 2025
33ccabe
removed general section, added temporary databases section
ronjakrg Feb 1, 2025
7ffbf4c
added font scaling to displayed plots
ronjakrg Feb 1, 2025
27d4c46
added requested changes
ronjakrg Feb 9, 2025
b4c837a
added tests
ronjakrg Feb 9, 2025
42aac62
attempt to fix tests that were successful locally
ronjakrg Feb 9, 2025
f905a24
removed unused imports
ronjakrg Feb 9, 2025
cc450ca
added requested changes
ronjakrg Feb 11, 2025
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
3 changes: 2 additions & 1 deletion protzilla/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import pandas as pd
import plotly.io as pio
import plotly.graph_objects as go
from PIL import Image, features
from PIL import Image

from protzilla.utilities import format_trace

Expand Down Expand Up @@ -281,6 +281,7 @@ def empty(self) -> bool:
def export(self, settings: dict) -> list:
"""
Converts all plots from this step to files according to the format and size in the Plotly template.
An exported plot is represented as BytesIO object containing binary image data.
:param settings: Dict containing the plot settings.
:return: List of all exported plots.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vielleicht noch hinzufügen was genau ein exportierter Plot ist, also ob es die raw files sind oder metadaten als Plot objekt oder so?

"""
Expand Down
13 changes: 12 additions & 1 deletion protzilla/utilities/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import pandas as pd
import psutil

from django.http import QueryDict

# recipie from https://docs.python.org/3/library/itertools.html
def unique_justseen(iterable, key=None):
Expand Down Expand Up @@ -138,7 +139,12 @@ def get_file_name_from_upload_path(upload_path: str) -> str:
return f"{base_name}.{file_extension}"


def parameters_from_post(post):
def parameters_from_post(post: QueryDict) -> dict:
"""
Removes token from dict and converts the remaining entries into suitable data formats.
:param post: Django dict containing POST data.
:return: Dict containing the parameters in suitable formats.
"""
d = dict(post)
if "csrfmiddlewaretoken" in d:
del d["csrfmiddlewaretoken"]
Expand All @@ -153,6 +159,11 @@ def parameters_from_post(post):


def convert_str_if_possible(s):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hier gerne auch doc-string und return type :)

Copy link
Collaborator Author

@ronjakrg ronjakrg Feb 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for parameters_from_post, aber ergänze ich gern! :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Danke, dass du es trotzdem ergänzt hast ^^

"""
Converts an input value into suitable representation as a string.
:param s: Input value.
:return: Converted input value.
"""
try:
f = float(s)
return int(f) if int(f) == f else f
Expand Down
41 changes: 41 additions & 0 deletions tests/ui/test_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import pytest
import plotly.graph_objects as go

from protzilla.constants.colors import PLOT_PRIMARY_COLOR, PLOT_SECONDARY_COLOR
from protzilla.constants.paths import SETTINGS_PATH
from ui.settings.plot_template import (
determine_font,
resize_for_display,
get_scale_factor
)


@pytest.fixture
def sample_params():
return {
"section_id": "plots",
"file_format": "png",
"width": 85,
"height": 60,
"custom_font": "Ubuntu Mono",
"font": "Arial",
"heading_size": 11,
"text_size": 8
}

def test_determine_font(sample_params):
assert determine_font(sample_params) == "Arial"
sample_params["font"] = "Custom"
assert determine_font(sample_params) == "Ubuntu Mono"

def test_resize_for_display(sample_params):
result = resize_for_display(sample_params)
assert result["display_width"] == 600 # SCALED_WIDTH
assert result["display_heading_size"] == 26

def test_get_scale_factor(sample_params):
fig = go.Figure()
fig.update_layout(width=600)
scale = get_scale_factor(fig, sample_params)
assert isinstance(scale, float)
assert round(scale, 3) == 1.735
4 changes: 3 additions & 1 deletion ui/settings/plot_template.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sehr schön geschriebener Code finde ich!!

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from protzilla.constants.colors import PLOT_PRIMARY_COLOR, PLOT_SECONDARY_COLOR
from protzilla.constants.paths import SETTINGS_PATH


SCALED_WIDTH = 600
template = None

def load_settings(section_id: str) -> dict:
"""
Expand All @@ -33,7 +35,7 @@ def save_settings(params: dict, section_id: str):
op = YamlOperator()
path = SETTINGS_PATH / (section_id + ".yaml")
op.write(path, params)
if section_id == "plots" and template:
if section_id == "plots" and isinstance(template, PlotTemplate):
template.update(params)
template.apply()

Expand Down
5 changes: 4 additions & 1 deletion ui/settings/templates/settings_databases.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ <h3>Manage Databases</h3>
<form method="post" id="settings-form">
{% csrf_token %}
<input type="hidden" name="section_id" value="{{ section_id }}">
<!-- TO DO: Move database content to this page -->

<!-- PLEASE NOTE: This HTML is a placeholder. TO DO: Move "Manage databases" content to this page. -->
<p><b>Please note: This page is an placeholder for displaying the database management in the future.</b></p>

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh fair... Habe ich übersehen haha

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alles fine, finde es so nochmal deutlich einleuchtender! (:

<div class="mb-2" id="settings-form">
<h5>Datebases</h5>
<div class="field-wrapper">
Expand Down
8 changes: 4 additions & 4 deletions user_data/settings/plots_default.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
custom_font: ''
file_format: png
font: Arial
heading_size: 22
height: 40
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bei mir sah es jetzt trotzdem wieder so aus wie im letzten Screenshot, kommt aber vermutlich daher, dass ich es das letzte mal doch gespeichert habe und dann die default werte ja "überschrieben" werden in plots.yaml. Man könnte überlegen, ob sich ein "reset to default" Button lohnt, der einfach wieder plots.yaml mit plots_default.yaml überschreibt für solche Fälle bzw. falls man mal falsch konfiguriert und sich nicht mehr erinnern kann was sinnvoll aussah? Wäre nur ein grober Vorschlag, weiß nicht, ob es unbedingt umgesetzt werden muss :)))

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ein "Should have" war ja die Selection von mehreren gespeicherten Plotly-Templates, zum Beispiel je Publikation (mit verschiedenen Guidelines) an der man arbeitet. Und da fänd ich es super sinnvoll, wie du es sagst, eine default Option zum Auswählen zu haben! Würde ich dann nach unserer Migration aufnehmen wollen. :)

heading_size: 11
height: 60
section_id: plots
text_size: 16
width: 60
text_size: 8
width: 85
Loading