<commit_before>import datetime
import json
import logging
import subprocess

from django.core.urlresolvers import reverse
from django.http import HttpResponse
from django.shortcuts import render
from django.shortcuts import redirect
from django.shortcuts import get_object_or_404
from django.utils.translation import ugettext
from django.contrib.auth.decorators import login_required
from django.contrib import messages
from django.contrib.sites.models import Site

from dakis.core.models import Experiment, Task

logger = logging.getLogger(__name__)


def index(request):
    exps = Experiment.objects.order_by('-created')
    if request.user.is_authenticated():
        exps = exps.filter(author=request.user)
    return render(request, 'website/index.html', {
        'experiments': exps,
    })


def toggle_exp_status(request, exp_id):
    exp = get_object_or_404(Experiment, pk=exp_id)
    if (exp.tasks.filter(status='C') | exp.tasks.filter(status='R')).exists():
        if exp.status == 'P':
            exp.status = 'R'
            run_worker(exp, request.user)
        else:
            exp.status = 'P'
            exp.threads = 0
        exp.save()
    elif exp.tasks.filter(status='D').exists():
        exp.status = 'D'
        exp.save()
    return redirect(exp)


def run_worker(exp, user):
    cmd = 'sshpass -p%s ssh %s "$HOME/.dakis/worker.py -exp=%d -exe=%s -rep=%s -br=%s -j"' % (
        user.profile.host_password,
        user.profile.hostname,
        exp.pk,
        exp.executable,
        exp.repository,
        exp.branch,
    )
    logger.debug('Running: ' + cmd)

    subprocess.Popen(cmd, shell=True, stdin=None, stdout=None, stderr=None, close_fds=True)
    if not exp.threads:
        exp.threads = 1
    else:
        exp.threads += 1
    exp.save()
    return

def run_worker_view(request, exp_id):
    exp = get_object_or_404(Experiment, pk=exp_id)
    run_worker(exp, request.user)
    return redirect(exp)


def get_next_task(request, exp_id):
    exp = get_object_or_404(Experiment, pk=exp_id)
    domain = Site.objects.get_current().domain<commit_msg>Show message when starting new experiment threads<commit_after>import datetime
import json
import logging
import subprocess

from django.core.urlresolvers import reverse
from django.http import HttpResponse
from django.shortcuts import render
from django.shortcuts import redirect
from django.shortcuts import get_object_or_404
from django.utils.translation import ugettext
from django.contrib.auth.decorators import login_required
from django.contrib import messages
from django.contrib.sites.models import Site

from dakis.core.models import Experiment, Task

logger = logging.getLogger(__name__)


def index(request):
    exps = Experiment.objects.order_by('-created')
    if request.user.is_authenticated():
        exps = exps.filter(author=request.user)
    return render(request, 'website/index.html', {
        'experiments': exps,
    })


def toggle_exp_status(request, exp_id):
    exp = get_object_or_404(Experiment, pk=exp_id)
    if (exp.tasks.filter(status='C') | exp.tasks.filter(status='R')).exists():
        if exp.status == 'P':
            exp.status = 'R'
            if not request.user.profile.hostname or not request.user.profile.host_password:
                messages.error(request, ugettext('Hostname or host password not set in UserProfile'))
            else:
                run_worker(exp, request.user)
                messages.success(request, ugettext('New thread was started successfully'))
        else:
            exp.status = 'P'
            exp.threads = 0
        exp.save()
    elif exp.tasks.filter(status='D').exists():
        exp.status = 'D'
        exp.save()
    return redirect(exp)


def run_worker(exp, user):
    cmd = 'sshpass -p%s ssh -o "StrictHostKeyChecking no" %s ' \
          '"$HOME/.dakis/worker.py -exp=%d -exe=%s -rep=%s -br=%s -j"' % (
        user.profile.host_password,
        user.profile.hostname,
        exp.pk,
        exp.executable,
        exp.repository,
        exp.branch,
    )
    logger.debug('Running: ' + cmd)

    subprocess.Popen(cmd, shell=True, stdin=None, stdout=None, stderr=None, close_fds=True)
    if not exp.threads:
        exp.threads = 1
    else:
        exp.threads += 1
    exp.save()
    return


def run_worker_view(request, exp_id):
    exp = get_object_or_404(Experiment, pk=exp_id)
    if not request.user.profile.hostname or not request.user.profile.host_password:
        messages.error(request, ugettext('Hostname or host password not set in UserProfile'))
    else:
        run_worker(exp, request.user)
        messages.success(request, ugettext('New thread was started successfully'))
    return redirect(exp)


def get_next_task(request, exp_id):
    exp = get_object_or_404(Experiment, pk=exp_id)
    domain = Site.objects.get_current().domain
{'fraction_non_alphanumeric': 0.11129431162407255, 'fraction_numerical': 0.006183017312448475, 'mean_word_length': 3.088458298230834, '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': '883018', 'n_tokens_mistral': 1551, 'n_tokens_neox': 1492, 'n_words': 350}