You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
3.0 KiB
87 lines
3.0 KiB
import json |
|
import random |
|
from datetime import datetime, timedelta |
|
|
|
def generate_random_point(): |
|
# Coordinate approssimative dell'Europa |
|
lon = random.uniform(-10.0, 30.0) |
|
lat = random.uniform(35.0, 60.0) |
|
return [lon, lat] |
|
|
|
def generate_data(num_points=500): |
|
features = [] |
|
operators = ["Operator A", "Operator B", "Operator C", "Operator D", "Operator E"] |
|
# Status principali (senza timing) |
|
statuses = ["OPEN", "CLOSED", "IN_PROGRESS", "ON_HOLD"] |
|
# Timing status solo per CLOSED |
|
timing_statuses = ["CLOSED_ON_TIME", "CLOSED_LATE"] |
|
# Task types |
|
task_types = ["Create Activity", "Close Activity", "Create WF", "Close WF", "Select DTO", "Report Generation", "Report QC"] |
|
|
|
base_time = datetime.now() |
|
|
|
for i in range(num_points): |
|
status = random.choice(statuses) |
|
operator = random.choice(operators) |
|
duration = random.randint(10, 300) |
|
task_type = random.choice(task_types) |
|
|
|
# Durations per task (in secondi) - min, max, avg variano per task |
|
min_duration = random.randint(10, 25) |
|
max_duration = random.randint(40, 60) |
|
avg_duration = random.randint(min_duration + 5, max_duration - 5) |
|
task_duration = random.randint(min_duration, max_duration + 20) |
|
|
|
# Lead time in minuti (per Avg Lead Time) - solo per CLOSED |
|
lead_time = None |
|
timing_status = None |
|
if status == "CLOSED": |
|
lead_time = random.randint(5, 120) # minuti |
|
# 70% on time, 30% late (come in figura ~24 vs 11) |
|
timing_status = random.choices(timing_statuses, weights=[70, 30])[0] |
|
|
|
# Random timestamp negli ultimi 7 giorni |
|
time_offset = random.randint(0, 7 * 24 * 60 * 60) |
|
timestamp = (base_time - timedelta(seconds=time_offset)).isoformat() |
|
|
|
properties = { |
|
"status": status, |
|
"operator": operator, |
|
"duration": duration, |
|
"timestamp": timestamp, |
|
"id": i, |
|
"task_type": task_type, |
|
"min_duration": min_duration, |
|
"max_duration": max_duration, |
|
"avg_duration": avg_duration, |
|
"task_duration": task_duration |
|
} |
|
|
|
# Aggiungi lead_time e timing_status solo se CLOSED |
|
if lead_time is not None: |
|
properties["lead_time"] = lead_time |
|
if timing_status is not None: |
|
properties["timing_status"] = timing_status |
|
|
|
feature = { |
|
"type": "Feature", |
|
"properties": properties, |
|
"geometry": { |
|
"type": "Point", |
|
"coordinates": generate_random_point() |
|
} |
|
} |
|
features.append(feature) |
|
|
|
geojson = { |
|
"type": "FeatureCollection", |
|
"features": features |
|
} |
|
|
|
with open('data/sample.geojson', 'w') as f: |
|
json.dump(geojson, f, indent=2) |
|
|
|
print(f"Generated {num_points} data points in data/sample.geojson") |
|
|
|
if __name__ == "__main__": |
|
generate_data(1000)
|
|
|