Conditions | 6 |
Total Lines | 52 |
Code Lines | 41 |
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 | import os |
||
17 | def getStations(self): |
||
18 | """ Sends ThriftClient request and writes out received files.""" |
||
19 | req = GetStationsRequest() |
||
20 | req.setPluginName(self.pluginName) |
||
21 | resp = self.client.sendRequest(req) |
||
22 | |||
23 | stns = [] |
||
24 | for item in resp: |
||
25 | stationstr = '{:<8}'.format(item.getStationId()) |
||
26 | |||
27 | if sys.byteorder == 'little': |
||
28 | stnid = (ord(stationstr[3]) << 24) + (ord(stationstr[2]) << 16) + \ |
||
29 | (ord(stationstr[1]) << 8) + ord(stationstr[0]) |
||
30 | stnid2 = (ord(stationstr[7]) << 24) + (ord(stationstr[6]) << 16) + \ |
||
31 | (ord(stationstr[5]) << 8) + ord(stationstr[4]) |
||
32 | else: |
||
33 | stnid = (ord(stationstr[0]) << 24) + (ord(stationstr[1]) << 16) + \ |
||
34 | (ord(stationstr[2]) << 8) + ord(stationstr[3]) |
||
35 | stnid2 = (ord(stationstr[4]) << 24) + (ord(stationstr[5]) << 16) + \ |
||
36 | (ord(stationstr[6]) << 8) + ord(stationstr[7]) |
||
37 | |||
38 | if item.getState() is None: |
||
39 | stationstr = ' ' |
||
40 | else: |
||
41 | stationstr = '{:<4}'.format(item.getState()) |
||
42 | |||
43 | if sys.byteorder == 'little': |
||
44 | state = (ord(stationstr[3]) << 24) + (ord(stationstr[2]) << 16) \ |
||
45 | + (ord(stationstr[1]) << 8) + ord(stationstr[0]) |
||
46 | else: |
||
47 | state = (ord(stationstr[0]) << 24) + (ord(stationstr[1]) << 16) \ |
||
48 | + (ord(stationstr[2]) << 8) + ord(stationstr[3]) |
||
49 | |||
50 | stationstr = '{:<4}'.format(item.getCountry()) |
||
51 | if sys.byteorder == 'little': |
||
52 | cntry = (ord(stationstr[3]) << 24) + (ord(stationstr[2]) << 16) \ |
||
53 | + (ord(stationstr[1]) << 8) + ord(stationstr[0]) |
||
54 | else: |
||
55 | cntry = (ord(stationstr[0]) << 24) + (ord(stationstr[1]) << 16) \ |
||
56 | + (ord(stationstr[2]) << 8) + ord(stationstr[3]) |
||
57 | |||
58 | stns.append(9999) |
||
59 | stns.append(stnid) |
||
60 | stns.append(item.getWmoIndex()) |
||
61 | stns.append(int(item.getLatitude()*100)) |
||
62 | stns.append(int(item.getLongitude()*100)) |
||
63 | stns.append(int(item.getElevation())) |
||
64 | stns.append(state) |
||
65 | stns.append(cntry) |
||
66 | stns.append(stnid2) |
||
67 | stns.append(0) |
||
68 | return stns |
||
69 | |||
87 |