Skip to content

Commit 1aa25e4

Browse files
lwalter86scls19fr
authored andcommitted
pep8 fixes (#16)
1 parent 56163d0 commit 1aa25e4

13 files changed

+113
-82
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,6 @@ docs/_build/
5555

5656
# PyBuilder
5757
target/
58+
59+
# VisualStudio Code
60+
.vscode

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ install:
1616
# command to run tests
1717
script:
1818
- flake8 --version
19-
- flake8 numpy_buffer samples test
19+
- flake8 --ignore E501 numpy_buffer samples test
2020
- nosetests

numpy_buffer/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env python
22

3-
from .ring import RingBuffer
3+
from .ring import RingBuffer # noqa

numpy_buffer/ring.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import numpy as np
44

5+
56
class RingBuffer(object):
67
def __init__(self, size_max, default_value=0.0, dtype=float, overflow=None):
78
"""initialization"""
@@ -28,23 +29,23 @@ def clear(self, size_max=None, default_value=None, dtype=None, overflow=None):
2829
if len(default_value) == size_max:
2930
self._data = default_value
3031
else:
31-
raise(NotImplementedError("len(default_value)=%d but size_max=%d",
32-
" but they should be equal" % (len(default_value), size_max)))
32+
msg = "len(default_value)=%d but size_max=%d, but they should be equal" % (len(default_value), size_max)
33+
raise NotImplementedError(msg)
3334

3435
self.size = 0
35-
36+
3637
self.full = False
37-
self.append = self._append_not_full
38+
self.append = self._append_not_full
3839

3940
def _append_not_full(self, value):
4041
"""append an element"""
4142
self._data = np.roll(self._data, 1)
42-
self._data[0] = value
43+
self._data[0] = value
4344

4445
self.size += 1
45-
46+
4647
if self.size == self.size_max:
47-
self.full = True
48+
self.full = True
4849
self.append = self._append_full
4950
self.overflow = self.overflow(self)
5051

@@ -53,20 +54,19 @@ def _append_full(self, value):
5354
self._data = np.roll(self._data, 1)
5455
self._data[0] = value
5556

56-
5757
@property
5858
def all(self):
5959
"""return a list of elements from the oldest to the newest (len: size_max)"""
6060
return self._data
61-
61+
6262
@property
6363
def partial(self):
6464
"""return a list of elements from the oldest to the newest (len: size)"""
6565
return self.all[0:self.size]
6666

6767
def view(self, *args, **kwargs):
6868
return self.partial[::-1].view(*args, **kwargs)
69-
69+
7070
def __len__(self):
7171
"""return size (not size_max)"""
7272
return self.size
@@ -81,11 +81,10 @@ def __repr__(self):
8181
all: %s
8282
partial: %s
8383
size/size_max: %d / %d
84-
>""" % (self.__class__.__name__,
85-
self.all.__repr__(),
86-
self.partial.__repr__(),
87-
self.size, self.size_max
88-
)
84+
>""" % (self.__class__.__name__,
85+
self.all.__repr__(),
86+
self.partial.__repr__(),
87+
self.size, self.size_max)
8988
return s
9089

9190
def overflow(self, *args, **kwargs):

samples/mqtt_publish.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
11
#!/usr/bin/env python
2-
2+
33
import mosquitto
44
from mqtt_settings import config
5-
import time
65
import datetime
76
import pytz
87
import numpy as np
98
import json
109

10+
1111
def on_message(mosq, obj, msg):
1212
print("%-20s %d %s" % (msg.topic, msg.qos, msg.payload))
1313
mosq.publish('pong', "Thanks", 0)
14-
14+
15+
1516
def on_publish(mosq, obj, mid):
1617
print("publish %s %s %s" % (mosq, obj, mid))
1718

19+
1820
def main():
1921
cli = mosquitto.Mosquitto()
2022
cli.on_message = on_message
2123
cli.on_publish = on_publish
2224

23-
#cli.tls_set('root.ca',
24-
#certfile='c1.crt',
25-
#keyfile='c1.key')
25+
# cli.tls_set('root.ca',
26+
# certfile='c1.crt',
27+
# keyfile='c1.key')
2628

27-
#cli.username_pw_set("guigui", password="abloc")
29+
# cli.username_pw_set("guigui", password="abloc")
2830

2931
cli.connect(config['host'], config['port'], config['keepalive'])
30-
31-
y = 100 # initial value
32+
33+
y = 100 # initial value
3234

3335
while cli.loop() == 0:
3436
now = datetime.datetime.now(pytz.utc)
@@ -39,10 +41,9 @@ def main():
3941
'y': y
4042
}
4143
}
42-
payload = json.dumps(data) # serialization
44+
payload = json.dumps(data) # serialization
4345
cli.publish(topic='/sensors/sensor01', payload=payload, qos=0, retain=False)
44-
#time.sleep(1)
45-
#print("wait")
46+
4647

