<commit_before>from django.template import Context
from django.http import HttpResponse
from django.views.decorators.cache import never_cache

from tardis.tardis_portal.auth import decorators as authz
from tardis.tardis_portal.shortcuts import render_response_index
from tardis.tardis_portal.views import *

from tardis.tardis_portal.models import DatafileParameterSet
from tardis.tardis_portal.models import Schema
    
def index_mt(request):
    status = ''

    c = Context({'status': status})
    return HttpResponse(render_response_index(request,
                        'index_mt.html', c))

def about_mt(request):
    c = Context({'subtitle': 'About',
                 'about_pressed': True,
                 'nav': [{'name': 'About', 'link': '/about/'}]})
    
    return HttpResponse(render_response_index(request,
                        'about_mt.html', c))
    
def partners_mt(request):
    c = Context({})
    
    return HttpResponse(render_response_index(request,
                        'partners_mt.html', c))
    
@never_cache
@authz.datafile_access_required
def retrieve_parameters(request, dataset_file_id):
    schema_edaxgenesis_spc = Schema.objects.filter(name="EDAXGenesis_SPC")
    schema_id = 0
    if schema_edaxgenesis_spc:
        schema_id = schema_edaxgenesis_spc[0].id
    ordered_fields = ["Sample Type (Label)", "Preset", "Live Time", "Acc. Voltage"]
    datafileparametersets = DatafileParameterSet.objects.filter(dataset_file__pk=dataset_file_id)
    parametersets = {}
    for parameterset in datafileparametersets:
        if parameterset.schema.id == schema_id:
            unsorted = {}
            sorted = []
            for parameter in parameterset.datafileparameter_set.all():
                unsorted[str(parameter.name.full_name)] = parameter
            for field in ordered_fields:
                if field in unsorted:
                    sorted.append(unsorted[field])
                    unsorted.pop(field)
            if unsorted:<commit_msg>MT-45: fixed the order of atomic peaks.<commit_after>from django.template import Context
from django.http import HttpResponse
from django.views.decorators.cache import never_cache

from tardis.tardis_portal.auth import decorators as authz
from tardis.tardis_portal.shortcuts import render_response_index
from tardis.tardis_portal.views import *

from tardis.tardis_portal.models import DatafileParameterSet
from tardis.tardis_portal.models import Schema
    
def index_mt(request):
    status = ''

    c = Context({'status': status})
    return HttpResponse(render_response_index(request,
                        'index_mt.html', c))

def about_mt(request):
    c = Context({'subtitle': 'About',
                 'about_pressed': True,
                 'nav': [{'name': 'About', 'link': '/about/'}]})
    
    return HttpResponse(render_response_index(request,
                        'about_mt.html', c))
    
def partners_mt(request):
    c = Context({})
    
    return HttpResponse(render_response_index(request,
                        'partners_mt.html', c))
    
@never_cache
@authz.datafile_access_required
def retrieve_parameters(request, dataset_file_id):
    schema_edaxgenesis_spc = Schema.objects.filter(name="EDAXGenesis_SPC")
    schema_id = 0
    if schema_edaxgenesis_spc:
        schema_id = schema_edaxgenesis_spc[0].id
    field_order_spc = ["Sample Type (Label)", "Preset", "Live Time", "Acc. Voltage"]
    datafileparametersets = DatafileParameterSet.objects.filter(dataset_file__pk=dataset_file_id)
    parametersets = {}
    for parameterset in datafileparametersets:
        # sort spectrum tags
        if parameterset.schema.id == schema_id:
            unsorted = {}
            sorted = []
            # get list of parameter
            for parameter in parameterset.datafileparameter_set.all():
                unsorted[str(parameter.name.full_name)] = parameter
            # sort spectrum tags defined in field_order_spc                
            for field in field_order_spc:
                if field in unsorted:
                    sorted.append(unsorted[field])
                    unsorted.pop(field)
            # sort atomic peak numbers
            peaks = []
            for field in unsorted:
                if field.startswith("Atomic Numbers"):
                    peaks.append(field)
            peaks.sort(key=lambda peak: int(peak.split("peak ")[-1][:-1])) 
            for field in peaks:
                sorted.append(unsorted[field])
                unsorted.pop(field)
            # sort the rest of unsorted parameters
            if unsorted:
{'fraction_non_alphanumeric': 0.09245159886882749, 'fraction_numerical': 0.001740265390472047, 'mean_word_length': 2.6006264682850433, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4989936', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1292, 'n_words': 285}