synthetic_diaries
Module that generates a MNO synthetic network.
SyntheticDiaries
Bases: Component
Class that generates the synthetic activity-trip diaries data. It inherits from the Component abstract class.
Source code in multimno/components/ingestion/synthetic/synthetic_diaries.py
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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 |
|
add_agent_date_activities(activities, user_id, agent_stay_type_sequence, home_location, work_location, date, start_of_date, end_of_date)
For a specific date and user, generate a sequence of activities probabilistically according to the specified activity superset and the activity probabilities. Firstly, assign to each of these activities the minimum duration considered for that activity type. Trip times are based on Pythagorean distance and a specified average speed. If the sum of all minimum duration of the activities and the duration of the trips is higher than the 24h of the day, then assign just one "home" activity to the agent from 00:00:00 to 23:59:59. Else, there will be a remaining time. E.g., the diary of an agent, after adding up all trip durations and minimum activity durations may end at 20:34:57. There is a remaining time to complete the full diary (23:59:59 - 20:34:57). Adjust activity times probabilistically according to the maximum activity duration and this remaining time, making the diary end at exactly 23:59:59.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
activities
|
List[Row]
|
list of generated activities (stays and moves) for the agent for all of the specified dates. Each activity is a spark row object. |
required |
user_id
|
int
|
agent identifier. |
required |
agent_stay_type_sequence
|
List[str]
|
list of generated stay types, each represented by a string indicating the stay type. |
required |
home_location
|
Tuple[float, float]
|
coordinates of home location. |
required |
work_location
|
Tuple[float, float]
|
coordinates of work location. |
required |
date
|
date
|
date for activity sequence generation, used for timestamps and random seed generation. |
required |
start_of_date
|
datetime
|
timestamp of current date at 00:00:00. |
required |
end_of_date
|
datetime
|
timestamp of current date at 23:59:59. |
required |
Source code in multimno/components/ingestion/synthetic/synthetic_diaries.py
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 |
|
add_date_activities(date, activities)
Generate activity (stays and moves) rows for a specific date according to parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
date
|
date
|
date for activity sequence generation, used for timestamps and random seed generation. |
required |
activities
|
List[Row]
|
list of generated activities (stays and moves) for the agent for all of the specified dates. Each activity is a spark row object. |
required |
Source code in multimno/components/ingestion/synthetic/synthetic_diaries.py
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 |
|
adjust_activity_times(date_activities, remaining_time, user_id, date, start_of_date, end_of_date)
Modifies the "date_activities" list, changing the initial and final timestamps of both stays and moves probablilistically in order to generate stay durations different from the minimum and adjust the durations of the activities to the 24h of the day.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
date_activities
|
List[Row]
|
list of generated activities (stays and moves) of the agent for the specified date. Each activity/trip is a spark row object. |
required |
user_id
|
int
|
agent identifier. |
required |
date
|
date
|
date for activity sequence generation, used for timestamps and random seed generation. |
required |
start_of_date
|
datetime
|
timestamp of current date at 00:00:00. |
required |
end_of_date
|
datetime
|
timestamp of current date at 23:59:59. |
required |
Source code in multimno/components/ingestion/synthetic/synthetic_diaries.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
|
calculate_trip_final_time(origin_location, destin_location, origin_timestamp)
Calculate end time of a trip given an origin time, an origin location, a destination location and a speed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
origin_location
|
Tuple[float, float]
|
lon, lat of 1st point, in decimal degrees. |
required |
destin_location
|
Tuple[float, float]
|
lon, lat of 2nd point, in decimal degrees. |
required |
origin_timestamp
|
datetime
|
start time of trip. |
required |
Returns:
Type | Description |
---|---|
datetime
|
datetime.datetime: end time of trip. |
Source code in multimno/components/ingestion/synthetic/synthetic_diaries.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
|
calculate_trip_time(o_location, d_location)
Calculate trip time given an origin location and a destination location, according to the specified trip speed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
o_location
|
Tuple[float, float]
|
lon, lat of 1st point, in decimal degrees. |
required |
d_location
|
Tuple[float, float]
|
lon, lat of 2nd point, in decimal degrees. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
trip time, in seconds. |
Source code in multimno/components/ingestion/synthetic/synthetic_diaries.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|
create_agent_activities_min_duration(user_id, agent_stay_type_sequence, home_location, work_location, date, start_of_date, end_of_date)
Generate activities of the minimum duration following the specified agent activity sequence for this agent and date.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_id
|
int
|
agent identifier. |
required |
agent_stay_type_sequence
|
List[str]
|
list of generated stay types, each represented by a string indicating the stay type. |
required |
home_location
|
Tuple[float, float]
|
coordinates of home location. |
required |
work_location
|
Tuple[float, float]
|
coordinates of work location. |
required |
date
|
date
|
date for activity sequence generation, used for timestamps and random seed generation. |
required |
start_of_date
|
datetime
|
timestamp of current date at 00:00:00. |
required |
end_of_date
|
datetime
|
timestamp of current date at 23:59:59. |
required |
Returns:
Type | Description |
---|---|
List[Row]
|
List[Row]: list of generated activities and trips, each represented by a spark row object with all its information. |
Source code in multimno/components/ingestion/synthetic/synthetic_diaries.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
|
generate_activities()
Generate activity and trip rows according to parameters.
Returns:
Type | Description |
---|---|
List[Row]
|
List[Row]: list of generated activities and trips for the agent for all of the specified dates. Each activity/trip is a spark row object. |
Source code in multimno/components/ingestion/synthetic/synthetic_diaries.py
478 479 480 481 482 483 484 485 486 487 488 489 |
|
generate_home_location(agent_id)
Generate random home location based on bounding box limits.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_id
|
int
|
identifier of agent, used for random seed generation. |
required |
Returns:
Type | Description |
---|---|
Tuple[float, float]
|
Tuple[float,float]: coordinates of generated home location. |
Source code in multimno/components/ingestion/synthetic/synthetic_diaries.py
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 |
|
generate_lonlat_at_distance(lon1, lat1, d, seed)
Given a point (lon, lat) and a distance, in meters, calculate a new random point that is exactly at the specified distance of the provided lon, lat.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lon1
|
float
|
longitude of point, specified in decimal degrees. |
required |
lat1
|
float
|
latitude of point, specified in decimal degrees. |
required |
d
|
float
|
distance, in meters. |
required |
seed
|
int
|
random seed integer. |
required |
Returns:
Type | Description |
---|---|
Tuple[float, float]
|
Tuple[float, float]: coordinates of randomly generated point. |
Source code in multimno/components/ingestion/synthetic/synthetic_diaries.py
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 |
|
generate_min_stay_duration(stay_type)
Generate minimum stay duration based on stay type specifications.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stay_type
|
str
|
type of stay. Shall be "home", "work" or "other". |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
minimum stay duration. |
Source code in multimno/components/ingestion/synthetic/synthetic_diaries.py
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 |
|
generate_other_location(agent_id, date, activity_number, home_location, previous_location, seed=6)
Generate other activity location based on previous location and maximum distance to previous location. If there is no previous location (this is the first activity of the day), then the home location is considered as previous location. If the location falls outside of bounding box limits, try again.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_id
|
int
|
identifier of agent, used for random seed generation. |
required |
date
|
date
|
date, used for random seed generation. |
required |
activity_number
|
int
|
act position, used for random seed generation. |
required |
home_location
|
Tuple[float, float]
|
coordinates of home location. |
required |
previous_location
|
Tuple[float, float]
|
coordinates of previous location. |
required |
seed
|
int
|
random seed integer. Defaults to 6. |
6
|
Returns:
Type | Description |
---|---|
Tuple[float, float]
|
Tuple[float,float]: coordinates of generated location. |
Source code in multimno/components/ingestion/synthetic/synthetic_diaries.py
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 |
|
generate_stay_duration(agent_id, date, i, stay_type, remaining_time)
Generate stay duration probabilistically based on activity type abd remaining time.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_id
|
int
|
identifier of agent, used for random seed generation. |
required |
date
|
date
|
date, used for random seed generation. |
required |
i
|
int
|
activity position, used for random seed generation. |
required |
stay_type
|
str
|
type of stay. Shall be "home", "work" or "other". |
required |
remaining_time
|
float
|
same units as durations. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
generated activity duration. |
Source code in multimno/components/ingestion/synthetic/synthetic_diaries.py
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 |
|
generate_stay_location(stay_type, home_location, work_location, previous_location, user_id, date, i)
Generate a random activity location within the bounding box limits based on the activity type and previous activity locations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stay_type
|
str
|
type of stay ("home", "work" or "other"). |
required |
home_location
|
Tuple[float, float]
|
coordinates of home location. |
required |
work_location
|
Tuple[float, float]
|
coordinates of work location. |
required |
previous_location
|
Tuple[float, float]
|
coordinates of previous activity location. |
required |
user_id
|
int
|
agent identifier, used for random seed generation. |
required |
date
|
date
|
date, used for random seed generation. |
required |
i
|
int
|
activity position, used for random seed generation. |
required |
Returns:
Type | Description |
---|---|
Tuple[float, float]
|
Tuple[float,float]: randomly generated activity location coordinates. |
Source code in multimno/components/ingestion/synthetic/synthetic_diaries.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
|
generate_stay_type_sequence(agent_id, date)
Generate the sequence of stay types for an agent for a specific date probabilistically based on the superset sequence and specified probabilities. Replace 'home'-'home' and 'work'-'work' sequences by just 'home' or 'work'.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_id
|
int
|
identifier of agent, used for random seed generation. |
required |
date
|
date
|
date for activity sequence generation, used for random seed generation. |
required |
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: list of generated stay types, each represented by a string indicating the stay type (e.g. "home", "work", "other"). |
Source code in multimno/components/ingestion/synthetic/synthetic_diaries.py
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 |
|
generate_work_location(agent_id, home_location, seed=4)
Generate random work location based on home location and maximum distance to home. If the work location falls outside of bounding box limits, try again.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_id
|
int
|
identifier of agent, used for random seed generation. |
required |
home_location
|
Tuple[float, float]
|
coordinates of home location. |
required |
seed
|
int
|
random seed integer. Defaults to 4. |
4
|
Returns:
Type | Description |
---|---|
Tuple[float, float]
|
Tuple[float,float]: coordinates of generated work location. |
Source code in multimno/components/ingestion/synthetic/synthetic_diaries.py
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 |
|
haversine(lon1, lat1, lon2, lat2)
Calculate the haversine distance in meters between two points.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lon1
|
float
|
longitude of first point, in decimal degrees. |
required |
lat1
|
float
|
latitude of first point, in decimal degrees. |
required |
lon2
|
float
|
longitude of second point, in decimal degrees. |
required |
lat2
|
float
|
latitude of second point, in decimal degrees. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
distance between both points, in meters. |
Source code in multimno/components/ingestion/synthetic/synthetic_diaries.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
random_seed_number_generator(base_seed, agent_id=None, date=None, i=None)
Generate random seed integer based on provided arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base_seed
|
int
|
base integer for operations. |
required |
agent_id
|
int
|
agent identifier. Defaults to None. |
None
|
date
|
date
|
date. Defaults to None. |
None
|
i
|
int
|
position integer. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
generated random seed integer. |
Source code in multimno/components/ingestion/synthetic/synthetic_diaries.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
remove_consecutive_stay_types(stay_sequence_list, stay_types_to_group)
Generate new list replacing consecutive stays of the same type by a unique stay as long as the stay type is contained in the "stay_types_to_group" list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stay_sequence_list
|
List[str]
|
input stay type list. |
required |
stay_types_to_group
|
Set[str]
|
stay types to group. |
required |
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: output stay sequence list. |
Source code in multimno/components/ingestion/synthetic/synthetic_diaries.py
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 |
|
update_spark_row(row, column_name, new_value)
Return an updated spark row object, changing the value of a column.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
row
|
Row
|
input spark row. |
required |
column_name
|
str
|
name of column to modify. |
required |
new_value
|
Any
|
new value to assign. |
required |
Returns:
Name | Type | Description |
---|---|---|
Row |
Row
|
modified spark row |
Source code in multimno/components/ingestion/synthetic/synthetic_diaries.py
325 326 327 328 329 330 331 332 333 334 335 336 337 |
|