4748
if __name__ == '__main__':
4849
main()

samples/mqtt_subscribe.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,44 @@
11
#!/usr/bin/env python
2-
2+
33
import mosquitto
44
import json
55
from mqtt_settings import config
6-
from numpy_buffer import RingBuffer
76
import datetime
87
import pytz
98
import dateutil.parser
109

10+
1111
def on_message(mosq, obj, msg):
12-
data = json.loads(msg.payload.decode("utf-8")) # deserialization
13-
sent = dateutil.parser.parse(data['ts']) # iso 8601 to datetime.datetime
12+
data = json.loads(msg.payload.decode("utf-8")) # deserialization
13+
sent = dateutil.parser.parse(data['ts']) # iso 8601 to datetime.datetime
1414
data['ts'] = sent
1515
received = datetime.datetime.now(pytz.utc)
1616
lag = received - sent
1717
print("%-20s %d %s lag=%s" % (msg.topic, msg.qos, data, lag))
18-
#mosq.publish('pong', "Thanks", 0)
19-
18+
# mosq.publish('pong', "Thanks", 0)
19+
20+
2021
def on_publish(mosq, obj, mid):
2122
pass
2223

24+
2325
def main():
2426
cli = mosquitto.Mosquitto()
2527
cli.on_message = on_message
2628
cli.on_publish = on_publish
2729

28-
#cli.tls_set('root.ca',
29-
#certfile='c1.crt',
30-
#keyfile='c1.key')
30+
# cli.tls_set('root.ca',
31+
# certfile='c1.crt',
32+
# keyfile='c1.key')
3133

32-
#cli.username_pw_set("guigui", password="abloc")
34+
# cli.username_pw_set("guigui", password="abloc")
3335

3436
cli.connect(config['host'], config['port'], config['keepalive'])
3537
cli.subscribe("/sensors/#", 0)
36-
38+
3739
while cli.loop() == 0:
3840
pass
3941

42+
4043
if __name__ == '__main__':
4144
main()

samples/mqtt_subscribe_matplotlib.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
2+
33
import matplotlib.pyplot as plt
44
import mosquitto
55
import json
@@ -9,9 +9,11 @@
99
import pytz
1010
import dateutil.parser
1111

12+
1213
def now():
1314
return datetime.datetime.now(pytz.utc)
1415

16+
1517
maxlen = 500
1618
data_x = RingBuffer(maxlen, now(), dtype=datetime.datetime)
1719
data_y = RingBuffer(maxlen)
@@ -20,14 +22,15 @@ def now():
2022
line, = ax.plot(data_x.all[::-1], data_y.all[::-1], linestyle='-', marker='+', color='r', markeredgecolor='b')
2123
ax.set_ylim([0, 100])
2224

25+
2326
def on_message(mosq, obj, msg):
24-
data = json.loads(msg.payload.decode("utf-8")) # deserialization
25-
sent = dateutil.parser.parse(data['ts']) # iso 8601 to datetime.datetime
27+
data = json.loads(msg.payload.decode("utf-8")) # deserialization
28+
sent = dateutil.parser.parse(data['ts']) # iso 8601 to datetime.datetime
2629
data['ts'] = sent
2730
received = now()
2831
lag = received - sent
2932
print("%-20s %d %s lag=%s" % (msg.topic, msg.qos, data, lag))
30-
#mosq.publish('pong', "Thanks", 0)
33+
# mosq.publish('pong', "Thanks", 0)
3134

3235
data_x.append(sent)
3336
data_y.append(data['d']['y'])
@@ -40,26 +43,29 @@ def on_message(mosq, obj, msg):
4043
if ymax > ymin:
4144
ax.set_ylim([ymin, ymax])
4245
plt.pause(0.001)
43-
46+
47+
4448
def on_publish(mosq, obj, mid):
4549
pass
4650

51+
4752
def main():
4853
cli = mosquitto.Mosquitto()
4954
cli.on_message = on_message
5055
cli.on_publish = on_publish
5156

52-
#cli.tls_set('root.ca',
53-
#certfile='c1.crt',
54-
#keyfile='c1.key')
57+
# cli.tls_set('root.ca',
58+
# certfile='c1.crt',
59+
# keyfile='c1.key')
5560

