<commit_before>from gevent import monkey; monkey.patch_all()

from bottle import post, get, run, request, response, HTTPResponse
import simcity
from simcity.util import listfiles
from simcityweb.util import error, get_simulation_config
from simcityweb.parameter import parse_parameters

config_sim = simcity.config.section('Simulations')

@get('/explore/simulate/<name>/<version>')
def get_simulation_by_name_version( name, version = None ):
    try:
        sim, version = get_simulation_config(name, version, config_sim)
        return sim[version]
    except HTTPResponse as ex:
        return ex

@get('/explore/simulate/<name>')
def get_simulation_by_name( name ):
    try:
        sim, version = get_simulation_config(name, None, config_sim)
        return sim
    except HTTPResponse as ex:
        return ex

@get('/explore')
def explore():
    return "API: overview | simulate | job"
    
@get('/explore/simulate')
def simulate_list():
    files = listfiles(config_sim['path'])
    return {"simulations": [f[:-5] for f in files if f.endswith('.json')]}

@post('/explore/simulate/<name>/<version>')
def simulate_name_version( name, version = None ):
    try:
        sim, version = get_simulation_config(name, version, config_sim)
        sim = sim[version]
        params = parse_parameters(dict(request.query), sim['parameters'])
    except HTTPResponse as ex:
        return ex
    
    token = simcity.task.add({
        'command': sim['command'],
        'version': version,
        'input': params
    })

    try:
        simcity.job.submit_if_needed(config_sim['default_host'], 1)
    except:
        pass # too bad. User can call /explore/job.

    couch_cfg = simcity.config.section('task-db')
    response.status = 201 # created
    response.set_header('Location', couch_cfg['public_url'] + couch_cfg['database'] + '/' + token.id)
    return token.value

@post('/explore/simulate/<name>')
def simulate_name( name ):
    return simulate_name_version(name)

@get('/explore/overview')
def overview():<commit_msg>Add simulation name to task<commit_after>from gevent import monkey; monkey.patch_all()

from bottle import post, get, run, request, response, HTTPResponse
import simcity
from simcity.util import listfiles
from simcityweb.util import error, get_simulation_config
from simcityweb.parameter import parse_parameters

config_sim = simcity.config.section('Simulations')

@get('/explore/simulate/<name>/<version>')
def get_simulation_by_name_version( name, version = None ):
    try:
        sim, version = get_simulation_config(name, version, config_sim)
        return sim[version]
    except HTTPResponse as ex:
        return ex

@get('/explore/simulate/<name>')
def get_simulation_by_name( name ):
    try:
        sim, version = get_simulation_config(name, None, config_sim)
        return sim
    except HTTPResponse as ex:
        return ex

@get('/explore')
def explore():
    return "API: overview | simulate | job"
    
@get('/explore/simulate')
def simulate_list():
    files = listfiles(config_sim['path'])
    return {"simulations": [f[:-5] for f in files if f.endswith('.json')]}

@post('/explore/simulate/<name>/<version>')
def simulate_name_version( name, version = None ):
    try:
        sim, version = get_simulation_config(name, version, config_sim)
        sim = sim[version]
        params = parse_parameters(dict(request.query), sim['parameters'])
    except HTTPResponse as ex:
        return ex
    
    token = simcity.task.add({
        'name': name,
        'command': sim['command'],
        'version': version,
        'input': params,
    })

    try:
        simcity.job.submit_if_needed(config_sim['default_host'], 1)
    except:
        pass # too bad. User can call /explore/job.

    couch_cfg = simcity.config.section('task-db')
    response.status = 201 # created
    response.set_header('Location', couch_cfg['public_url'] + couch_cfg['database'] + '/' + token.id)
    return token.value

@post('/explore/simulate/<name>')
def simulate_name( name ):
    return simulate_name_version(name)

@get('/explore/overview')
def overview():
{'fraction_non_alphanumeric': 0.12631321768873688, 'fraction_numerical': 0.002443195699975568, 'mean_word_length': 3.636466591166478, 'pattern_counts': {'":': 2, '<': 15, '<?xml version=': 0, '>': 15, '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': '5472968', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1250, 'n_words': 311}