-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsvgen.py
More file actions
57 lines (48 loc) · 1.93 KB
/
csvgen.py
File metadata and controls
57 lines (48 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import csv
from datetime import datetime, timedelta
import random
import numpy as np
# Configuración
COCO_LABELS_PATH = './coco_80_labels_list.txt'
OUTPUT_FILE = 'data.csv'
START_DATE = datetime(2025, 3, 1, 0, 0, 0)
END_DATE = datetime(2025, 4, 1, 0, 0, 0)
def cargar_labels():
with open(COCO_LABELS_PATH, 'r') as f:
return [line.strip() for line in f if line.strip()]
def generar_datos_objeto(hora, dia_semana, label):
# Frecuencias base por tipo de objeto (ejemplo)
frecuencias = {
'person': 0.8, 'car': 0.7, 'chair': 0.5, 'book': 0.3,
'truck': 0.4, 'dog': 0.2, 'cell phone': 0.6, 'bottle': 0.5
}
base = frecuencias.get(label, 0.2) # Valor por defecto para objetos menos comunes
# Variación por hora y día
if dia_semana < 5: # Días laborables
if 7 <= hora <= 9 or 17 <= hora <= 19:
multiplicador = random.uniform(1.5, 3.0) # Horas pico
else:
multiplicador = random.uniform(0.5, 1.2)
else: # Fin de semana
if 10 <= hora <= 20:
multiplicador = random.uniform(1.2, 2.0)
else:
multiplicador = random.uniform(0.3, 0.8)
return max(0, int(np.random.poisson(base * multiplicador * 10)))
# Generar el archivo CSV
labels = cargar_labels()
with open(OUTPUT_FILE, 'w', newline='') as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=['Timestamp'] + labels)
writer.writeheader()
current = START_DATE
while current < END_DATE:
fila = {'Timestamp': current.strftime('%d/%m/%Y %H:%M:%S')}
for label in labels:
fila[label] = generar_datos_objeto(
hora=current.hour,
dia_semana=current.weekday(),
label=label
)
writer.writerow(fila)
current += timedelta(hours=1)
print(f'Archivo {OUTPUT_FILE} generado con {len(labels)} objetos COCO')