Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
File renamed without changes.
Binary file not shown.
68 changes: 68 additions & 0 deletions dataset/scenario1/batch_runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import os
import json
from multiprocessing import Pool, cpu_count
import time
from scenario1 import run_automated_simulation

def process_single_simulation(input_path):
"""
Função que carrega o JSON e executa a simulação automática.
Esta função será executada em um processo separado.
"""

filename = os.path.basename(input_path)

try:
with open(input_path, 'r') as f:
actions = json.load(f)

# Chama a função de simulação
run_automated_simulation(actions, filename)

return f"[SUCESSO] Simulação para {filename} concluída."

except Exception as e:
return f"[ERRO] Falha ao processar {filename}. Motivo: {e}"

def run_batch_simulations_parallel():
"""
Varre a pasta 'inputs' e executa simulações para todos os JSONs em paralelo.
"""
start_time = time.time()

inputs_dir = os.path.join(os.path.dirname(__file__), 'inputs')

if not os.path.exists(inputs_dir):
print(f"Erro: Pasta de inputs não encontrada em {inputs_dir}.")
return

json_files = [f for f in os.listdir(inputs_dir) if f.endswith('.json')]

if not json_files:
print("Nenhum arquivo JSON encontrado na pasta 'inputs'.")
return

# Constroi a lista de caminhos completos
json_files_paths = [os.path.join(inputs_dir, f) for f in json_files]

num_cores = cpu_count()
print(f"Encontrados {len(json_files_paths)} arquivos para simular")
print(f"Utilizando {num_cores} núcleos para processamento paralelo.")

# Pool de processos: distribui as tarefas entre os núcleos disponíveis
with Pool(processes=num_cores) as pool:
# map() aplica a função 'process_single_simulation' a todos os caminhos na lista
results = pool.map(process_single_simulation, json_files_paths)

end_time = time.time()

# Exibir Resultados
print("\n" + "="*50)
print("RESUMO DO PROCESSAMENTO EM LOTE:")
for result in results:
print(result)
print(f"\nTempo total de processamento: {end_time - start_time:.2f} segundos.")
print("="*50)

if __name__ == "__main__":
run_batch_simulations_parallel()
51 changes: 51 additions & 0 deletions dataset/scenario1/generate_random_inputs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import json
import random
import os
import datetime

def generate_random_input(num_files=10, max_actions=15, max_time=10.0):
"""Gera multiplos arquivos JSON com ações aleatorias."""

inputs_dir = os.path.join(os.path.dirname(__file__), 'inputs')
os.makedirs(inputs_dir, exist_ok=True) # Checa se a pasta 'inputs' já existe

for i in range(num_files):
actions = []

# 1. Gera o numero de acoes para este arquivo (entre 5 e max_actions)
num_actions = random.randint(5, max_actions)

# 2. Gera as acoes com tempo crescente
current_time = 0.0
for _ in range(num_actions):
# Tempo aleatorio entre 0.3s e 1.5s apos a ultima acao
current_time += random.uniform(0.3, 1.5)

# Limita o tempo total
if current_time > max_time:
break

# Posicao aleatoria dentro da tela (800x600)
pos_x = random.randint(50, 750)
pos_y = random.randint(50, 500)

action = {
"time": round(current_time, 2),
"type": "mouse_down",
"object": "ball", # No Cenario 1, so ha bolas
"pos": [pos_x, pos_y]
}
actions.append(action)

# 3. Salva o arquivo
timestamp = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
filename = f"random_input_{timestamp}_{i+1:02d}.json"
file_path = os.path.join(inputs_dir, filename)

with open(file_path, 'w') as f:
json.dump(actions, f, indent=4)

print(f"Gerado: {filename} ({len(actions)} acoes)")

if __name__ == "__main__":
generate_random_input(num_files=200, max_actions=15)
119 changes: 119 additions & 0 deletions dataset/scenario1/inputs/random_input_20251005161830_01.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
[
{
"time": 0.58,
"type": "mouse_down",
"object": "ball",
"pos": [
694,
93
]
},
{
"time": 1.36,
"type": "mouse_down",
"object": "ball",
"pos": [
331,
329
]
},
{
"time": 2.8,
"type": "mouse_down",
"object": "ball",
"pos": [
608,
239
]
},
{
"time": 3.63,
"type": "mouse_down",
"object": "ball",
"pos": [
571,
327
]
},
{
"time": 4.79,
"type": "mouse_down",
"object": "ball",
"pos": [
607,
116
]
},
{
"time": 5.38,
"type": "mouse_down",
"object": "ball",
"pos": [
664,
177
]
},
{
"time": 5.76,
"type": "mouse_down",
"object": "ball",
"pos": [
748,
290
]
},
{
"time": 7.2,
"type": "mouse_down",
"object": "ball",
"pos": [
597,
144
]
},
{
"time": 7.85,
"type": "mouse_down",
"object": "ball",
"pos": [
715,
108
]
},
{
"time": 8.4,
"type": "mouse_down",
"object": "ball",
"pos": [
588,
358
]
},
{
"time": 8.9,
"type": "mouse_down",
"object": "ball",
"pos": [
554,
92
]
},
{
"time": 9.33,
"type": "mouse_down",
"object": "ball",
"pos": [
649,
50
]
},
{
"time": 9.65,
"type": "mouse_down",
"object": "ball",
"pos": [
569,
414
]
}
]
101 changes: 101 additions & 0 deletions dataset/scenario1/inputs/random_input_20251005161830_02.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
[
{
"time": 0.35,
"type": "mouse_down",
"object": "ball",
"pos": [
602,
196
]
},
{
"time": 1.05,
"type": "mouse_down",
"object": "ball",
"pos": [
185,
112
]
},
{
"time": 2.49,
"type": "mouse_down",
"object": "ball",
"pos": [
284,
58
]
},
{
"time": 3.94,
"type": "mouse_down",
"object": "ball",
"pos": [
288,
67
]
},
{
"time": 5.09,
"type": "mouse_down",
"object": "ball",
"pos": [
505,
341
]
},
{
"time": 5.72,
"type": "mouse_down",
"object": "ball",
"pos": [
596,
423
]
},
{
"time": 6.02,
"type": "mouse_down",
"object": "ball",
"pos": [
64,
273
]
},
{
"time": 6.82,
"type": "mouse_down",
"object": "ball",
"pos": [
721,
466
]
},
{
"time": 7.61,
"type": "mouse_down",
"object": "ball",
"pos": [
370,
358
]
},
{
"time": 8.72,
"type": "mouse_down",
"object": "ball",
"pos": [
93,
343
]
},
{
"time": 9.98,
"type": "mouse_down",
"object": "ball",
"pos": [
360,
309
]
}
]
Loading