| Conditions | 8 |
| Total Lines | 68 |
| Code Lines | 60 |
| 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 | """Data Class for IMS Meteorological Readings.""" |
||
| 176 | channel_value[API_VALUE] |
||
| 177 | ) |
||
| 178 | |||
| 179 | rain = channel_value_dict.get(API_RAIN) |
||
| 180 | ws_max = channel_value_dict.get(API_WS_MAX) |
||
| 181 | wd_max = channel_value_dict.get(API_WD_MAX) |
||
| 182 | ws = channel_value_dict.get(API_WS) |
||
| 183 | wd = channel_value_dict.get(API_WD) |
||
| 184 | std_wd = channel_value_dict.get(API_STD_WD) |
||
| 185 | td = channel_value_dict.get(API_TD) |
||
| 186 | rh = channel_value_dict.get(API_RH) |
||
| 187 | td_max = channel_value_dict.get(API_TD_MAX) |
||
| 188 | td_min = channel_value_dict.get(API_TD_MIN) |
||
| 189 | ws_1mm = channel_value_dict.get(API_WS_1MM) |
||
| 190 | ws_10mm = channel_value_dict.get(API_WS_10MM) |
||
| 191 | tg = channel_value_dict.get(API_TG) |
||
| 192 | tw = channel_value_dict.get(API_TW) |
||
| 193 | time_val = channel_value_dict.get(API_TIME) |
||
| 194 | if time_val: |
||
| 195 | time_int = int(time_val) |
||
| 196 | if time_int <= MAX_HOUR_INT: |
||
| 197 | t = time.strptime(str(time_int), "%H") |
||
| 198 | else : |
||
| 199 | t = time.strptime(str(time_int), "%H%M") |
||
| 200 | time_val = datetime.time(t.tm_hour, t.tm_min, tzinfo=tz) |
||
| 201 | bp = channel_value_dict.get(API_BP) |
||
| 202 | diff_r = channel_value_dict.get(API_DIFF) |
||
| 203 | grad = channel_value_dict.get(API_GRAD) |
||
| 204 | nip = channel_value_dict.get(API_NIP) |
||
| 205 | rain_1_min = channel_value_dict.get(API_RAIN_1_MIN) |
||
| 206 | |||
| 207 | if is_dst and time_val: |
||
| 208 | # Strange IMS logic :o |
||
| 209 | dt = dt + datetime.timedelta(hours=1) |
||
| 210 | time_val = time_val.replace(hour=(time_val.hour+1)%24) |
||
| 211 | |||
| 212 | return MeteorologicalData( |
||
| 213 | station_id=station_id, |
||
| 214 | datetime=dt, |
||
| 215 | rain=rain, |
||
| 216 | ws=ws, |
||
| 217 | ws_max=ws_max, |
||
| 218 | wd=wd, |
||
| 219 | wd_max=wd_max, |
||
| 220 | std_wd=std_wd, |
||
| 221 | td=td, |
||
| 222 | td_max=td_max, |
||
| 223 | td_min=td_min, |
||
| 224 | tg=tg, |
||
| 225 | tw=tw, |
||
| 226 | rh=rh, |
||
| 227 | ws_1mm=ws_1mm, |
||
| 228 | ws_10mm=ws_10mm, |
||
| 229 | time=time_val, |
||
| 230 | bp=bp, |
||
| 231 | diff_r=diff_r, |
||
| 232 | grad=grad, |
||
| 233 | nip=nip, |
||
| 234 | rain_1_min=rain_1_min |
||
| 235 | ) |
||
| 236 | |||
| 237 | |||
| 238 | def station_meteo_data_from_json(json: dict) -> StationMeteorologicalReadings | None: |
||
| 239 | station_id = int(json[API_STATION_ID]) |
||
| 240 | data = json.get(API_DATA) |
||
| 241 | if not data: |
||
| 242 | return None |
||
| 243 | meteo_data = [meteo_data_from_json(station_id, single_meteo_data) for single_meteo_data in data] |
||
| 244 | return StationMeteorologicalReadings(station_id, meteo_data) |
||
| 245 |