Skip to content

Commit

Permalink
update configuration, djangoq workrer
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-dvorak committed Apr 11, 2024
1 parent 3de5cd3 commit f4e3b7a
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 13 deletions.
4 changes: 4 additions & 0 deletions DOSPORTAL/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
from django_q import models as q_models
from django_q import admin as q_admin

admin.site.site_header = 'DOSPORTAL admin page'
admin.site.site_title = 'DOSPORTAL admin page'
admin.site.index_title = 'DOSPORTAL administration'

class AirportsResource(resources.ModelResource):
class Meta:
model = Airports
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.11 on 2024-04-11 23:15

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('DOSPORTAL', '0033_record_time_of_interest_end_and_more'),
]

operations = [
migrations.AlterField(
model_name='detector',
name='data',
field=models.JSONField(blank=True, default=dict, help_text='Detector metadata, used for advanced data processing and maintaining', verbose_name='Detector metadata'),
),
migrations.AlterField(
model_name='record',
name='metadata',
field=models.JSONField(blank=True, default=dict, help_text='record metadata, used for advanced data processing and maintaining', verbose_name='record_metadata'),
),
]
14 changes: 8 additions & 6 deletions DOSPORTAL/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
'guardian',
'prettyjson',
# 'organizations',
'rest_framework'
]

MARKDOWNX_MARKDOWN_EXTENSIONS = [
Expand Down Expand Up @@ -217,15 +218,16 @@

Q_CLUSTER = {
'name': 'dosportal',
'workers': 4,
'recycle': 500,
'timeout': 60,
'compress': True,
'retry': 10,
#'workers': 4,
#'recycle': 500,
'timeout': 5,
#'compress': True,
#'save_limit': 250,
#'queue_limit': 500,
#'cpu_affinity': 1,
'label': 'Worker',
'orm': 'default',
#'label': 'Worker',
#'orm': 'default',
'redis': {
'host': '10.5.0.7',
'port': 6379,
Expand Down
3 changes: 3 additions & 0 deletions DOSPORTAL/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def save_record(sender, instance, created = None, **kwargs):
df_spectrum['time'] = df_spectrum['time'].astype(float)
duration = df_spectrum['time'].max() - df_spectrum['time'].min()


metadata['log_info'] = {}
metadata['log_info']['internat_time_min'] = df_spectrum['time'].min()
metadata['log_info']['internat_time_max'] = df_spectrum['time'].max()
Expand All @@ -109,6 +110,8 @@ def save_record(sender, instance, created = None, **kwargs):

df_spectrum['time'] = df_spectrum['time'] - df_spectrum['time'].min()
instance.record_duration = datetime.timedelta(seconds=float(duration))
instance.time_of_interest_start = 0
instance.time_of_interest_end = float(duration)

new_name = instance.user_directory_path_data('pk')
df_spectrum.to_pickle('data/media/'+new_name)
Expand Down
11 changes: 9 additions & 2 deletions DOSPORTAL/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,21 @@ def process_record_entry(pk):
# si_mass = 0.1165e-3 # kg
# integration = 10 # s

metadata = json.loads(record.metadata)
#metadata = json.loads(record.metadata)
metadata = record.metadata

print('METADATA FILE', metadata)
print(type(metadata))

metadata = json.loads(metadata)

if not 'outputs' in metadata:
metadata["outputs"] = {}

metadata["outputs"]["dose_rate_mean"] = dose_rate

record.metadata = json.dumps(metadata, indent=4)
#record.metadata = json.dumps(metadata, indent=4)
record.metadata = metadata
record.save()

return dose_rate
Expand Down
11 changes: 7 additions & 4 deletions DOSPORTAL/templates/records/record_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
<td class="w-auto">Record duration:</td>
<td class="">{{ record.record_duration }}</td>
</tr>
<tr>
<td class="w-auto">Time of interest:</td>
<td class="">{{ record.time_of_interest_start }}s - {{ record.time_of_interest_end }}s</td>
</tr>
{% comment %}<tr>
<td class="w-auto">Type:</td>
<td class="">{{ record.get_record_type_display }}</td>
Expand All @@ -59,9 +63,9 @@
<tr>
<td class="w-auto">Log file:</td>
<td class="">{{record.log_original_filename}} ({{ record.log_file | filesize_mb }})</td>
{% if record.description|length > 1 %}<tr>
{% if record.metadata|length > 1 %}<tr>
<td class="w-auto">Description:</td>
<td class=""><div class="callout m-0 p-2">{{record.formatted_markdown | safe }}</div></td>
<td class=""><div class="callout m-0 p-2">{{record.metadata | safe }}</div></td>
</tr> {% endif %}
</tr>

Expand All @@ -86,11 +90,10 @@
<div class="card-body">
<div class="row m-0">
{% if "dose_rate_mean" in outputs %}
<div class="card p-2" style="width: initial; text-align: center;">
<div class="card p-2" style="width: initial; text-align: center;" title="Mean dose rate from whole record">
<div class="fw-light">Dose rate</div>
<div class="fw-bold text-muted">{{outputs.dose_rate_mean|floatformat:2 }}</div>
<div class="fw-light">uS/h</div>
<div class="small text-muted">mean dose rate</div>
</div>
{% endif %}
</div>
Expand Down
1 change: 1 addition & 0 deletions DOSPORTAL/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

path('login/', login_view, name='login'),
path('markdownx/', include('markdownx.urls')),
path('api-auth/', include('rest_framework.urls')),

#path(r'accounts/', include('organizations.urls')),
#path(r'invitations/', include(invitation_backend().get_urls())),
Expand Down
4 changes: 3 additions & 1 deletion DOSPORTAL/views_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ def RecordNewView(request):
def RecordView(request, pk):
rec = Record.objects.get(pk=pk)

outputs = json.loads(rec.metadata).get('outputs', {})
#outputs = json.loads(rec.metadata).get('outputs', {})
print("metadata", type(rec.metadata))
outputs = rec.metadata.get('outputs', {})
return render(request, 'records/record_detail.html', context={'record': rec, 'outputs': outputs})


Expand Down

0 comments on commit f4e3b7a

Please sign in to comment.