| Conditions | 1 |
| Total Lines | 367 |
| Code Lines | 252 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | """ |
||
| 271 | def add_metadata(): |
||
| 272 | """ |
||
| 273 | Add metadata to tables egon_ev_metadata, egon_ev_mv_grid_district, |
||
| 274 | egon_ev_trip in schema demand |
||
| 275 | """ |
||
| 276 | # egon_ev_metadata |
||
| 277 | schema = "demand" |
||
| 278 | meta_run_config = read_simbev_metadata_file("eGon100RE", "config").loc[ |
||
| 279 | "basic" |
||
| 280 | ] |
||
| 281 | |||
| 282 | contris = contributors(["kh", "kh"]) |
||
| 283 | |||
| 284 | contris[0]["date"] = "2023-03-17" |
||
| 285 | |||
| 286 | contris[0]["object"] = "metadata" |
||
| 287 | contris[1]["object"] = "dataset" |
||
| 288 | |||
| 289 | contris[0]["comment"] = "Add metadata to dataset." |
||
| 290 | contris[1]["comment"] = "Add workflow to generate dataset." |
||
| 291 | |||
| 292 | table = "egon_ev_metadata" |
||
| 293 | name = f"{schema}.{table}" |
||
| 294 | |||
| 295 | meta = { |
||
| 296 | "name": name, |
||
| 297 | "title": "eGon EV metadata", |
||
| 298 | "id": "WILL_BE_SET_AT_PUBLICATION", |
||
| 299 | "description": ( |
||
| 300 | "Metadata regarding the generation of EV trip profiles with SimBEV" |
||
| 301 | ), |
||
| 302 | "language": "en-US", |
||
| 303 | "keywords": ["ev", "mit", "simbev", "metadata", "parameters"], |
||
| 304 | "publicationDate": datetime.date.today().isoformat(), |
||
| 305 | "context": context(), |
||
| 306 | "spatial": { |
||
| 307 | "location": "none", |
||
| 308 | "extent": "none", |
||
| 309 | "resolution": "none", |
||
| 310 | }, |
||
| 311 | "temporal": { |
||
| 312 | "referenceDate": f"{meta_run_config.start_date}", |
||
| 313 | "timeseries": {}, |
||
| 314 | }, |
||
| 315 | "sources": [ |
||
| 316 | sources()["egon-data"], |
||
| 317 | { |
||
| 318 | "title": "SimBEV", |
||
| 319 | "description": ( |
||
| 320 | "Simulation of electric vehicle charging demand" |
||
| 321 | ), |
||
| 322 | "path": "https://github.com/rl-institut/simbev", |
||
| 323 | "licenses": [ |
||
| 324 | license_ccby(attribution="© Reiner Lemoine Institut") |
||
| 325 | ], |
||
| 326 | }, |
||
| 327 | { |
||
| 328 | "title": "SimBEV", |
||
| 329 | "description": ( |
||
| 330 | "Simulation of electric vehicle charging demand" |
||
| 331 | ), |
||
| 332 | "path": "https://github.com/rl-institut/simbev", |
||
| 333 | "licenses": [ |
||
| 334 | license_agpl(attribution="© Reiner Lemoine Institut") |
||
| 335 | ], |
||
| 336 | }, |
||
| 337 | ], |
||
| 338 | "licenses": [license_ccby()], |
||
| 339 | "contributors": contris, |
||
| 340 | "resources": [ |
||
| 341 | { |
||
| 342 | "profile": "tabular-data-resource", |
||
| 343 | "name": name, |
||
| 344 | "path": "None", |
||
| 345 | "format": "PostgreSQL", |
||
| 346 | "encoding": "UTF-8", |
||
| 347 | "schema": { |
||
| 348 | "fields": generate_resource_fields_from_db_table( |
||
| 349 | schema, |
||
| 350 | table, |
||
| 351 | ), |
||
| 352 | "primaryKey": "scenario", |
||
| 353 | }, |
||
| 354 | "dialect": {"delimiter": "", "decimalSeparator": ""}, |
||
| 355 | } |
||
| 356 | ], |
||
| 357 | "review": {"path": "", "badge": ""}, |
||
| 358 | "metaMetadata": meta_metadata(), |
||
| 359 | "_comment": { |
||
| 360 | "metadata": ( |
||
| 361 | "Metadata documentation and explanation (https://github." |
||
| 362 | "com/OpenEnergyPlatform/oemetadata/blob/master/metadata/" |
||
| 363 | "v141/metadata_key_description.md)" |
||
| 364 | ), |
||
| 365 | "dates": ( |
||
| 366 | "Dates and time must follow the ISO8601 including time " |
||
| 367 | "zone (YYYY-MM-DD or YYYY-MM-DDThh:mm:ss±hh)" |
||
| 368 | ), |
||
| 369 | "units": "Use a space between numbers and units (100 m)", |
||
| 370 | "languages": ( |
||
| 371 | "Languages must follow the IETF (BCP47) format (en-GB, " |
||
| 372 | "en-US, de-DE)" |
||
| 373 | ), |
||
| 374 | "licenses": ( |
||
| 375 | "License name must follow the SPDX License List " |
||
| 376 | "(https://spdx.org/licenses/)" |
||
| 377 | ), |
||
| 378 | "review": ( |
||
| 379 | "Following the OEP Data Review (https://github.com/" |
||
| 380 | "OpenEnergyPlatform/data-preprocessing/wiki)" |
||
| 381 | ), |
||
| 382 | "none": "If not applicable use (none)", |
||
| 383 | }, |
||
| 384 | } |
||
| 385 | |||
| 386 | dialect = get_dialect(oep_metadata_version())() |
||
| 387 | |||
| 388 | meta = dialect.compile_and_render(dialect.parse(json.dumps(meta))) |
||
| 389 | |||
| 390 | db.submit_comment( |
||
| 391 | f"'{json.dumps(meta)}'", |
||
| 392 | schema, |
||
| 393 | table, |
||
| 394 | ) |
||
| 395 | |||
| 396 | table = "egon_ev_mv_grid_district" |
||
| 397 | name = f"{schema}.{table}" |
||
| 398 | |||
| 399 | meta = { |
||
| 400 | "name": name, |
||
| 401 | "title": "eGon EV MV grid district", |
||
| 402 | "id": "WILL_BE_SET_AT_PUBLICATION", |
||
| 403 | "description": ("EV mapping to MV grids"), |
||
| 404 | "language": "en-US", |
||
| 405 | "keywords": ["ev", "mit", "simbev", "mv", "grid"], |
||
| 406 | "publicationDate": datetime.date.today().isoformat(), |
||
| 407 | "context": context(), |
||
| 408 | "spatial": { |
||
| 409 | "location": "none", |
||
| 410 | "extent": "Germany", |
||
| 411 | "resolution": "Grid district", |
||
| 412 | }, |
||
| 413 | "temporal": { |
||
| 414 | "referenceDate": f"{meta_run_config.start_date}", |
||
| 415 | "timeseries": {}, |
||
| 416 | }, |
||
| 417 | "sources": [ |
||
| 418 | sources()["bgr_inspee"], |
||
| 419 | sources()["bgr_inspeeds"], |
||
| 420 | sources()["bgr_inspeeds_data_bundle"], |
||
| 421 | sources()["bgr_inspeeds_report"], |
||
| 422 | sources()["demandregio"], |
||
| 423 | sources()["dsm-heitkoetter"], |
||
| 424 | sources()["egon-data"], |
||
| 425 | sources()["era5"], |
||
| 426 | sources()["hotmaps_industrial_sites"], |
||
| 427 | sources()["mastr"], |
||
| 428 | sources()["nep2021"], |
||
| 429 | sources()["openffe_gas"], |
||
| 430 | sources()["openstreetmap"], |
||
| 431 | sources()["peta"], |
||
| 432 | sources()["pipeline_classification"], |
||
| 433 | sources()["SciGRID_gas"], |
||
| 434 | sources()["schmidt"], |
||
| 435 | sources()["technology-data"], |
||
| 436 | sources()["tyndp"], |
||
| 437 | sources()["vg250"], |
||
| 438 | sources()["zensus"], |
||
| 439 | { |
||
| 440 | "title": "SimBEV", |
||
| 441 | "description": ( |
||
| 442 | "Simulation of electric vehicle charging demand" |
||
| 443 | ), |
||
| 444 | "path": "https://github.com/rl-institut/simbev", |
||
| 445 | "licenses": [ |
||
| 446 | license_ccby(attribution="© Reiner Lemoine Institut") |
||
| 447 | ], |
||
| 448 | }, |
||
| 449 | { |
||
| 450 | "title": "SimBEV", |
||
| 451 | "description": ( |
||
| 452 | "Simulation of electric vehicle charging demand" |
||
| 453 | ), |
||
| 454 | "path": "https://github.com/rl-institut/simbev", |
||
| 455 | "licenses": [ |
||
| 456 | license_agpl(attribution="© Reiner Lemoine Institut") |
||
| 457 | ], |
||
| 458 | }, |
||
| 459 | ], |
||
| 460 | "licenses": [license_odbl()], |
||
| 461 | "contributors": contris, |
||
| 462 | "resources": [ |
||
| 463 | { |
||
| 464 | "profile": "tabular-data-resource", |
||
| 465 | "name": name, |
||
| 466 | "path": "None", |
||
| 467 | "format": "PostgreSQL", |
||
| 468 | "encoding": "UTF-8", |
||
| 469 | "schema": { |
||
| 470 | "fields": generate_resource_fields_from_db_table( |
||
| 471 | schema, |
||
| 472 | table, |
||
| 473 | ), |
||
| 474 | "primaryKey": "id", |
||
| 475 | }, |
||
| 476 | "dialect": {"delimiter": "", "decimalSeparator": ""}, |
||
| 477 | } |
||
| 478 | ], |
||
| 479 | "review": {"path": "", "badge": ""}, |
||
| 480 | "metaMetadata": meta_metadata(), |
||
| 481 | "_comment": { |
||
| 482 | "metadata": ( |
||
| 483 | "Metadata documentation and explanation (https://github." |
||
| 484 | "com/OpenEnergyPlatform/oemetadata/blob/master/metadata/" |
||
| 485 | "v141/metadata_key_description.md)" |
||
| 486 | ), |
||
| 487 | "dates": ( |
||
| 488 | "Dates and time must follow the ISO8601 including time " |
||
| 489 | "zone (YYYY-MM-DD or YYYY-MM-DDThh:mm:ss±hh)" |
||
| 490 | ), |
||
| 491 | "units": "Use a space between numbers and units (100 m)", |
||
| 492 | "languages": ( |
||
| 493 | "Languages must follow the IETF (BCP47) format (en-GB, " |
||
| 494 | "en-US, de-DE)" |
||
| 495 | ), |
||
| 496 | "licenses": ( |
||
| 497 | "License name must follow the SPDX License List " |
||
| 498 | "(https://spdx.org/licenses/)" |
||
| 499 | ), |
||
| 500 | "review": ( |
||
| 501 | "Following the OEP Data Review (https://github.com/" |
||
| 502 | "OpenEnergyPlatform/data-preprocessing/wiki)" |
||
| 503 | ), |
||
| 504 | "none": "If not applicable use (none)", |
||
| 505 | }, |
||
| 506 | } |
||
| 507 | |||
| 508 | dialect = get_dialect(oep_metadata_version())() |
||
| 509 | |||
| 510 | meta = dialect.compile_and_render(dialect.parse(json.dumps(meta))) |
||
| 511 | |||
| 512 | db.submit_comment( |
||
| 513 | f"'{json.dumps(meta)}'", |
||
| 514 | schema, |
||
| 515 | table, |
||
| 516 | ) |
||
| 517 | |||
| 518 | table = "egon_ev_trip" |
||
| 519 | name = f"{schema}.{table}" |
||
| 520 | |||
| 521 | meta = { |
||
| 522 | "name": name, |
||
| 523 | "title": "eGon EV trip profiles", |
||
| 524 | "id": "WILL_BE_SET_AT_PUBLICATION", |
||
| 525 | "description": ("EV trip profiles generated with SimBEV"), |
||
| 526 | "language": "en-US", |
||
| 527 | "keywords": ["ev", "mit", "simbev", "trip", "profiles"], |
||
| 528 | "publicationDate": datetime.date.today().isoformat(), |
||
| 529 | "context": context(), |
||
| 530 | "spatial": { |
||
| 531 | "location": "none", |
||
| 532 | "extent": "Germany", |
||
| 533 | "resolution": "none", |
||
| 534 | }, |
||
| 535 | "temporal": { |
||
| 536 | "referenceDate": f"{meta_run_config.start_date}", |
||
| 537 | "timeseries": {}, |
||
| 538 | }, |
||
| 539 | "sources": [ |
||
| 540 | sources()["bgr_inspee"], |
||
| 541 | sources()["bgr_inspeeds"], |
||
| 542 | sources()["bgr_inspeeds_data_bundle"], |
||
| 543 | sources()["bgr_inspeeds_report"], |
||
| 544 | sources()["demandregio"], |
||
| 545 | sources()["dsm-heitkoetter"], |
||
| 546 | sources()["egon-data"], |
||
| 547 | sources()["era5"], |
||
| 548 | sources()["hotmaps_industrial_sites"], |
||
| 549 | sources()["mastr"], |
||
| 550 | sources()["nep2021"], |
||
| 551 | sources()["openffe_gas"], |
||
| 552 | sources()["openstreetmap"], |
||
| 553 | sources()["peta"], |
||
| 554 | sources()["pipeline_classification"], |
||
| 555 | sources()["SciGRID_gas"], |
||
| 556 | sources()["schmidt"], |
||
| 557 | sources()["technology-data"], |
||
| 558 | sources()["tyndp"], |
||
| 559 | sources()["vg250"], |
||
| 560 | sources()["zensus"], |
||
| 561 | { |
||
| 562 | "title": "SimBEV", |
||
| 563 | "description": ( |
||
| 564 | "Simulation of electric vehicle charging demand" |
||
| 565 | ), |
||
| 566 | "path": "https://github.com/rl-institut/simbev", |
||
| 567 | "licenses": [ |
||
| 568 | license_ccby(attribution="© Reiner Lemoine Institut") |
||
| 569 | ], |
||
| 570 | }, |
||
| 571 | { |
||
| 572 | "title": "SimBEV", |
||
| 573 | "description": ( |
||
| 574 | "Simulation of electric vehicle charging demand" |
||
| 575 | ), |
||
| 576 | "path": "https://github.com/rl-institut/simbev", |
||
| 577 | "licenses": [ |
||
| 578 | license_agpl(attribution="© Reiner Lemoine Institut") |
||
| 579 | ], |
||
| 580 | }, |
||
| 581 | ], |
||
| 582 | "licenses": [license_odbl()], |
||
| 583 | "contributors": contris, |
||
| 584 | "resources": [ |
||
| 585 | { |
||
| 586 | "profile": "tabular-data-resource", |
||
| 587 | "name": name, |
||
| 588 | "path": "None", |
||
| 589 | "format": "PostgreSQL", |
||
| 590 | "encoding": "UTF-8", |
||
| 591 | "schema": { |
||
| 592 | "fields": generate_resource_fields_from_db_table( |
||
| 593 | schema, |
||
| 594 | table, |
||
| 595 | ), |
||
| 596 | "primaryKey": ["scenario", "event_id"], |
||
| 597 | }, |
||
| 598 | "dialect": {"delimiter": "", "decimalSeparator": ""}, |
||
| 599 | } |
||
| 600 | ], |
||
| 601 | "review": {"path": "", "badge": ""}, |
||
| 602 | "metaMetadata": meta_metadata(), |
||
| 603 | "_comment": { |
||
| 604 | "metadata": ( |
||
| 605 | "Metadata documentation and explanation (https://github." |
||
| 606 | "com/OpenEnergyPlatform/oemetadata/blob/master/metadata/" |
||
| 607 | "v141/metadata_key_description.md)" |
||
| 608 | ), |
||
| 609 | "dates": ( |
||
| 610 | "Dates and time must follow the ISO8601 including time " |
||
| 611 | "zone (YYYY-MM-DD or YYYY-MM-DDThh:mm:ss±hh)" |
||
| 612 | ), |
||
| 613 | "units": "Use a space between numbers and units (100 m)", |
||
| 614 | "languages": ( |
||
| 615 | "Languages must follow the IETF (BCP47) format (en-GB, " |
||
| 616 | "en-US, de-DE)" |
||
| 617 | ), |
||
| 618 | "licenses": ( |
||
| 619 | "License name must follow the SPDX License List " |
||
| 620 | "(https://spdx.org/licenses/)" |
||
| 621 | ), |
||
| 622 | "review": ( |
||
| 623 | "Following the OEP Data Review (https://github.com/" |
||
| 624 | "OpenEnergyPlatform/data-preprocessing/wiki)" |
||
| 625 | ), |
||
| 626 | "none": "If not applicable use (none)", |
||
| 627 | }, |
||
| 628 | } |
||
| 629 | |||
| 630 | dialect = get_dialect(oep_metadata_version())() |
||
| 631 | |||
| 632 | meta = dialect.compile_and_render(dialect.parse(json.dumps(meta))) |
||
| 633 | |||
| 634 | db.submit_comment( |
||
| 635 | f"'{json.dumps(meta)}'", |
||
| 636 | schema, |
||
| 637 | table, |
||
| 638 | ) |
||
| 639 |