| Conditions | 10 |
| Total Lines | 94 |
| Code Lines | 78 |
| 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 | nav = [] |
||
| 162 | |||
| 163 | for record in resp: |
||
| 164 | unit = record['spacingunit'] |
||
| 165 | sk = record['spatialkey'] |
||
| 166 | skarr = sk.split('/') |
||
| 167 | |||
| 168 | nx = float(skarr[1]) |
||
| 169 | ny = float(skarr[2]) |
||
| 170 | dx = float(skarr[3]) |
||
| 171 | dy = float(skarr[4]) |
||
| 172 | |||
| 173 | sc = StringConverter() |
||
| 174 | if record['projtype'] == 'LatLon': |
||
| 175 | sc.char = 'CED ' |
||
| 176 | gemproj = 2.0 |
||
| 177 | ang1 = 0.0 |
||
| 178 | ang2 = 0.0 |
||
| 179 | ang3 = 0.0 |
||
| 180 | |||
| 181 | lllat = float(record['lowerleftlat']) |
||
| 182 | lllon = float(record['lowerleftlon']) |
||
| 183 | urlat = lllat + (dy * (ny-1)) |
||
| 184 | urlon = lllon + (dx * (nx-1)) |
||
| 185 | if lllon > 180: |
||
| 186 | lllon -= 360.0 |
||
| 187 | if urlon > 180: |
||
| 188 | urlon -= 360.0 |
||
| 189 | |||
| 190 | if record['projtype'] == 'Polar Stereographic': |
||
| 191 | sc.char = 'STR ' |
||
| 192 | gemproj = 2.0 |
||
| 193 | if float(record['standard_parallel_1']) < 0.0: |
||
| 194 | ang1 = -90.0 |
||
| 195 | nsflag = 'S' |
||
| 196 | else: |
||
| 197 | ang1 = 90.0 |
||
| 198 | nsflag = 'N' |
||
| 199 | ang2 = float(record['central_meridian']) |
||
| 200 | ang3 = 0.0 |
||
| 201 | |||
| 202 | lat1 = float(record['lowerleftlat']) |
||
| 203 | lon1 = float(record['lowerleftlon']) |
||
| 204 | coords = createPolar(nsflag, ang2, lat1, lon1, dx, dy, unit, nx, ny) |
||
| 205 | lllat = coords[0] |
||
| 206 | lllon = coords[1] |
||
| 207 | urlat = coords[2] |
||
| 208 | urlon = coords[3] |
||
| 209 | |||
| 210 | if record['projtype'] == 'Lambert Conformal': |
||
| 211 | sc.char = 'LCC ' |
||
| 212 | gemproj = 2.0 |
||
| 213 | |||
| 214 | ang1 = float(skarr[7]) |
||
| 215 | ang2 = float(record['central_meridian']) |
||
| 216 | ang3 = float(skarr[8]) |
||
| 217 | if ang1 < 0.0: |
||
| 218 | nsflag = 'S' |
||
| 219 | else: |
||
| 220 | nsflag = 'N' |
||
| 221 | |||
| 222 | lat1 = float(record['lowerleftlat']) |
||
| 223 | lon1 = float(record['lowerleftlon']) |
||
| 224 | coords = createConic(nsflag, ang2, lat1, lon1, dx, dy, unit, nx, ny, ang1, ang3) |
||
| 225 | lllat = coords[0] |
||
| 226 | lllon = coords[1] |
||
| 227 | urlat = coords[2] |
||
| 228 | urlon = coords[3] |
||
| 229 | |||
| 230 | # Fill up the output array of floats |
||
| 231 | nav.append(gemproj) |
||
| 232 | nav.append(sc.float) |
||
| 233 | nav.append(1.0) |
||
| 234 | nav.append(1.0) |
||
| 235 | nav.append(nx) |
||
| 236 | nav.append(ny) |
||
| 237 | nav.append(lllat) |
||
| 238 | nav.append(lllon) |
||
| 239 | nav.append(urlat) |
||
| 240 | nav.append(urlon) |
||
| 241 | nav.append(ang1) |
||
| 242 | nav.append(ang2) |
||
| 243 | nav.append(ang3) |
||
| 244 | |||
| 245 | for i in range(13, int(self.arrayLen)): |
||
| 246 | nav.append(0.0) |
||
| 247 | return nav |
||
| 248 | |||
| 295 |