-
Notifications
You must be signed in to change notification settings - Fork 1
/
reportsgenerator.py
87 lines (64 loc) · 2.94 KB
/
reportsgenerator.py
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from faker import Faker
from geopy.geocoders import Nominatim
import random
import csv
import datetime
faker = Faker()
geolocator = Nominatim(user_agent="crime_report", timeout=10000)
# Define Nairobi's latitude and longitude boundaries
nairobi_bounds = {
'north': -1.160757,
'south': -1.450000, # Updated value to include Ongata Rongai's latitude
'east': 36.996153,
'west': 36.654915
}
# Define the crime categories
crime_categories = ['theft', 'burglary', 'assault', 'vandalism', 'fraud']
# Define the timeframe for the crime reports (1 year)
start_date = datetime.date.today() - datetime.timedelta(days=365)
end_date = datetime.date.today()
# Define gender categories
gender_categories = ["male", "female"]
# Define age between 18 and 60
age_categories = [i for i in range(18, 61)]
# Suspect's Gender
suspect_gender = ["male", "female"]
# Define demographic categories
demographic_categories = ["poor", "rich", "middle class"]
# Define the weather categories
weather_categories = ["sunny", "rainy", "cloudy", "windy"]
# Generate fake crime reports and write to a CSV file
with open('fake_crime_reports.csv', mode='w', newline='') as file:
writer = csv.writer(file)
writer.writerow(['Category', 'Latitude', 'Longitude', 'Location Name', 'Date', "Victim Gender", "Victim Age", "Suspect Gender", "Demographic", "Weather"])
for i in range(1000):
# Generate a random and location
location = geolocator.reverse(
(random.uniform(nairobi_bounds['south'], nairobi_bounds['north']),
random.uniform(nairobi_bounds['west'], nairobi_bounds['east']))
)
# Ensure the location is within Nairobi's boundaries
while location.address.find('Nairobi') == -1:
location = geolocator.reverse(
(random.uniform(nairobi_bounds['south'], nairobi_bounds['north']),
random.uniform(nairobi_bounds['west'], nairobi_bounds['east']))
)
reports = random.randint(10,30)
# Generate the reports
for j in range(reports):
# Generate a random crime category
category = random.choice(crime_categories)
# Generate a random date within the specified timeframe
date = faker.date_between(start_date=start_date, end_date=end_date)
# Generate a random gender
gender = random.choice(gender_categories)
# Generate a random age
age = random.choice(age_categories)
# Generate a random suspect's gender
suspect = random.choice(suspect_gender)
# Generate a random demographic
demographic = random.choice(demographic_categories)
# Generate a random weather
weather = random.choice(weather_categories)
# Write the report to the CSV file
writer.writerow([category, location.latitude, location.longitude, location.address, date, gender, age, suspect, demographic, weather])