| Conditions | 1 |
| Total Lines | 167 |
| Code Lines | 123 |
| 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 | """The central module containing all code dealing with heat supply data |
||
| 183 | def metadata(): |
||
| 184 | """Write metadata for heat supply tables |
||
| 185 | |||
| 186 | Returns |
||
| 187 | ------- |
||
| 188 | None. |
||
| 189 | |||
| 190 | """ |
||
| 191 | |||
| 192 | fields = generate_resource_fields_from_sqla_model( |
||
| 193 | EgonDistrictHeatingSupply |
||
| 194 | ) |
||
| 195 | |||
| 196 | fields_df = pd.DataFrame(data=fields).set_index("name") |
||
| 197 | fields_df.loc["index", "description"] = "Unique identifyer" |
||
| 198 | fields_df.loc[ |
||
| 199 | "district_heating_id", "description" |
||
| 200 | ] = "Index of the corresponding district heating grid" |
||
| 201 | fields_df.loc["carrier", "description"] = "Name of energy carrier" |
||
| 202 | fields_df.loc[ |
||
| 203 | "category", "description" |
||
| 204 | ] = "Size-category of district heating grid" |
||
| 205 | fields_df.loc["capacity", "description"] = "Installed heating capacity" |
||
| 206 | fields_df.loc[ |
||
| 207 | "geometry", "description" |
||
| 208 | ] = "Location of thermal power plant" |
||
| 209 | fields_df.loc["scenario", "description"] = "Name of corresponing scenario" |
||
| 210 | |||
| 211 | fields_df.loc["capacity", "unit"] = "MW_th" |
||
| 212 | fields_df.unit.fillna("none", inplace=True) |
||
| 213 | |||
| 214 | fields = fields_df.reset_index().to_dict(orient="records") |
||
| 215 | |||
| 216 | meta_district = { |
||
| 217 | "name": "supply.egon_district_heating", |
||
| 218 | "title": "eGon heat supply for district heating grids", |
||
| 219 | "id": "WILL_BE_SET_AT_PUBLICATION", |
||
| 220 | "description": "Heat supply technologies for district heating grids", |
||
| 221 | "language": ["EN"], |
||
| 222 | "publicationDate": datetime.date.today().isoformat(), |
||
| 223 | "context": context(), |
||
| 224 | "spatial": { |
||
| 225 | "location": None, |
||
| 226 | "extent": "Germany", |
||
| 227 | "resolution": None, |
||
| 228 | }, |
||
| 229 | "sources": [ |
||
| 230 | sources()["era5"], |
||
| 231 | sources()["vg250"], |
||
| 232 | sources()["egon-data"], |
||
| 233 | sources()["egon-data_bundle"], |
||
| 234 | sources()["openstreetmap"], |
||
| 235 | sources()["mastr"], |
||
| 236 | sources()["peta"], |
||
| 237 | ], |
||
| 238 | "licenses": [license_egon_data_odbl()], |
||
| 239 | "contributors": [ |
||
| 240 | { |
||
| 241 | "title": "Clara Büttner", |
||
| 242 | "email": "http://github.com/ClaraBuettner", |
||
| 243 | "date": time.strftime("%Y-%m-%d"), |
||
| 244 | "object": None, |
||
| 245 | "comment": "Imported data", |
||
| 246 | }, |
||
| 247 | ], |
||
| 248 | "resources": [ |
||
| 249 | { |
||
| 250 | "profile": "tabular-data-resource", |
||
| 251 | "name": "supply.egon_district_heating", |
||
| 252 | "path": None, |
||
| 253 | "format": "PostgreSQL", |
||
| 254 | "encoding": "UTF-8", |
||
| 255 | "schema": { |
||
| 256 | "fields": fields, |
||
| 257 | "primaryKey": ["index"], |
||
| 258 | "foreignKeys": [], |
||
| 259 | }, |
||
| 260 | "dialect": {"delimiter": None, "decimalSeparator": "."}, |
||
| 261 | } |
||
| 262 | ], |
||
| 263 | "metaMetadata": meta_metadata(), |
||
| 264 | } |
||
| 265 | |||
| 266 | # Add metadata as a comment to the table |
||
| 267 | db.submit_comment( |
||
| 268 | "'" + json.dumps(meta_district) + "'", |
||
| 269 | EgonDistrictHeatingSupply.__table__.schema, |
||
| 270 | EgonDistrictHeatingSupply.__table__.name, |
||
| 271 | ) |
||
| 272 | |||
| 273 | fields = generate_resource_fields_from_sqla_model( |
||
| 274 | EgonIndividualHeatingSupply |
||
| 275 | ) |
||
| 276 | |||
| 277 | fields_df = pd.DataFrame(data=fields).set_index("name") |
||
| 278 | fields_df.loc["index", "description"] = "Unique identifyer" |
||
| 279 | fields_df.loc[ |
||
| 280 | "mv_grid_id", "description" |
||
| 281 | ] = "Index of the corresponding mv grid district" |
||
| 282 | fields_df.loc["carrier", "description"] = "Name of energy carrier" |
||
| 283 | fields_df.loc["category", "description"] = "Size-category" |
||
| 284 | fields_df.loc["capacity", "description"] = "Installed heating capacity" |
||
| 285 | fields_df.loc[ |
||
| 286 | "geometry", "description" |
||
| 287 | ] = "Location of thermal power plant" |
||
| 288 | fields_df.loc["scenario", "description"] = "Name of corresponing scenario" |
||
| 289 | |||
| 290 | fields_df.loc["capacity", "unit"] = "MW_th" |
||
| 291 | fields_df.unit.fillna("none", inplace=True) |
||
| 292 | |||
| 293 | fields = fields_df.reset_index().to_dict(orient="records") |
||
| 294 | |||
| 295 | meta_district = { |
||
| 296 | "name": "supply.egon_individual_heating", |
||
| 297 | "title": "eGon heat supply for individual supplied buildings", |
||
| 298 | "id": "WILL_BE_SET_AT_PUBLICATION", |
||
| 299 | "description": "Heat supply technologies for individual supplied buildings", |
||
| 300 | "language": ["EN"], |
||
| 301 | "publicationDate": datetime.date.today().isoformat(), |
||
| 302 | "context": context(), |
||
| 303 | "spatial": { |
||
| 304 | "location": None, |
||
| 305 | "extent": "Germany", |
||
| 306 | "resolution": None, |
||
| 307 | }, |
||
| 308 | "sources": [ |
||
| 309 | sources()["era5"], |
||
| 310 | sources()["vg250"], |
||
| 311 | sources()["egon-data"], |
||
| 312 | sources()["egon-data_bundle"], |
||
| 313 | sources()["openstreetmap"], |
||
| 314 | sources()["mastr"], |
||
| 315 | sources()["peta"], |
||
| 316 | ], |
||
| 317 | "licenses": [license_egon_data_odbl()], |
||
| 318 | "contributors": [ |
||
| 319 | { |
||
| 320 | "title": "Clara Büttner", |
||
| 321 | "email": "http://github.com/ClaraBuettner", |
||
| 322 | "date": time.strftime("%Y-%m-%d"), |
||
| 323 | "object": None, |
||
| 324 | "comment": "Imported data", |
||
| 325 | }, |
||
| 326 | ], |
||
| 327 | "resources": [ |
||
| 328 | { |
||
| 329 | "profile": "tabular-data-resource", |
||
| 330 | "name": "supply.egon_individual_heating", |
||
| 331 | "path": None, |
||
| 332 | "format": "PostgreSQL", |
||
| 333 | "encoding": "UTF-8", |
||
| 334 | "schema": { |
||
| 335 | "fields": fields, |
||
| 336 | "primaryKey": ["index"], |
||
| 337 | "foreignKeys": [], |
||
| 338 | }, |
||
| 339 | "dialect": {"delimiter": None, "decimalSeparator": "."}, |
||
| 340 | } |
||
| 341 | ], |
||
| 342 | "metaMetadata": meta_metadata(), |
||
| 343 | } |
||
| 344 | |||
| 345 | # Add metadata as a comment to the table |
||
| 346 | db.submit_comment( |
||
| 347 | "'" + json.dumps(meta_district) + "'", |
||
| 348 | EgonIndividualHeatingSupply.__table__.schema, |
||
| 349 | EgonIndividualHeatingSupply.__table__.name, |
||
| 350 | ) |
||
| 398 |