| Conditions | 2 |
| Total Lines | 71 |
| Code Lines | 56 |
| 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 | """Import MaStR dataset and write to DB tables""" |
||
| 13 | def import_mastr(): |
||
| 14 | cfg = egon.data.config.datasets()["power_plants"] |
||
| 15 | |||
| 16 | cols_mapping = { |
||
| 17 | "all": { |
||
| 18 | "EinheitMastrNummer": "gens_id", |
||
| 19 | "EinheitBetriebsstatus": "status", |
||
| 20 | "Inbetriebnahmedatum": "commissioning_date", |
||
| 21 | "Postleitzahl": "postcode", |
||
| 22 | "Ort": "city", |
||
| 23 | "Bundesland": "federal_state", |
||
| 24 | "Nettonennleistung": "capacity", |
||
| 25 | "Einspeisungsart": "feedin_type", |
||
| 26 | }, |
||
| 27 | "pv": { |
||
| 28 | "Lage": "site_type", |
||
| 29 | "Nutzungsbereich": "usage_sector", |
||
| 30 | "Hauptausrichtung": "orientation_primary", |
||
| 31 | "HauptausrichtungNeigungswinkel": "orientation_primary_angle", |
||
| 32 | "Nebenausrichtung": "orientation_secondary", |
||
| 33 | "NebenausrichtungNeigungswinkel": "orientation_secondary_angle", |
||
| 34 | "EinheitlicheAusrichtungUndNeigungswinkel": "orientation_uniform", |
||
| 35 | "AnzahlModule": "module_count", |
||
| 36 | "ZugeordneteWirkleistungWechselrichter": "capacity_inverter", |
||
| 37 | }, |
||
| 38 | "wind": { |
||
| 39 | "Lage": "site_type", |
||
| 40 | "Hersteller": "manufacturer_name", |
||
| 41 | "Typenbezeichnung": "type_name", |
||
| 42 | "Nabenhoehe": "hub_height", |
||
| 43 | "Rotordurchmesser": "rotor_diameter", |
||
| 44 | }, |
||
| 45 | "biomass": { |
||
| 46 | "Technologie": "technology", |
||
| 47 | "Hauptbrennstoff": "fuel_name", |
||
| 48 | "Biomasseart": "fuel_type", |
||
| 49 | "ThermischeNutzleistung": "th_capacity", |
||
| 50 | }, |
||
| 51 | "hydro": { |
||
| 52 | "ArtDerWasserkraftanlage": "type", |
||
| 53 | "ArtDesZuflusses": "water_origin", |
||
| 54 | }, |
||
| 55 | } |
||
| 56 | |||
| 57 | source_files = { |
||
| 58 | "pv": cfg["sources"]["mastr_pv"], |
||
| 59 | "wind": cfg["sources"]["mastr_wind"], |
||
| 60 | "biomass": cfg["sources"]["mastr_biomass"], |
||
| 61 | "hydro": cfg["sources"]["mastr_hydro"], |
||
| 62 | } |
||
| 63 | target_tables = { |
||
| 64 | "pv": EgonPowerPlantsPv, |
||
| 65 | "wind": EgonPowerPlantsWind, |
||
| 66 | "biomass": EgonPowerPlantsBiomass, |
||
| 67 | "hydro": EgonPowerPlantsHydro, |
||
| 68 | } |
||
| 69 | |||
| 70 | # import locations |
||
| 71 | locations = pd.read_csv(cfg["sources"]["mastr_location"], index_col=None) |
||
| 72 | |||
| 73 | # import units |
||
| 74 | technologies = ["pv", "wind", "biomass", "hydro"] |
||
| 75 | for tech in technologies: |
||
| 76 | units = pd.read_csv( |
||
| 77 | source_files[tech], |
||
| 78 | usecols=( |
||
| 79 | list(cols_mapping["all"].keys()) |
||
| 80 | + list(cols_mapping[tech].keys()) |
||
| 81 | ), |
||
| 82 | index_col=None, |
||
| 83 | ).rename(columns=cols_mapping) |
||
| 84 |