| Conditions | 13 | 
| Total Lines | 101 | 
| Code Lines | 83 | 
| 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 GridNavRetriever.GridNavRetriever.getNavBlk() 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 | import os | ||
| 154 | def getNavBlk(self): | ||
| 155 | """ Sends ThriftClient request and writes out received files.""" | ||
| 156 | req = GetGridNavRequest() | ||
| 157 | req.setPluginName(self.pluginName) | ||
| 158 | req.setModelId(self.modelId) | ||
| 159 | resp = self.client.sendRequest(req) | ||
| 160 | |||
| 161 | for i, rec in enumerate(resp): | ||
| 162 |             resp[i] = { | ||
| 163 | key.decode() if isinstance(key, bytes) else key: | ||
| 164 | val.decode() if isinstance(val, bytes) else val | ||
| 165 | for key, val in rec.items() | ||
| 166 | } | ||
| 167 | |||
| 168 | nav = [] | ||
| 169 | |||
| 170 | for record in resp: | ||
| 171 | unit = record['spacingunit'] | ||
| 172 | sk = record['spatialkey'] | ||
| 173 |             skarr = sk.split('/') | ||
| 174 | |||
| 175 | nx = float(skarr[1]) | ||
| 176 | ny = float(skarr[2]) | ||
| 177 | dx = float(skarr[3]) | ||
| 178 | dy = float(skarr[4]) | ||
| 179 | |||
| 180 | sc = StringConverter() | ||
| 181 | if record['projtype'] == 'LatLon': | ||
| 182 | sc.char = 'CED ' | ||
| 183 | gemproj = 2.0 | ||
| 184 | ang1 = 0.0 | ||
| 185 | ang2 = 0.0 | ||
| 186 | ang3 = 0.0 | ||
| 187 | |||
| 188 | lllat = float(record['lowerleftlat']) | ||
| 189 | lllon = float(record['lowerleftlon']) | ||
| 190 | urlat = lllat + (dy * (ny-1)) | ||
| 191 | urlon = lllon + (dx * (nx-1)) | ||
| 192 | if lllon > 180: | ||
| 193 | lllon -= 360.0 | ||
| 194 | if urlon > 180: | ||
| 195 | urlon -= 360.0 | ||
| 196 | |||
| 197 | if record['projtype'] == 'Polar Stereographic': | ||
| 198 | sc.char = 'STR ' | ||
| 199 | gemproj = 2.0 | ||
| 200 | if float(record['standard_parallel_1']) < 0.0: | ||
| 201 | ang1 = -90.0 | ||
| 202 | nsflag = 'S' | ||
| 203 | else: | ||
| 204 | ang1 = 90.0 | ||
| 205 | nsflag = 'N' | ||
| 206 | ang2 = float(record['central_meridian']) | ||
| 207 | ang3 = 0.0 | ||
| 208 | |||
| 209 | lat1 = float(record['lowerleftlat']) | ||
| 210 | lon1 = float(record['lowerleftlon']) | ||
| 211 | coords = createPolar(nsflag, ang2, lat1, lon1, dx, dy, unit, nx, ny) | ||
| 212 | lllat = coords[0] | ||
| 213 | lllon = coords[1] | ||
| 214 | urlat = coords[2] | ||
| 215 | urlon = coords[3] | ||
| 216 | |||
| 217 | if record['projtype'] == 'Lambert Conformal': | ||
| 218 | sc.char = 'LCC ' | ||
| 219 | gemproj = 2.0 | ||
| 220 | |||
| 221 | ang1 = float(skarr[7]) | ||
| 222 | ang2 = float(record['central_meridian']) | ||
| 223 | ang3 = float(skarr[8]) | ||
| 224 | if ang1 < 0.0: | ||
| 225 | nsflag = 'S' | ||
| 226 | else: | ||
| 227 | nsflag = 'N' | ||
| 228 | |||
| 229 | lat1 = float(record['lowerleftlat']) | ||
| 230 | lon1 = float(record['lowerleftlon']) | ||
| 231 | coords = createConic(nsflag, ang2, lat1, lon1, dx, dy, unit, nx, ny, ang1, ang3) | ||
| 232 | lllat = coords[0] | ||
| 233 | lllon = coords[1] | ||
| 234 | urlat = coords[2] | ||
| 235 | urlon = coords[3] | ||
| 236 | |||
| 237 | # Fill up the output array of floats | ||
| 238 | nav.append(gemproj) | ||
| 239 | nav.append(sc.float) | ||
| 240 | nav.append(1.0) | ||
| 241 | nav.append(1.0) | ||
| 242 | nav.append(nx) | ||
| 243 | nav.append(ny) | ||
| 244 | nav.append(lllat) | ||
| 245 | nav.append(lllon) | ||
| 246 | nav.append(urlat) | ||
| 247 | nav.append(urlon) | ||
| 248 | nav.append(ang1) | ||
| 249 | nav.append(ang2) | ||
| 250 | nav.append(ang3) | ||
| 251 | |||
| 252 | for i in range(13, int(self.arrayLen)): | ||
| 253 | nav.append(0.0) | ||
| 254 | return nav | ||
| 255 | |||
| 302 |