-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
173 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.py eol=lf | ||
*.md eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,99 @@ | ||
class DbStoreBase(object): | ||
"""Base class for storing information in a database.""" | ||
|
||
def __init__(self, cursor): | ||
"""Creates a new DbStoreBase object for storing information. | ||
Args: | ||
cursor: SQLite database cursor. | ||
""" | ||
self._cursor = cursor | ||
|
||
|
||
class SoilMoistureStore(DbStoreBase): | ||
"""Stores timestamp and soil moisture readings.""" | ||
|
||
def store_soil_moisture(self, timestamp, soil_moisture): | ||
"""Inserts moisture and timestamp info into an SQLite database. | ||
Args: | ||
timestamp: A datetime object representing the time of the soil | ||
moisture reading. | ||
soil_moisture: An int of the soil moisture reading. | ||
""" | ||
self._cursor.execute('INSERT INTO soil_moisture VALUES (?, ?)', | ||
(timestamp, soil_moisture)) | ||
|
||
|
||
class AmbientLightStore(DbStoreBase): | ||
"""Stores timestamp and ambient light readings.""" | ||
|
||
def store_ambient_light(self, timestamp, ambient_light): | ||
"""Inserts ambient light and timestamp info into an SQLite database. | ||
Args: | ||
timestamp: A datetime object representing the time of the ambient | ||
light reading. | ||
ambient_light: A float of the ambient light level. | ||
""" | ||
self._cursor.execute('INSERT INTO ambient_light VALUES (?, ?)', | ||
(timestamp, ambient_light)) | ||
|
||
|
||
class HumidityStore(DbStoreBase): | ||
"""Stores timestamp and ambient humidity readings.""" | ||
|
||
def store_humidity(self, timestamp, humidity): | ||
"""Inserts humidity and timestamp info into an SQLite database. | ||
Args: | ||
timestamp: A datetime object representing the time of the | ||
humidity reading. | ||
humidity: A float of the humidity reading. | ||
""" | ||
self._cursor.execute('INSERT INTO ambient_humidity VALUES (?, ?)', | ||
(timestamp, humidity)) | ||
|
||
|
||
class ReservoirLevelStore(DbStoreBase): | ||
"""Stores timestamp and reservoir level readings.""" | ||
|
||
def store_reservoir_level(self, timestamp, reservoir_level): | ||
"""Inserts reservoir level and timestamp info into an SQLite database. | ||
Args: | ||
timestamp: A datetime object representing the time of the | ||
reservoir level reading. | ||
reservoir_level: A float of the reservoir level reading in mL. | ||
""" | ||
self._cursor.execute('INSERT INTO reservoir_level VALUES (?, ?)', | ||
(timestamp, reservoir_level)) | ||
|
||
|
||
class TemperatureStore(DbStoreBase): | ||
"""Stores timestamp and ambient temperature readings.""" | ||
|
||
def store_temperature(self, timestamp, temperature): | ||
"""Inserts temperature and timestamp info into an SQLite database. | ||
Args: | ||
timestamp: A datetime object representing the time of the | ||
temperature reading. | ||
temperature: A float of the temperature reading in Celsius. | ||
""" | ||
self._cursor.execute('INSERT INTO temperature VALUES (?, ?)', | ||
(timestamp, temperature)) | ||
|
||
|
||
class WateringEventStore(DbStoreBase): | ||
"""Stores timestamp and volume of water pumped to plant.""" | ||
|
||
def store_water_pumped(self, timestamp, water_pumped): | ||
"""Inserts water volume and timestamp info into an SQLite database. | ||
Args: | ||
timestamp: A datetime object representing the time of the reading. | ||
water_pumped: A float of the water volume pumped in mL. | ||
""" | ||
self._cursor.execute('INSERT INTO watering_events VALUES (?, ?)', | ||
class DbStoreBase(object): | ||
"""Base class for storing information in a database.""" | ||
|
||
def __init__(self, cursor): | ||
"""Creates a new DbStoreBase object for storing information. | ||
Args: | ||
cursor: SQLite database cursor. | ||
""" | ||
self._cursor = cursor | ||
|
||
|
||
class SoilMoistureStore(DbStoreBase): | ||
"""Stores timestamp and soil moisture readings.""" | ||
|
||
def store_soil_moisture(self, timestamp, soil_moisture): | ||
"""Inserts moisture and timestamp info into an SQLite database. | ||
Args: | ||
timestamp: A datetime object representing the time of the soil | ||
moisture reading. | ||
soil_moisture: An int of the soil moisture reading. | ||
""" | ||
self._cursor.execute('INSERT INTO soil_moisture VALUES (?, ?)', | ||
(timestamp, soil_moisture)) | ||
|
||
|
||
class AmbientLightStore(DbStoreBase): | ||
"""Stores timestamp and ambient light readings.""" | ||
|
||
def store_ambient_light(self, timestamp, ambient_light): | ||
"""Inserts ambient light and timestamp info into an SQLite database. | ||
Args: | ||
timestamp: A datetime object representing the time of the ambient | ||
light reading. | ||
ambient_light: A float of the ambient light level. | ||
""" | ||
self._cursor.execute('INSERT INTO ambient_light VALUES (?, ?)', | ||
(timestamp, ambient_light)) | ||
|
||
|
||
class HumidityStore(DbStoreBase): | ||
"""Stores timestamp and ambient humidity readings.""" | ||
|
||
def store_humidity(self, timestamp, humidity): | ||
"""Inserts humidity and timestamp info into an SQLite database. | ||
Args: | ||
timestamp: A datetime object representing the time of the | ||
humidity reading. | ||
humidity: A float of the humidity reading. | ||
""" | ||
self._cursor.execute('INSERT INTO ambient_humidity VALUES (?, ?)', | ||
(timestamp, humidity)) | ||
|
||
|
||
class ReservoirLevelStore(DbStoreBase): | ||
"""Stores timestamp and reservoir level readings.""" | ||
|
||
def store_reservoir_level(self, timestamp, reservoir_level): | ||
"""Inserts reservoir level and timestamp info into an SQLite database. | ||
Args: | ||
timestamp: A datetime object representing the time of the | ||
reservoir level reading. | ||
reservoir_level: A float of the reservoir level reading in mL. | ||
""" | ||
self._cursor.execute('INSERT INTO reservoir_level VALUES (?, ?)', | ||
(timestamp, reservoir_level)) | ||
|
||
|
||
class TemperatureStore(DbStoreBase): | ||
"""Stores timestamp and ambient temperature readings.""" | ||
|
||
def store_temperature(self, timestamp, temperature): | ||
"""Inserts temperature and timestamp info into an SQLite database. | ||
Args: | ||
timestamp: A datetime object representing the time of the | ||
temperature reading. | ||
temperature: A float of the temperature reading in Celsius. | ||
""" | ||
self._cursor.execute('INSERT INTO temperature VALUES (?, ?)', | ||
(timestamp, temperature)) | ||
|
||
|
||
class WateringEventStore(DbStoreBase): | ||
"""Stores timestamp and volume of water pumped to plant.""" | ||
|
||
def store_water_pumped(self, timestamp, water_pumped): | ||
"""Inserts water volume and timestamp info into an SQLite database. | ||
Args: | ||
timestamp: A datetime object representing the time of the reading. | ||
water_pumped: A float of the water volume pumped in mL. | ||
""" | ||
self._cursor.execute('INSERT INTO watering_events VALUES (?, ?)', | ||
(timestamp, water_pumped)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,74 @@ | ||
from __future__ import absolute_import | ||
import unittest | ||
|
||
import mock | ||
import datetime | ||
|
||
from greenpithumb import db_store | ||
|
||
|
||
class StoreClassesTest(unittest.TestCase): | ||
|
||
def test_store_soil_moisture(self): | ||
"""Should insert timestamp and moisture level into database.""" | ||
timestamp = datetime.datetime(2016, 7, 23, 10, 51, 9, 928000) | ||
soil_moisture = 300 | ||
mock_cursor = mock.Mock() | ||
store = db_store.SoilMoistureStore(mock_cursor) | ||
store.store_soil_moisture(timestamp, soil_moisture) | ||
mock_cursor.execute.assert_called_once_with( | ||
"INSERT INTO soil_moisture VALUES (?, ?)", (timestamp, | ||
soil_moisture)) | ||
|
||
def test_store_ambient_light(self): | ||
"""Should insert timestamp and ambient light into database.""" | ||
timestamp = datetime.datetime(2016, 7, 23, 10, 51, 9, 928000) | ||
ambient_light = 50.0 | ||
mock_cursor = mock.Mock() | ||
store = db_store.AmbientLightStore(mock_cursor) | ||
store.store_ambient_light(timestamp, ambient_light) | ||
mock_cursor.execute.assert_called_once_with( | ||
"INSERT INTO ambient_light VALUES (?, ?)", (timestamp, | ||
ambient_light)) | ||
|
||
def test_store_humidity(self): | ||
"""Should insert timestamp and humidity level into database.""" | ||
timestamp = datetime.datetime(2016, 7, 23, 10, 51, 9, 928000) | ||
humidity = 50.0 | ||
mock_cursor = mock.Mock() | ||
store = db_store.HumidityStore(mock_cursor) | ||
store.store_humidity(timestamp, humidity) | ||
mock_cursor.execute.assert_called_once_with( | ||
"INSERT INTO ambient_humidity VALUES (?, ?)", (timestamp, humidity)) | ||
|
||
def test_store_reservoir_level(self): | ||
"""Should insert timestamp and reservoir level into detabase.""" | ||
timestamp = datetime.datetime(2016, 7, 23, 10, 51, 9, 928000) | ||
reservoir_level = 1000.0 | ||
mock_cursor = mock.Mock() | ||
store = db_store.ReservoirLevelStore(mock_cursor) | ||
store.store_reservoir_level(timestamp, reservoir_level) | ||
mock_cursor.execute.assert_called_once_with( | ||
"INSERT INTO reservoir_level VALUES (?, ?)", (timestamp, | ||
reservoir_level)) | ||
|
||
def test_store_temperature(self): | ||
"""Should insert timestamp and temperature into database.""" | ||
timestamp = datetime.datetime(2016, 7, 23, 10, 51, 9, 928000) | ||
temperature = 21.1 | ||
mock_cursor = mock.Mock() | ||
store = db_store.TemperatureStore(mock_cursor) | ||
store.store_temperature(timestamp, temperature) | ||
mock_cursor.execute.assert_called_once_with( | ||
"INSERT INTO temperature VALUES (?, ?)", (timestamp, temperature)) | ||
|
||
def test_store_water_pumped(self): | ||
"""Should insert timestamp and volume of water pumped into database.""" | ||
timestamp = datetime.datetime(2016, 7, 23, 10, 51, 9, 928000) | ||
water_pumped = 200.0 | ||
mock_cursor = mock.Mock() | ||
store = db_store.WateringEventStore(mock_cursor) | ||
store.store_water_pumped(timestamp, water_pumped) | ||
mock_cursor.execute.assert_called_once_with( | ||
"INSERT INTO watering_events VALUES (?, ?)", (timestamp, | ||
from __future__ import absolute_import | ||
import unittest | ||
|
||
import mock | ||
import datetime | ||
|
||
from greenpithumb import db_store | ||
|
||
|
||
class StoreClassesTest(unittest.TestCase): | ||
|
||
def test_store_soil_moisture(self): | ||
"""Should insert timestamp and moisture level into database.""" | ||
timestamp = datetime.datetime(2016, 7, 23, 10, 51, 9, 928000) | ||
soil_moisture = 300 | ||
mock_cursor = mock.Mock() | ||
store = db_store.SoilMoistureStore(mock_cursor) | ||
store.store_soil_moisture(timestamp, soil_moisture) | ||
mock_cursor.execute.assert_called_once_with( | ||
"INSERT INTO soil_moisture VALUES (?, ?)", (timestamp, | ||
soil_moisture)) | ||
|
||
def test_store_ambient_light(self): | ||
"""Should insert timestamp and ambient light into database.""" | ||
timestamp = datetime.datetime(2016, 7, 23, 10, 51, 9, 928000) | ||
ambient_light = 50.0 | ||
mock_cursor = mock.Mock() | ||
store = db_store.AmbientLightStore(mock_cursor) | ||
store.store_ambient_light(timestamp, ambient_light) | ||
mock_cursor.execute.assert_called_once_with( | ||
"INSERT INTO ambient_light VALUES (?, ?)", (timestamp, | ||
ambient_light)) | ||
|
||
def test_store_humidity(self): | ||
"""Should insert timestamp and humidity level into database.""" | ||
timestamp = datetime.datetime(2016, 7, 23, 10, 51, 9, 928000) | ||
humidity = 50.0 | ||
mock_cursor = mock.Mock() | ||
store = db_store.HumidityStore(mock_cursor) | ||
store.store_humidity(timestamp, humidity) | ||
mock_cursor.execute.assert_called_once_with( | ||
"INSERT INTO ambient_humidity VALUES (?, ?)", (timestamp, humidity)) | ||
|
||
def test_store_reservoir_level(self): | ||
"""Should insert timestamp and reservoir level into detabase.""" | ||
timestamp = datetime.datetime(2016, 7, 23, 10, 51, 9, 928000) | ||
reservoir_level = 1000.0 | ||
mock_cursor = mock.Mock() | ||
store = db_store.ReservoirLevelStore(mock_cursor) | ||
store.store_reservoir_level(timestamp, reservoir_level) | ||
mock_cursor.execute.assert_called_once_with( | ||
"INSERT INTO reservoir_level VALUES (?, ?)", (timestamp, | ||
reservoir_level)) | ||
|
||
def test_store_temperature(self): | ||
"""Should insert timestamp and temperature into database.""" | ||
timestamp = datetime.datetime(2016, 7, 23, 10, 51, 9, 928000) | ||
temperature = 21.1 | ||
mock_cursor = mock.Mock() | ||
store = db_store.TemperatureStore(mock_cursor) | ||
store.store_temperature(timestamp, temperature) | ||
mock_cursor.execute.assert_called_once_with( | ||
"INSERT INTO temperature VALUES (?, ?)", (timestamp, temperature)) | ||
|
||
def test_store_water_pumped(self): | ||
"""Should insert timestamp and volume of water pumped into database.""" | ||
timestamp = datetime.datetime(2016, 7, 23, 10, 51, 9, 928000) | ||
water_pumped = 200.0 | ||
mock_cursor = mock.Mock() | ||
store = db_store.WateringEventStore(mock_cursor) | ||
store.store_water_pumped(timestamp, water_pumped) | ||
mock_cursor.execute.assert_called_once_with( | ||
"INSERT INTO watering_events VALUES (?, ?)", (timestamp, | ||
water_pumped)) |