Conditions | 2 |
Total Lines | 65 |
Code Lines | 22 |
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 | ``settings['rsam']['enabled']`` ``True`` |
||
65 | ``settings['rsam']['debug']`` ``True`` |
||
66 | ======================================== =================== |
||
67 | |||
68 | .. note:: |
||
69 | |||
70 | If there is no internet connection detected, the station |
||
71 | name will default to ``'Z0000'`` so that no time is wasted |
||
72 | trying to download an inventory from the Raspberry Shake |
||
73 | FDSN service. |
||
74 | |||
75 | :param dict settings: settings dictionary (will be modified from :ref:`defaults`) |
||
76 | :param bool inet: whether or not the internet test passed |
||
77 | :rtype: dict |
||
78 | :return: settings dictionary to test with |
||
79 | ''' |
||
80 | settings = json.loads(settings) |
||
81 | |||
82 | settings['settings']['port'] = PORT |
||
83 | if inet: |
||
84 | settings['settings']['station'] = 'R24FA' |
||
85 | else: |
||
86 | settings['settings']['station'] = 'Z0000' |
||
87 | |||
88 | |||
89 | settings['alert']['threshold'] = 2 |
||
90 | settings['alert']['reset'] = 0.5 |
||
91 | settings['alert']['lowpass'] = 9 |
||
92 | settings['alert']['highpass'] = 0.8 |
||
93 | |||
94 | settings['plot']['channels'] = ['all'] |
||
95 | settings['plot']['duration'] = 60 |
||
96 | settings['plot']['deconvolve'] = True |
||
97 | settings['plot']['units'] = 'CHAN' |
||
98 | settings['plot']['eq_screenshots'] = True |
||
99 | |||
100 | settings['alertsound']['enabled'] = True |
||
101 | |||
102 | settings['rsam']['enabled'] = True |
||
103 | settings['rsam']['debug'] = True |
||
104 | settings['rsam']['interval'] = 5 |
||
105 | settings['rsam']['fwaddr'] = "127.0.0.1" |
||
106 | settings['rsam']['fwport'] = 4444 |
||
107 | |||
108 | return settings |
||
109 | |||
212 |