<commit_before>import json
from pyramid.view import view_config, view_defaults
from pyramid.response import Response
from magmaweb.job import make_job_factory

# TODO Do not use _html_response but,
# create renderer derived from json renderer with content_type='text/html'
@view_defaults(renderer='json')
class RpcViews(object):
    # TODO RpcViews is a wrapper around JobQuery, make self smaller
    def __init__(self, request):
        self.request = request
        self.job_factory = make_job_factory(request.registry.settings)

    def job(self):
        """ Job of current request """
        return self.job_factory.fromId(self.request.matchdict['jobid'])

    def new_job(self):
        """ Returns clone of job of current request
         or empty job if current request has no job"""
        try:
            return self.job_factory.cloneJob(self.job())
        except KeyError:
            return self.job_factory.fromScratch()

    def _html_response(self, id):
        return Response(json.dumps({"success": True, "jobid": str(id) }), content_type='text/html')

    @view_config(route_name='rpc.add_structures')
    def add_structures(self):
        job = self.new_job()
        """ stage input files and write job script """
        jobquery = job.jobquery().add_structures(self.request.POST, job.maxMSLevel() > 0)
        """ Submit job script to job manager """
        self.job_factory.submitQuery(jobquery)
        return self._html_response(job.id)

    @view_config(route_name='rpc.add_ms_data')
    def add_ms_data(self):
        job = self.new_job()
        """ stage input files and write job script """
        jobquery = job.jobquery().add_ms_data(self.request.POST, job.metabolitesTotalCount() > 0)
        """ Submit job script to job manager """
        self.job_factory.submitQuery(jobquery)
        return self._html_response(job.id)

    @view_config(route_name='rpc.metabolize')
    def metabolize(self):
        job = self.new_job()
        """ stage input files and write job script """
        jobquery = job.jobquery().metabolize(self.request.POST, job.maxMSLevel() > 0)
        """ Submit job script to job manager """
        self.job_factory.submitQuery(jobquery)
        return { 'success': True, 'jobid': job.id }

    @view_config(route_name='rpc.metabolize_one')
    def metabolize_one(self):
        job = self.new_job()
        """ stage input files and write job script """
        jobquery = job.jobquery().metabolize_one(self.request.POST, job.maxMSLevel() > 0)
        """ Submit job script to job manager """
        self.job_factory.submitQuery(jobquery)
        return { 'success': True, 'jobid': job.id }

    @view_config(route_name='rpc.annotate')
    def annotate(self):
        job = self.new_job()
        """ stage input files and write job script """
        jobquery = job.jobquery().annotate(self.request.POST)
        """ Submit job script to job manager """
        self.job_factory.submitQuery(jobquery)
        return { 'success': True, 'jobid': job.id }

    @view_config(route_name='rpc.allinone')
    def allinone(self):
        job = self.new_job()
        """ stage input files and write job script """
        jobquery = job.jobquery().allinone(self.request.POST)
        """ Submit job script to job manager """
        self.job_factory.submitQuery(jobquery)
        return self._html_response(job.id)<commit_msg>UUID can not be json encoded, convert to str<commit_after>import json
from pyramid.view import view_config, view_defaults
from pyramid.response import Response
from magmaweb.job import make_job_factory

# TODO Do not use _html_response but,
# create renderer derived from json renderer with content_type='text/html'
@view_defaults(renderer='json')
class RpcViews(object):
    # TODO RpcViews is a wrapper around JobQuery, make self smaller
    def __init__(self, request):
        self.request = request
        self.job_factory = make_job_factory(request.registry.settings)

    def job(self):
        """ Job of current request """
        return self.job_factory.fromId(self.request.matchdict['jobid'])

    def new_job(self):
        """ Returns clone of job of current request
         or empty job if current request has no job"""
        try:
            return self.job_factory.cloneJob(self.job())
        except KeyError:
            return self.job_factory.fromScratch()

    def _html_response(self, id):
        return Response(json.dumps({"success": True, "jobid": str(id) }), content_type='text/html')

    @view_config(route_name='rpc.add_structures')
    def add_structures(self):
        job = self.new_job()
        """ stage input files and write job script """
        jobquery = job.jobquery().add_structures(self.request.POST, job.maxMSLevel() > 0)
        """ Submit job script to job manager """
        self.job_factory.submitQuery(jobquery)
        return self._html_response(job.id)

    @view_config(route_name='rpc.add_ms_data')
    def add_ms_data(self):
        job = self.new_job()
        """ stage input files and write job script """
        jobquery = job.jobquery().add_ms_data(self.request.POST, job.metabolitesTotalCount() > 0)
        """ Submit job script to job manager """
        self.job_factory.submitQuery(jobquery)
        return self._html_response(job.id)

    @view_config(route_name='rpc.metabolize')
    def metabolize(self):
        job = self.new_job()
        """ stage input files and write job script """
        jobquery = job.jobquery().metabolize(self.request.POST, job.maxMSLevel() > 0)
        """ Submit job script to job manager """
        self.job_factory.submitQuery(jobquery)
        return { 'success': True, 'jobid': str(job.id) }

    @view_config(route_name='rpc.metabolize_one')
    def metabolize_one(self):
        job = self.new_job()
        """ stage input files and write job script """
        jobquery = job.jobquery().metabolize_one(self.request.POST, job.maxMSLevel() > 0)
        """ Submit job script to job manager """
        self.job_factory.submitQuery(jobquery)
        return { 'success': True, 'jobid': str(job.id) }

    @view_config(route_name='rpc.annotate')
    def annotate(self):
        job = self.new_job()
        """ stage input files and write job script """
        jobquery = job.jobquery().annotate(self.request.POST)
        """ Submit job script to job manager """
        self.job_factory.submitQuery(jobquery)
        return { 'success': True, 'jobid': str(job.id) }

    @view_config(route_name='rpc.allinone')
    def allinone(self):
        job = self.new_job()
        """ stage input files and write job script """
        jobquery = job.jobquery().allinone(self.request.POST)
        """ Submit job script to job manager """
        self.job_factory.submitQuery(jobquery)
        return self._html_response(job.id)
{'fraction_non_alphanumeric': 0.11806981519507187, 'fraction_numerical': 0.0011733646230566149, 'mean_word_length': 3.023008849557522, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 11, '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': '4390895', 'n_tokens_mistral': 2037, 'n_tokens_neox': 1994, 'n_words': 499}