diff --git a/display_results.py b/display_results.py index 0f06585..c274311 100755 --- a/display_results.py +++ b/display_results.py @@ -10,6 +10,8 @@ import sys import socket +import re + import pygame class DisplayResult: @@ -78,6 +80,10 @@ def new_data(self, line): ''' Add a new data point to the graph. ''' + line = self.get_columns(self.strip_spaces(line)) + if len(line) < 2: + return + print(len(line)) self.points.append(self._get_datapoint(line)) self._update_minmax_points(self.points[-1]) self._update_scaling_factors() @@ -88,15 +94,26 @@ def get_data(self): done = False full_data = "" while not done: - data = s.recv() + data = s.recv(4096).decode('utf-8') if data == "": break full_data = full_data + data + return full_data + def strip_spaces(self, string): + return re.sub(' *', ' ', string) + + def get_columns(self, input): + words = input.split(" ") + if len(words) < 2: + return "" + return words[0] + " " + words[1] + def mainloop(): A = DisplayResult() - for line in sys.stdin: + for line in A.get_data(): + print(line) A.new_data(line) A.save_image("temperatures.bmp") diff --git a/get_temperatures.sh b/get_temperatures.sh index db4e346..fdc69e8 100755 --- a/get_temperatures.sh +++ b/get_temperatures.sh @@ -3,8 +3,10 @@ # Gets the first two columns of a space-seperated input on STDIN # Outputs the first two columns on STDOUT -while read line -do - a="$(echo "$line" | cut -d ' ' -f 1,2)" - echo "$a" -done < "${1:-/dev/stdin}" +cut -d ' ' -f 1,2 + +#while read line +#do + #a="$(echo "$line" | cut -d ' ' -f 1,2)" + #echo "$a" +#done < "${1:-/dev/stdin}" diff --git a/strip_spaces.sh b/strip_spaces.sh index 68060fb..234dcf5 100755 --- a/strip_spaces.sh +++ b/strip_spaces.sh @@ -3,8 +3,4 @@ # Reads data from STDIN, and strips repeated spaces # Outputs the stdin data with spaces removed to STDOUT -while read line -do - a="$(echo "$line" | sed -r 's/ +/ /g')" - echo "$a" -done < "${1:-/dev/stdin}" +sed 's/ */ /g' diff --git a/tags b/tags new file mode 100644 index 0000000..01e092f --- /dev/null +++ b/tags @@ -0,0 +1,34 @@ +!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ +!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ +!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/ +!_TAG_PROGRAM_AUTHOR Universal Ctags Team // +!_TAG_PROGRAM_NAME Universal Ctags /Derived from Exuberant Ctags/ +!_TAG_PROGRAM_URL https://ctags.io/ /official site/ +!_TAG_PROGRAM_VERSION 0.0.0 /45968eff/ +Components README.md /^## Components$/;" s +DisplayResult display_results.py /^class DisplayResult:$/;" c +FakeConnection test_display.py /^class FakeConnection:$/;" c +TestDisplay test_display.py /^class TestDisplay(unittest.TestCase):$/;" c +WeatherGrapher README.md /^# WeatherGrapher$/;" c +__init__ display_results.py /^ def __init__(self):$/;" m class:DisplayResult +__init__ test_display.py /^ def __init__(self):$/;" m class:FakeConnection +__next__ test_display.py /^ def __next__(self):$/;" m class:FakeConnection +_draw_screen display_results.py /^ def _draw_screen(self):$/;" m class:DisplayResult +_get_datapoint display_results.py /^ def _get_datapoint(self, line):$/;" m class:DisplayResult +_get_seconds display_results.py /^ def _get_seconds(self, time):$/;" m class:DisplayResult +_update_minmax_points display_results.py /^ def _update_minmax_points(self, new_point):$/;" m class:DisplayResult +_update_scaling_factors display_results.py /^ def _update_scaling_factors(self):$/;" m class:DisplayResult +get_columns display_results.py /^ def get_columns(self, input):$/;" m class:DisplayResult +get_data display_results.py /^ def get_data(self):$/;" m class:DisplayResult +m test_display.py /^import unittest.mock as m$/;" I +mainloop display_results.py /^def mainloop():$/;" f +new_data display_results.py /^ def new_data(self, line):$/;" m class:DisplayResult +recv test_display.py /^ def recv(self, *args):$/;" m class:FakeConnection +save_image display_results.py /^ def save_image(self, filename):$/;" m class:DisplayResult +setUp test_display.py /^ def setUp(self):$/;" m class:TestDisplay +strip_spaces display_results.py /^ def strip_spaces(self, string):$/;" m class:DisplayResult +test_get_columns test_display.py /^ def test_get_columns(self):$/;" m class:TestDisplay +test_get_data test_display.py /^ def test_get_data(self, socket):$/;" m class:TestDisplay +test_strip_spaces test_display.py /^ def test_strip_spaces(self):$/;" m class:TestDisplay +test_update_points test_display.py /^ def test_update_points(self):$/;" m class:TestDisplay +test_write_image test_display.py /^ def test_write_image(self):$/;" m class:TestDisplay diff --git a/temperatures.bmp b/temperatures.bmp new file mode 100644 index 0000000..ebf5c05 Binary files /dev/null and b/temperatures.bmp differ diff --git a/test.bmp b/test.bmp new file mode 100644 index 0000000..ebf5c05 Binary files /dev/null and b/test.bmp differ diff --git a/test_display.py b/test_display.py index b2656c9..276f328 100644 --- a/test_display.py +++ b/test_display.py @@ -57,5 +57,10 @@ def test_strip_spaces(self): output_string = "hello world two" self.assertEqual(self.disp.strip_spaces(input_string), output_string) + def test_get_columns(self): + input_string = "c1 c2 c3 c4" + output_string = "c1 c2" + self.assertEqual(self.disp.get_columns(input_string), output_string) + if __name__ == "__main__": unittest.main()