From 4646c7d7a62b1e7d4d3715c0d2ba4c272b89e91f Mon Sep 17 00:00:00 2001 From: Thomas Klaehn Date: Thu, 30 Mar 2017 15:15:00 +0200 Subject: [PATCH] project: reorder Signed-off-by: Thomas Klaehn --- .gitlab-ci.yml | 4 +- .pydevproject | 1 - .../gate_guard.py => gate_guard/__init__.py | 2 - .../__init__.py => gate_guard/data_buffer.py | 5 +++ .../__init__.py => gate_guard/engine.py | 5 +++ source/gate/__init__.py => gate_guard/gate.py | 7 ++- .../__init__.py => gate_guard/light_sensor.py | 5 +++ .../__init__.py => gate_guard/power_sensor.py | 1 - sonar-project.properties | 2 +- source/__init__.py | 0 source/close.py | 45 ------------------- source/light.py | 19 -------- source/open.py | 45 ------------------- tests/unittests/test_data_buffer.py | 8 ++-- 14 files changed, 24 insertions(+), 125 deletions(-) rename source/gate_guard.py => gate_guard/__init__.py (89%) rename source/data_buffer/__init__.py => gate_guard/data_buffer.py (92%) rename source/engine/__init__.py => gate_guard/engine.py (92%) rename source/gate/__init__.py => gate_guard/gate.py (97%) rename source/light_sensor/__init__.py => gate_guard/light_sensor.py (88%) rename source/power_sensor/__init__.py => gate_guard/power_sensor.py (99%) delete mode 100644 source/__init__.py delete mode 100644 source/close.py delete mode 100644 source/light.py delete mode 100644 source/open.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 125cbf8..e01a0e0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,8 +9,8 @@ stages: tests: stage: test script: - - "python scripts/pylint_wrapper.py -s source -s tests" - - "nosetests --with-coverage --cover-package=source --cover-xml" + - "python scripts/pylint_wrapper.py -s gate_guard -s tests" + - "nosetests --with-coverage --cover-package=gate_guard --cover-xml" - "nosetests --with-xunit tests/unittests/" - "sonar-runner" diff --git a/.pydevproject b/.pydevproject index 170cdc9..34534da 100644 --- a/.pydevproject +++ b/.pydevproject @@ -1,7 +1,6 @@ -/${PROJECT_DIR_NAME}/source /${PROJECT_DIR_NAME}/scripts /${PROJECT_DIR_NAME}/tests diff --git a/source/gate_guard.py b/gate_guard/__init__.py similarity index 89% rename from source/gate_guard.py rename to gate_guard/__init__.py index dec0fbd..caf3758 100644 --- a/source/gate_guard.py +++ b/gate_guard/__init__.py @@ -3,8 +3,6 @@ Created on Dec 19, 2016 @author: klaehn ''' -import sys -sys.path.append('source/') import time import gate diff --git a/source/data_buffer/__init__.py b/gate_guard/data_buffer.py similarity index 92% rename from source/data_buffer/__init__.py rename to gate_guard/data_buffer.py index c503ee9..26b99f7 100644 --- a/source/data_buffer/__init__.py +++ b/gate_guard/data_buffer.py @@ -1,3 +1,8 @@ +''' +Created on Mar 30, 2017 + +@author: tkla +''' class DataBuffer(object): def __init__(self, length): diff --git a/source/engine/__init__.py b/gate_guard/engine.py similarity index 92% rename from source/engine/__init__.py rename to gate_guard/engine.py index 47f3b0d..493fdf3 100644 --- a/source/engine/__init__.py +++ b/gate_guard/engine.py @@ -1,3 +1,8 @@ +''' +Created on Mar 30, 2017 + +@author: tkla +''' import gpio class Engine(object): diff --git a/source/gate/__init__.py b/gate_guard/gate.py similarity index 97% rename from source/gate/__init__.py rename to gate_guard/gate.py index 29267a4..a89e145 100644 --- a/source/gate/__init__.py +++ b/gate_guard/gate.py @@ -3,14 +3,13 @@ Created on Dec 19, 2016 @author: klaehn ''' -import sys -sys.path.append('source/') import time import mqtt import data_buffer import light_sensor import engine -from power_sensor import PowerSensor +import power_sensor +from numpy.core.umath import power STATE_INIT = "init" STATE_OPENED = "open" @@ -54,7 +53,7 @@ class Gate(object): self.__light_data = data_buffer.DataBuffer(LIGHT_CONSECUTIVE_READS) self.__comserver = mqtt.Mqtt(MQTT_HOST) self.__engine = engine.Engine(gpio_1=13, gpio_2=19) - self.__power_sensor = PowerSensor(POWER_SENSOR_I2C_BUS, \ + self.__power_sensor = power_sensor.PowerSensor(POWER_SENSOR_I2C_BUS, \ POWER_SENSOR_I2C_ADDRESS) self.__power_data = data_buffer.DataBuffer(POWER_CONSECUTIVE_READS) self.__gate_move_timeout = 0 diff --git a/source/light_sensor/__init__.py b/gate_guard/light_sensor.py similarity index 88% rename from source/light_sensor/__init__.py rename to gate_guard/light_sensor.py index c59d164..4dcc3ab 100644 --- a/source/light_sensor/__init__.py +++ b/gate_guard/light_sensor.py @@ -1,3 +1,8 @@ +''' +Created on Mar 30, 2017 + +@author: tkla +''' import smbus class LightSensor(object): diff --git a/source/power_sensor/__init__.py b/gate_guard/power_sensor.py similarity index 99% rename from source/power_sensor/__init__.py rename to gate_guard/power_sensor.py index b9e2bec..2bf4d0a 100644 --- a/source/power_sensor/__init__.py +++ b/gate_guard/power_sensor.py @@ -3,7 +3,6 @@ Created on Dec 19, 2016 @author: klaehn ''' - import smbus class PowerSensor(object): diff --git a/sonar-project.properties b/sonar-project.properties index 4494272..98c89fa 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -2,7 +2,7 @@ sonar.projectKey=chickenhouse:python sonar.projectName=chickenhouse:python sonar.projectVersion=1.0 sonar.host.url=http://sonarqube:9000 -sonar.sources=source +sonar.sources=gate_guard sonar.tests=tests/unittests sonar.language=py sonar.sourceEncoding=UTF-8 diff --git a/source/__init__.py b/source/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/source/close.py b/source/close.py deleted file mode 100644 index 85b9a80..0000000 --- a/source/close.py +++ /dev/null @@ -1,45 +0,0 @@ -''' -Created on Dec 23, 2016 - -@author: klaehn -''' -import sys -sys.path.append('source/') -import time - -import data_buffer -import engine -import power_sensor - -POWER_SENSOR_I2C_BUS = 1 -POWER_SENSOR_I2C_ADDRESS = 0x40 - -CONSECUTIVE_POWER_READS = 1000 - -MAX_ENGINE_POWER = {"up":330, "down":280} - -def main(argv): - __engine = engine.Engine(gpio_1=13, gpio_2=19) - __power_sensor = power_sensor.PowerSensor(POWER_SENSOR_I2C_BUS, POWER_SENSOR_I2C_ADDRESS) - __power_data = data_buffer.DataBuffer(CONSECUTIVE_POWER_READS) - __engine.down() - try: - while True: - rd = __power_sensor.power_mw() - __power_data.push(rd) - average = __power_data.average() - print str(time.time()) + " " + str(rd) - if average != None: - if average > MAX_ENGINE_POWER["down"]: - __engine.stop() -# print "Gate successfully closed" - return 0 - - except KeyboardInterrupt: - __engine.stop() -# print "Closing procedure interrupted." - return 1 - - -if __name__ == "__main__": - sys.exit(main(sys.argv[1:])) diff --git a/source/light.py b/source/light.py deleted file mode 100644 index 1750d27..0000000 --- a/source/light.py +++ /dev/null @@ -1,19 +0,0 @@ -''' -Created on Dec 24, 2016 - -@author: tkl -''' -import sys -sys.path.append('source/') -import time -import light_sensor -import mqtt - -def main(): - conn = mqtt.Mqtt(hostname='proxy') - light = light_sensor.LightSensor(1, 0x23) - conn.transmit("outdoor/chickenhouse/sensors/light", \ - str(int(time.time())) + " " + str(light.read())) - -if __name__ == "__main__": - sys.exit(main()) diff --git a/source/open.py b/source/open.py deleted file mode 100644 index 1ec4eea..0000000 --- a/source/open.py +++ /dev/null @@ -1,45 +0,0 @@ -''' -Created on Dec 23, 2016 - -@author: klaehn -''' -import sys -sys.path.append('source/') -import time - -import data_buffer -import engine -import power_sensor - -POWER_SENSOR_I2C_BUS = 1 -POWER_SENSOR_I2C_ADDRESS = 0x40 - -CONSECUTIVE_POWER_READS = 1000 - -MAX_ENGINE_POWER = {"up":330, "down":290} - -def main(argv): - __engine = engine.Engine(gpio_1=13, gpio_2=19) - __power_sensor = power_sensor.PowerSensor(POWER_SENSOR_I2C_BUS, POWER_SENSOR_I2C_ADDRESS) - power_data = data_buffer.DataBuffer(CONSECUTIVE_POWER_READS) - __engine.up() - try: - while True: - rd = __power_sensor.power_mw() - power_data.push(rd) - average = power_data.average() - print str(time.time()) + " " + str(rd) - if average != None: - if average > MAX_ENGINE_POWER["up"]: - __engine.stop() -# print "Gate successfully opened" - return 0 - - except KeyboardInterrupt: - __engine.stop() - print "Closing procedure interrupted." - return 1 - - -if __name__ == "__main__": - sys.exit(main(sys.argv[1:])) diff --git a/tests/unittests/test_data_buffer.py b/tests/unittests/test_data_buffer.py index ae0bb42..e1a7333 100644 --- a/tests/unittests/test_data_buffer.py +++ b/tests/unittests/test_data_buffer.py @@ -3,24 +3,22 @@ Created on Dec 19, 2016 @author: klaehn ''' -import sys -sys.path.append('source/') import unittest import random -import data_buffer +import gate_guard.data_buffer class Test(unittest.TestCase): def test_zero_space(self): - dut = data_buffer.DataBuffer(0) + dut = gate_guard.data_buffer.DataBuffer(0) result = dut.push(10) self.assertFalse(result, "test_zero_space - exp: False res: True") def test_max_data(self): buffer_size = 10 - dut = data_buffer.DataBuffer(buffer_size) + dut = gate_guard.data_buffer.DataBuffer(buffer_size) for _ in range(11): dut.push(random.random()) result = dut.length()