56-
#cli.username_pw_set("guigui", password="abloc")
61+
# cli.username_pw_set("guigui", password="abloc")
5762

5863
cli.connect(config['host'], config['port'], config['keepalive'])
5964
cli.subscribe("/sensors/#", 0)
60-
65+
6166
while cli.loop() == 0:
6267
pass
6368

69+
6470
if __name__ == '__main__':
6571
main()

samples/sample_matplotlib_no_datetime.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
import numpy as np
55
from numpy_buffer import RingBuffer
66

7+
78
def main():
89
maxlen = 50
9-
#data_x = RingBuffer(maxlen)
10+
# data_x = RingBuffer(maxlen)
1011
data_y = RingBuffer(maxlen)
1112

12-
y = 100 # initial value
13+
y = 100 # initial value
1314

1415
fig, ax = plt.subplots()
1516
line, = ax.plot(data_y.all[::-1])
@@ -22,5 +23,6 @@ def main():
2223
line.set_ydata(data_y.all[::-1])
2324
plt.pause(0.001)
2425

26+
2527
if __name__ == '__main__':
2628
main()

samples/sample_matplotlib_with_datetime.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
import datetime
66
from numpy_buffer import RingBuffer
77

8+
89
def main():
910
maxlen = 500
1011
data_x = RingBuffer(maxlen, datetime.datetime.utcnow(), dtype=datetime.datetime)
1112
data_y = RingBuffer(maxlen)
1213

13-
y = 100 # initial value
14+
y = 100 # initial value
1415

1516
fig, ax = plt.subplots()
1617
line, = ax.plot(data_x.all[::-1], data_y.all[::-1], linestyle='-', marker='+', color='r', markeredgecolor='b')
@@ -32,5 +33,6 @@ def main():
3233
ax.set_ylim([ymin, ymax])
3334
plt.pause(0.001)
3435

36+
3537
if __name__ == '__main__':
3638
main()

samples/sample_pyqtgraph_no_datetime.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import sys
22
import numpy as np
3-
import datetime
43

5-
from PyQt4.QtCore import QTime, QTimer
4+
from PyQt4.QtCore import QTimer
65
from pyqtgraph.Qt import QtGui, QtCore
76
import pyqtgraph as pg
87

9-
from timestamp import now_timestamp, int2dt
8+
from timestamp import now_timestamp
109
from numpy_buffer import RingBuffer
1110

11+
1212
class MyApplication(QtGui.QApplication):
1313
def __init__(self, *args, **kwargs):
1414
super(MyApplication, self).__init__(*args, **kwargs)
15-
#self.t = QTime()
16-
#self.t.start()
15+
# self.t = QTime()
16+
# self.t.start()
1717

1818
maxlen = 50
1919
self.data_x = RingBuffer(maxlen)
@@ -24,9 +24,9 @@ def __init__(self, *args, **kwargs):
2424
self.win.setWindowTitle('Plot with PyQtGraph')
2525

2626
self.plot = self.win.addPlot(title='Timed data')
27-
#self.plot.setYRange(0, 150)
27+
# self.plot.setYRange(0, 150)
2828

29-
#self.curve = self.plot.plot()
29+
# self.curve = self.plot.plot()
3030

3131
pen = pg.mkPen('r', style=QtCore.Qt.SolidLine)
3232
self.curve = self.plot.plot(pen=pen, symbol='+')
@@ -38,16 +38,17 @@ def __init__(self, *args, **kwargs):
3838
self.y = 100
3939

4040
def update(self):
41-
#self.data.append({'x': self.t.elapsed(), 'y': np.random.randint(0, 100)})
41+
# self.data.append({'x': self.t.elapsed(), 'y': np.random.randint(0, 100)})
4242
x = now_timestamp()
4343
self.y = self.y + np.random.uniform(-1, 1)
4444

4545
self.data_x.append(x)
4646
self.data_y.append(self.y)
4747

48-
#self.curve.setData(x=self.data_x, y=self.data_y)
48+
# self.curve.setData(x=self.data_x, y=self.data_y)
4949
self.curve.setData(y=self.data_y)
5050

51+
5152
def main():
5253
# Set PyQtGraph colors
5354
pg.setConfigOption('background', 'w')
@@ -59,5 +60,6 @@ def main():
5960
app = MyApplication(sys.argv)
6061
sys.exit(app.exec_())
6162

63+
6264
if __name__ == '__main__':
6365
main()

0 commit comments

Comments
 (0)