| Conditions | 7 |
| Total Lines | 62 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 | """ |
||
| 23 | def default(self, o, sort_keys=True): |
||
| 24 | if isinstance(o, datetime): |
||
| 25 | return { |
||
| 26 | '__type__': 'datetime', |
||
| 27 | 'year': o.year, |
||
| 28 | 'month': o.month, |
||
| 29 | 'day': o.day, |
||
| 30 | 'hour': o.hour, |
||
| 31 | 'minute': o.minute, |
||
| 32 | 'second': o.second, |
||
| 33 | 'microsecond': o.microsecond |
||
| 34 | } |
||
| 35 | elif isinstance(o, ua.NodeId): |
||
| 36 | return { |
||
| 37 | '__type__': 'NodeId', |
||
| 38 | 'Identifier': str(o.Identifier), |
||
| 39 | 'NamespaceIndex': str(o.NamespaceIndex), |
||
| 40 | 'NamespaceUri': o.NamespaceUri, |
||
| 41 | 'NodeIdType': o.NodeIdType.name, |
||
| 42 | |||
| 43 | } |
||
| 44 | elif isinstance(o, Node): |
||
| 45 | return { |
||
| 46 | '__type__': 'Node', |
||
| 47 | 'NodeId': str(o.nodeid), |
||
| 48 | 'BrowseName': o.get_browse_name().Name, |
||
| 49 | 'DisplayName': o.get_display_name().Text.decode(encoding='UTF-8'), |
||
| 50 | } |
||
| 51 | elif isinstance(o, ua.DataValue): |
||
| 52 | return { |
||
| 53 | '__type__': 'DataValue', |
||
| 54 | 'ServerTimestamp': o.ServerTimestamp.isoformat(' '), |
||
| 55 | 'SourceTimestamp': o.SourceTimestamp.isoformat(' '), |
||
| 56 | 'StatusCode': o.StatusCode.name, |
||
| 57 | 'VariantType': o.Value.VariantType.name, |
||
| 58 | 'Value': str(o.Value.Value), |
||
| 59 | } |
||
| 60 | elif isinstance(o, DataChangeNotif): |
||
| 61 | return { |
||
| 62 | '__type__': 'DataChangeNotif', |
||
| 63 | 'Node': str(o.subscription_data.node.nodeid), |
||
| 64 | 'DisplayName': o.subscription_data.node.get_display_name().Text.decode(encoding='UTF-8'), |
||
| 65 | 'ServerTimestamp': o.monitored_item.Value.ServerTimestamp.isoformat(' '), |
||
| 66 | 'SourceTimestamp': o.monitored_item.Value.SourceTimestamp.isoformat(' '), |
||
| 67 | 'StatusCode': o.monitored_item.Value.StatusCode.name, |
||
| 68 | 'VariantType': o.monitored_item.Value.Value.VariantType.name, |
||
| 69 | 'Value': str(o.monitored_item.Value.Value.Value), |
||
| 70 | } |
||
| 71 | elif isinstance(o, Event): |
||
| 72 | return { |
||
| 73 | '__type__': 'Event', |
||
| 74 | 'SourceNode': str(o.SourceNode), |
||
| 75 | 'EventId': o.EventId, |
||
| 76 | 'EventType': str(o.EventType), |
||
| 77 | 'LocalTime': o.LocalTime.isoformat(' '), |
||
| 78 | 'ReceiveTime': o.ReceiveTime.isoformat(' '), |
||
| 79 | 'Time': o.Time.isoformat(' '), |
||
| 80 | 'Severity': str(o.Severity), |
||
| 81 | 'Message': o.Message.Text.decode(encoding='UTF-8'), |
||
| 82 | } |
||
| 83 | else: |
||
| 84 | return JSONEncoder.default(self, o) |
||
| 85 | |||
| 138 |