<commit_before>import requests
import os
import shutil
import json
from django.conf import settings
import encodings.idna

import boto3
import boto
os.environ['http_proxy']=''
import urllib
from django.conf import settings
from django.http import HttpResponseRedirect
import numpy as np
from ..models import DesignModel
from .utils import *

def create_neurodesign_string(sid):
    desdata = DesignModel.objects.filter(SID=sid).last()

    matrices = probs_and_cons(desdata.SID)

    if desdata.ITImodel == 1:
        model = "fixed"
        ITImean = desdata.ITIfixed
        ITImin = 'None'
        ITImax = 'None'
    elif desdata.ITImodel == 2:
        model = "exponential"
        ITImean = desdata.ITItruncmean
        ITImin = desdata.ITItruncmin
        ITImax = desdata.ITItruncmax
    elif desdata.ITImodel == 3:
        model = "uniform"
        ITImin = desdata.ITIunifmin
        ITImax = desdata.ITIunifmax
        ITImean = (desdata.ITIunifmin+desdata.ITIunifmax)/2.

    if (desdata.MaxRepeat<4 and desdata.S<5) or desdata.S==2:
        R = [0,1,0]
    else:
        R = [0.4,0.4,0.2]

    neurodesign_string = "from neurodesign import geneticalgorithm \n" + \
    "EXP = geneticalgorithm.experiment( \n" + \
    "    TR = %s, \n " %desdata.TR + \
    "    n_trials = %s, \n " %desdata.L + \
    "    P = %s, \n " %matrices['P'].tolist() + \
    "    C = %s, \n " %matrices['C'].tolist() + \
    "    duration = %s, \n " %desdata.duration + \
    "    n_stimuli = %s, \n " %desdata.S + \
    "    rho = %s, \n " %desdata.rho + \
    "    resolution = %s, \n " %desdata.resolution + \
    "    stim_duration = %s, \n " %desdata.stim_duration + \
    "    restnum = %s, \n " %desdata.RestNum + \
    "    restdur = %s, \n " %desdata.RestDur + \
    "    ITImodel = '%s', \n " %model + \
    "    ITImin = %s, \n " %ITImin + \
    "    ITImean = %s, \n " %ITImean + \
    "    ITImax = %s, \n " %ITImax + \
    "    confoundorder = %s, \n " %desdata.ConfoundOrder + \
    "    maxrep = %s, \n " %desdata.MaxRepeat + \
    "    hardprob = %s, \n " %desdata.HardProb + \
    "    t_pre = %s, \n " %desdata.t_prestim + \
    "    t_post = %s, \n" %desdata.t_poststim + \
    ") \n \n" + \
    "seed = %s \n" %np.random.randint(10000) + \
    "POP = geneticalgorithm.population( \n" + \
    "    experiment = EXP, \n " + \<commit_msg>debug GA for batch<commit_after>import requests
import os
import shutil
import json
from django.conf import settings
import encodings.idna

import boto3
import boto
os.environ['http_proxy']=''
import urllib
from django.conf import settings
from django.http import HttpResponseRedirect
import numpy as np
from ..models import DesignModel
from .utils import *

def create_neurodesign_string(sid):
    desdata = DesignModel.objects.filter(SID=sid).last()

    matrices = probs_and_cons(desdata.SID)

    if desdata.ITImodel == 1:
        model = "fixed"
        ITImean = desdata.ITIfixed
        ITImin = 'None'
        ITImax = 'None'
    elif desdata.ITImodel == 2:
        model = "exponential"
        ITImean = desdata.ITItruncmean
        ITImin = desdata.ITItruncmin
        ITImax = desdata.ITItruncmax
    elif desdata.ITImodel == 3:
        model = "uniform"
        ITImin = desdata.ITIunifmin
        ITImax = desdata.ITIunifmax
        ITImean = (desdata.ITIunifmin+desdata.ITIunifmax)/2.

    if (desdata.MaxRepeat<4 and desdata.S<5) or desdata.S==2:
        R = [0,1,0]
    else:
        R = [0.4,0.4,0.2]

    neurodesign_string = "import os \n" + \
    "if 'TASK_UID' in os.environ.keys(): \n" + \
    "    import geneticalgorithm \n" + \
    "else: \n" + \
    "    from neurodesign import geneticalgorithm, generate, msequence \n" + \
    "from neurodesign import geneticalgorithm \n" + \
    "EXP = geneticalgorithm.experiment( \n" + \
    "    TR = %s, \n " %desdata.TR + \
    "    n_trials = %s, \n " %desdata.L + \
    "    P = %s, \n " %matrices['P'].tolist() + \
    "    C = %s, \n " %matrices['C'].tolist() + \
    "    duration = %s, \n " %desdata.duration + \
    "    n_stimuli = %s, \n " %desdata.S + \
    "    rho = %s, \n " %desdata.rho + \
    "    resolution = %s, \n " %desdata.resolution + \
    "    stim_duration = %s, \n " %desdata.stim_duration + \
    "    restnum = %s, \n " %desdata.RestNum + \
    "    restdur = %s, \n " %desdata.RestDur + \
    "    ITImodel = '%s', \n " %model + \
    "    ITImin = %s, \n " %ITImin + \
    "    ITImean = %s, \n " %ITImean + \
    "    ITImax = %s, \n " %ITImax + \
    "    confoundorder = %s, \n " %desdata.ConfoundOrder + \
    "    maxrep = %s, \n " %desdata.MaxRepeat + \
    "    hardprob = %s, \n " %desdata.HardProb + \
    "    t_pre = %s, \n " %desdata.t_prestim + \
    "    t_post = %s, \n" %desdata.t_poststim + \
    ") \n \n" + \
    "seed = %s \n" %np.random.randint(10000) + \
    "POP = geneticalgorithm.population( \n" + \
    "    experiment = EXP, \n " + \
{'fraction_non_alphanumeric': 0.15558727569331157, 'fraction_numerical': 0.00897226753670473, 'mean_word_length': 2.132183908045977, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6640286', 'n_tokens_mistral': 1954, 'n_tokens_neox': 1919, 'n_words': 405}