| Conditions | 14 | 
| Total Lines | 107 | 
| Code Lines | 57 | 
| 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:
Complex classes like zooma.helpers.useZooma() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | #!/usr/bin/env python3 | ||
| 48 | result["confidence"].lower()) | ||
| 49 | |||
| 50 | model.confidence = confidence | ||
| 51 | model.save() | ||
| 52 | |||
| 53 | |||
| 54 | def annotate_country(country_obj): | ||
| 55 | """Annotate a country object using Zooma""" | ||
| 56 | |||
| 57 | annotate_generic(country_obj, "country") | ||
| 58 | |||
| 59 | |||
| 60 | def annotate_breed(breed_obj): | ||
| 61 | """Annotate a breed object using Zooma""" | ||
| 62 | |||
| 63 |     logger.debug("Processing %s" % (breed_obj)) | ||
| 64 | |||
| 65 | result = use_zooma( | ||
| 66 | breed_obj.supplied_breed, "breed") | ||
| 67 | |||
| 68 | # update object (if possible) | ||
| 69 | if result: | ||
| 70 | url = result['ontologyTerms'] | ||
| 71 | # https://stackoverflow.com/a/7253830 | ||
| 72 |         term = url.rsplit('/', 1)[-1] | ||
| 73 | |||
| 74 | # The ontology seems correct. Annotate! | ||
| 75 |         logger.info("Updating %s with %s" % (breed_obj, result)) | ||
| 76 | url = result['ontologyTerms'] | ||
| 77 | |||
| 78 | # this is slight different from annotate_generic | ||
| 79 | breed_obj.mapped_breed_term = term | ||
| 80 | breed_obj.mapped_breed = result['text'] | ||
| 81 | |||
| 82 | # get an int object for such confidence | ||
| 83 | confidence = CONFIDENCES.get_value( | ||
| 84 | result["confidence"].lower()) | ||
| 85 | |||
| 86 | breed_obj.confidence = confidence | ||
| 87 | breed_obj.save() | ||
| 88 | |||
| 89 | |||
| 90 | def annotate_specie(specie_obj): | ||
| 91 | """Annotate a specie object using Zooma""" | ||
| 92 | |||
| 93 | annotate_generic(specie_obj, "species") | ||
| 94 | |||
| 95 | |||
| 96 | def annotate_organismpart(uberon_obj): | ||
| 97 | """Annotate an organism part object using Zooma""" | ||
| 98 | |||
| 99 | annotate_generic(uberon_obj, "organism part") | ||
| 100 | |||
| 101 | |||
| 102 | def annotate_develstage(dictdevelstage_obj): | ||
| 103 | """Annotate an developmental stage part object using Zooma""" | ||
| 104 | |||
| 105 | annotate_generic(dictdevelstage_obj, "developmental stage") | ||
| 106 | |||
| 107 | |||
| 108 | def annotate_physiostage(dictphysiostage_obj): | ||
| 109 | """Annotate an physiological stage object using Zooma""" | ||
| 110 | |||
| 111 | annotate_generic(dictphysiostage_obj, "physiological stage") | ||
| 112 |