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