Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions display_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import sys
import socket

import re

import pygame

class DisplayResult:
Expand Down Expand Up @@ -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()
Expand All @@ -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")

Expand Down
12 changes: 7 additions & 5 deletions get_temperatures.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
6 changes: 1 addition & 5 deletions strip_spaces.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
34 changes: 34 additions & 0 deletions tags
Original file line number Diff line number Diff line change
@@ -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
Binary file added temperatures.bmp
Binary file not shown.
Binary file added test.bmp
Binary file not shown.
5 changes: 5 additions & 0 deletions test_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()