| Conditions | 2 |
| Total Lines | 57 |
| Code Lines | 17 |
| 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, sys |
||
| 44 | def make_test_settings(settings, inet=False): |
||
| 45 | ''' |
||
| 46 | Get the default settings and return settings for testing. |
||
| 47 | |||
| 48 | The default settings are modified in the following way: |
||
| 49 | |||
| 50 | ======================================== =================== |
||
| 51 | Setting Value |
||
| 52 | ======================================== =================== |
||
| 53 | ``settings['settings']['station']`` ``'R24FA'`` |
||
| 54 | ``settings['alert']['threshold']`` ``2`` |
||
| 55 | ``settings['alert']['reset']`` ``0.5`` |
||
| 56 | ``settings['alert']['lowpass']`` ``9`` |
||
| 57 | ``settings['alert']['highpass']`` ``0.8`` |
||
| 58 | ``settings['plot']['channels']`` ``['all']`` |
||
| 59 | ``settings['plot']['duration']`` ``60`` |
||
| 60 | ``settings['plot']['deconvolve']`` ``True`` |
||
| 61 | ``settings['plot']['units']`` ``'CHAN'`` |
||
| 62 | ``settings['plot']['eq_screenshots']`` ``True`` |
||
| 63 | ``settings['alertsound']['enabled']`` ``True`` |
||
| 64 | ======================================== =================== |
||
| 65 | |||
| 66 | .. note:: |
||
| 67 | |||
| 68 | If there is no internet connection detected, the station |
||
| 69 | name will default to ``'Z0000'`` so that no time is wasted |
||
| 70 | trying to download an inventory from the Raspberry Shake |
||
| 71 | FDSN service. |
||
| 72 | |||
| 73 | :param dict settings: settings dictionary (will be modified from :ref:`defaults`) |
||
| 74 | :param bool inet: whether or not the internet test passed |
||
| 75 | :rtype: dict |
||
| 76 | :return: settings dictionary to test with |
||
| 77 | ''' |
||
| 78 | settings = json.loads(settings) |
||
| 79 | |||
| 80 | settings['settings']['port'] = PORT |
||
| 81 | if inet: |
||
| 82 | settings['settings']['station'] = 'R24FA' |
||
| 83 | else: |
||
| 84 | settings['settings']['station'] = 'Z0000' |
||
| 85 | |||
| 86 | |||
| 87 | settings['alert']['threshold'] = 2 |
||
| 88 | settings['alert']['reset'] = 0.5 |
||
| 89 | settings['alert']['lowpass'] = 9 |
||
| 90 | settings['alert']['highpass'] = 0.8 |
||
| 91 | |||
| 92 | settings['plot']['channels'] = ['all'] |
||
| 93 | settings['plot']['duration'] = 60 |
||
| 94 | settings['plot']['deconvolve'] = True |
||
| 95 | settings['plot']['units'] = 'CHAN' |
||
| 96 | settings['plot']['eq_screenshots'] = True |
||
| 97 | |||
| 98 | settings['alertsound']['enabled'] = True |
||
| 99 | |||
| 100 | return settings |
||
| 101 | |||
| 202 |