Conditions | 1 |
Total Lines | 133 |
Code Lines | 85 |
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 | """ |
||
207 | def add_metadata(): |
||
208 | """ |
||
209 | Add metadata to table supply.egon_home_batteries |
||
210 | """ |
||
211 | targets = config.datasets()["home_batteries"]["targets"] |
||
212 | deposit_id_mastr = config.datasets()["mastr_new"]["deposit_id"] |
||
213 | deposit_id_data_bundle = config.datasets()["data-bundle"]["sources"][ |
||
214 | "zenodo" |
||
215 | ]["deposit_id"] |
||
216 | |||
217 | contris = contributors(["kh", "kh"]) |
||
218 | |||
219 | contris[0]["date"] = "2023-03-15" |
||
220 | |||
221 | contris[0]["object"] = "metadata" |
||
222 | contris[1]["object"] = "dataset" |
||
223 | |||
224 | contris[0]["comment"] = "Add metadata to dataset." |
||
225 | contris[1]["comment"] = "Add workflow to generate dataset." |
||
226 | |||
227 | meta = { |
||
228 | "name": ( |
||
229 | f"{targets['home_batteries']['schema']}." |
||
230 | f"{targets['home_batteries']['table']}" |
||
231 | ), |
||
232 | "title": "eGon Home Batteries", |
||
233 | "id": "WILL_BE_SET_AT_PUBLICATION", |
||
234 | "description": "Home storage systems allocated to buildings", |
||
235 | "language": "en-US", |
||
236 | "keywords": ["battery", "batteries", "home", "storage", "building"], |
||
237 | "publicationDate": datetime.date.today().isoformat(), |
||
238 | "context": context(), |
||
239 | "spatial": { |
||
240 | "location": "none", |
||
241 | "extent": "Germany", |
||
242 | "resolution": "building", |
||
243 | }, |
||
244 | "temporal": { |
||
245 | "referenceDate": "2021-12-31", |
||
246 | "timeseries": {}, |
||
247 | }, |
||
248 | "sources": [ |
||
249 | { |
||
250 | "title": "Data bundle for egon-data", |
||
251 | "description": ( |
||
252 | "Data bundle for egon-data: A transparent and " |
||
253 | "reproducible data processing pipeline for energy " |
||
254 | "system modeling" |
||
255 | ), |
||
256 | "path": ( |
||
257 | "https://zenodo.org/record/" |
||
258 | f"{deposit_id_data_bundle}#.Y_dWM4CZMVM" |
||
259 | ), |
||
260 | "licenses": [license_dedl(attribution="© Cußmann, Ilka")], |
||
261 | }, |
||
262 | { |
||
263 | "title": ("open-MaStR power unit registry for eGo^n project"), |
||
264 | "description": ( |
||
265 | "Data from Marktstammdatenregister (MaStR) data using " |
||
266 | "the data dump from 2022-11-17 for eGon-data." |
||
267 | ), |
||
268 | "path": ( |
||
269 | f"https://zenodo.org/record/{deposit_id_mastr}" |
||
270 | ), |
||
271 | "licenses": [license_dedl(attribution="© Amme, Jonathan")], |
||
272 | }, |
||
273 | sources()["openstreetmap"], |
||
274 | sources()["era5"], |
||
275 | sources()["vg250"], |
||
276 | sources()["egon-data"], |
||
277 | sources()["nep2021"], |
||
278 | sources()["mastr"], |
||
279 | sources()["technology-data"], |
||
280 | ], |
||
281 | "licenses": [license_odbl("© eGon development team")], |
||
282 | "contributors": contris, |
||
283 | "resources": [ |
||
284 | { |
||
285 | "profile": "tabular-data-resource", |
||
286 | "name": ( |
||
287 | f"{targets['home_batteries']['schema']}." |
||
288 | f"{targets['home_batteries']['table']}" |
||
289 | ), |
||
290 | "path": "None", |
||
291 | "format": "PostgreSQL", |
||
292 | "encoding": "UTF-8", |
||
293 | "schema": { |
||
294 | "fields": generate_resource_fields_from_db_table( |
||
295 | targets["home_batteries"]["schema"], |
||
296 | targets["home_batteries"]["table"], |
||
297 | ), |
||
298 | "primaryKey": "index", |
||
299 | }, |
||
300 | "dialect": {"delimiter": "", "decimalSeparator": ""}, |
||
301 | } |
||
302 | ], |
||
303 | "review": {"path": "", "badge": ""}, |
||
304 | "metaMetadata": meta_metadata(), |
||
305 | "_comment": { |
||
306 | "metadata": ( |
||
307 | "Metadata documentation and explanation (https://github.com/" |
||
308 | "OpenEnergyPlatform/oemetadata/blob/master/metadata/v141/" |
||
309 | "metadata_key_description.md)" |
||
310 | ), |
||
311 | "dates": ( |
||
312 | "Dates and time must follow the ISO8601 including time zone " |
||
313 | "(YYYY-MM-DD or YYYY-MM-DDThh:mm:ss±hh)" |
||
314 | ), |
||
315 | "units": "Use a space between numbers and units (100 m)", |
||
316 | "languages": ( |
||
317 | "Languages must follow the IETF (BCP47) format (en-GB, en-US, " |
||
318 | "de-DE)" |
||
319 | ), |
||
320 | "licenses": ( |
||
321 | "License name must follow the SPDX License List " |
||
322 | "(https://spdx.org/licenses/)" |
||
323 | ), |
||
324 | "review": ( |
||
325 | "Following the OEP Data Review (https://github.com/" |
||
326 | "OpenEnergyPlatform/data-preprocessing/wiki)" |
||
327 | ), |
||
328 | "none": "If not applicable use (none)", |
||
329 | }, |
||
330 | } |
||
331 | |||
332 | dialect = get_dialect(meta_metadata())() |
||
333 | |||
334 | meta = dialect.compile_and_render(dialect.parse(json.dumps(meta))) |
||
335 | |||
336 | db.submit_comment( |
||
337 | f"'{json.dumps(meta)}'", |
||
338 | targets["home_batteries"]["schema"], |
||
339 | targets["home_batteries"]["table"], |
||
340 | ) |
||
357 |