-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseedData.py
177 lines (162 loc) · 4.04 KB
/
seedData.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import json
from random import randrange, random, choice, uniform
from datetime import datetime, timedelta
def get_random_id():
ship_id = ''.join(choice('0123456789abcdef') for i in range(24))
return ship_id
locations = [
{'city' : "Houston",
'location': {
'type': "Point",
'coordinates' : [-95.36, 29.76]
}
},
{'city' : "College Station",
'location': {
'type': "Point",
'coordinates' : [-96.33, 30.62]
}
},
{'city' : "Austin",
'location': {
'type': "Point",
'coordinates' : [-97.74, 30.26]
}
},
{'city' : "San Antonio",
'location': {
'type': "Point",
'coordinates' : [-98.49, 29.42]
}
},
{'city' : "Dallas",
'location': {
'type': "Point",
'coordinates' : [-96.79, 32.77]
}
},
]
costs = {
'01' : {
'distance': 96,
'duration': 90,
},
'02' : {
'distance': 160,
'duration': 150,
},
'03' : {
'distance': 197,
'duration': 180,
},
'04' : {
'distance': 260,
'duration': 240,
},
'12' : {
'distance': 110,
'duration': 110,
},
'13' : {
'distance': 170,
'duration': 172,
},
'14' : {
'distance': 175,
'duration': 165,
},
'23' : {
'distance': 80,
'duration': 77,
},
'24' : {
'distance': 195,
'duration': 175,
},
'34' : {
'distance': 274,
'duration': 240,
},
}
companies = [
{
'company' : "Baker Hughes",
'city' : "Houston",
'location': {
'type': "Point",
'coordinates' : [-95.36, 29.76]
}
},
{
'company' : "Texas A&M University",
'city' : "College Station",
'location': {
'type': "Point",
'coordinates' : [-96.33, 30.62]
}
},
{
'company' : "t.u.",
'city' : "Austin",
'location': {
'type': "Point",
'coordinates' : [-97.74, 30.26]
}
},
]
def get_origin_destination():
a = randrange(0, 5)
b = randrange(0, 5)
while (a==b):
b = randrange(0, 5)
return a, b
def order(a,b):
if (a<b):
return str(a)+str(b)
else:
return str(b)+str(a)
def get_duration(origin, destination):
return costs[order(origin, destination)]['duration']
def get_distance(origin, destination):
return costs[order(origin, destination)]['distance']
def get_depart_time():
return datetime(2020, 1, randrange(26, 32), hour=randrange(0, 24), minute=randrange(0, 60), second=0, microsecond=0, tzinfo=None)
def get_arrival_time(depart_time, duration):
return depart_time + timedelta(minutes=duration)
def score(a,b):
return int(a*uniform(0.9,1.1) + b*uniform(0.9,1.1))
def shipGenerator():
ship_id = get_random_id()
origin, destination = get_origin_destination()
depart_time = get_depart_time()
distance = get_distance(origin, destination)
duration = get_duration(origin, destination)
return json.dumps({
"_id":{
"$oid": ship_id
},
"owner":companies[randrange(0, 3)],
"shipNumber":ship_id,
"origin": locations[origin],
"destination": locations[destination],
"distance": distance,
"duration":duration,
"departureTime": str(depart_time),
"arrivalTime": str(get_arrival_time(depart_time, duration)),
"cargoType": randrange(0,3),
"maxSpeed":"90",
"weight":randrange(1,10),
"dimension": {
"length":random()*10,
"height":random()*2,
"width":random()*2,
},
"fullCargo":randrange(0,2),
"sustainabilityScore": score(distance, duration),
"stage":0,
})
def print_samples(n_samples):
file = open('data.json','w')
for i in range (0, n_samples):
file.write(shipGenerator()+'\n')
print_samples(500)