Skip to content

Commit

Permalink
Issue 28: updating points with csvstorage (#29)
Browse files Browse the repository at this point in the history
* #28: bugfix

* hotfix: update codebase for black23 and flake6

* hotfix: black and flake updates
  • Loading branch information
citrusvanilla committed Feb 16, 2023
1 parent 24ab88d commit 13f80d7
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Check static typing
run: mypy tinyflux/ tests/
- name: Run tests
run: coverage run -m pytest && coverage report -m
run: coverage run --source tinyflux/ -m pytest && coverage report -m
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v2
with:
Expand Down
6 changes: 6 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

v0.2.4 (2023-2-15)
^^^^^^^^^^^^^^^^^^

* Fix bug that prevents updating Points when using a CSVStorage instance.


v0.2.1 (2022-11-22)
^^^^^^^^^^^^^^^^^^^

Expand Down
5 changes: 2 additions & 3 deletions examples/3_iot_datastore_with_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def on_connect(client, *args):
def on_disconnect(_, __, rc):
"""Define the on_disconnect callback.
See http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718035
See http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/
mqtt-v3.1.1-os.html#_Toc398718035
for return codes descriptions.
Args:
Expand Down Expand Up @@ -144,10 +145,8 @@ def run_tinyflux_worker():
"""
# Loop until exit_event is set by main thread.
while True:

# Check the queue for new packets.
if not q.empty():

# Unpack MQTT packet.
data = q.get()
topic = data["topic"]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ def test_regex():

def test_custom_function():
"""Test custom function in the test method."""
# Test an arbitrary function with no additional args.

def is_los_angeles(value):
"""Return value is los angeles."""
return value == "los angeles"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def test_in_memory_close():

def test_subclassing_storage():
"""Test subclassing ABC Storage without defining abstract methods."""
# Subclass without abstract methods.

class MyStorage(Storage):
pass

Expand Down
36 changes: 1 addition & 35 deletions tinyflux/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ def contains(
"""
# If the index is valid, check it.
if self._index.valid:

if measurement:
mq = MeasurementQuery() == measurement
index_rst = self._index.search(mq & query)
Expand All @@ -313,7 +312,6 @@ def contains(

# Search without help of the index.
for item in self._storage:

# Filter by measurement.
if (
measurement
Expand Down Expand Up @@ -341,7 +339,6 @@ def count(self, query: Query, measurement: Optional[str] = None) -> int:
"""
# If the index is valid, check it.
if self._index.valid:

if measurement:
mq = MeasurementQuery() == measurement
index_rst = self._index.search(mq & query)
Expand All @@ -356,7 +353,6 @@ def count(self, query: Query, measurement: Optional[str] = None) -> int:

# Search without help of the index.
for item in self._storage:

# Filter by measurement.
if (
measurement
Expand Down Expand Up @@ -411,7 +407,6 @@ def get(

# If we are auto-indexing and the index is valid, check it.
if use_index:

if measurement:
mq = MeasurementQuery() == measurement
index_rst = self._index.search(mq & query)
Expand All @@ -431,9 +426,7 @@ def get(

# Search with help of the index.
if use_index:

for i, item in enumerate(self._storage):

# Not a candidate.
if i not in index_rst._items:
continue
Expand All @@ -443,10 +436,8 @@ def get(
break

else:

# Evaluate all points until match.
for item in self._storage:

# Filter by measurement.
if (
measurement
Expand Down Expand Up @@ -488,7 +479,6 @@ def get_field_keys(self, measurement: Optional[str] = None) -> List[str]:
rst = set({})

for item in self._storage:

# Filter by measurement.
if (
measurement
Expand Down Expand Up @@ -525,7 +515,6 @@ def get_field_values(
rst = []

for item in self._storage:

# Filter by measurement.
if (
measurement
Expand Down Expand Up @@ -581,7 +570,6 @@ def get_tag_keys(self, measurement: Optional[str] = None) -> List[str]:
rst = set({})

for item in self._storage:

# Filter by measurement.
if (
measurement
Expand Down Expand Up @@ -625,7 +613,6 @@ def get_tag_values(
rst = {i: set({}) for i in sorted(relevant_tags)}

for item in self._storage:

# Filter by measurement.
if (
measurement
Expand Down Expand Up @@ -672,7 +659,6 @@ def get_timestamps(
rst: List[datetime] = []

for item in self._storage:

# Filter by measurement.
if (
measurement
Expand Down Expand Up @@ -826,7 +812,6 @@ def search(

# If we are auto-indexing and the index is valid, check it.
if use_index:

if measurement:
mq = MeasurementQuery() == measurement
index_rst = self._index.search(mq & query)
Expand All @@ -849,7 +834,6 @@ def search(
j = 0

for i, item in enumerate(self._storage):

# Not a candidate, skip.
if i not in index_rst._items:
continue
Expand All @@ -867,9 +851,7 @@ def search(

# Search without index.
else:

for item in self._storage:

# Filter by measurement.
if (
measurement
Expand Down Expand Up @@ -947,7 +929,6 @@ def select(

# If we are auto-indexing and the index is valid, check it.
if use_index:

if measurement:
mq = MeasurementQuery() == measurement
index_rst = self._index.search(mq & query)
Expand All @@ -961,7 +942,6 @@ def select(
j = 0

for i, item in enumerate(self._storage):

# Not in result set, skip.
if i not in index_rst._items:
continue
Expand Down Expand Up @@ -1007,9 +987,7 @@ def select(

# Select without index.
else:

for item in self._storage:

# Filter by measurement.
if (
measurement
Expand All @@ -1022,7 +1000,6 @@ def select(
_point = self._storage._deserialize_storage_item(item)

if query(_point):

result = []

for key in keys:
Expand Down Expand Up @@ -1297,7 +1274,6 @@ def _remove_helper(

# If we are auto-indexing and the index is valid, check it.
if use_index:

if measurement:
mq = MeasurementQuery() == measurement
index_rst = self._index.search(mq & query)
Expand Down Expand Up @@ -1327,11 +1303,9 @@ def _remove_helper(

# Update with the help of the index.
if use_index:

j = 0

for i, item in enumerate(self._storage):

# No more items or item is not a candidate.
if j == len(index_rst._items) or i not in index_rst._items:
self._storage.append([item], temporary=True)
Expand All @@ -1351,9 +1325,7 @@ def _remove_helper(

# Update without the help of the index.
else:

for i, item in enumerate(self._storage):

# Filter by measurement.
if measurement:
_measurement = self._storage._deserialize_measurement(item)
Expand Down Expand Up @@ -1451,7 +1423,6 @@ def _update_helper(

# If we are auto-indexing and the index is valid, check it.
if use_index:

if _measurement:
mq = MeasurementQuery() == _measurement
index_rst = self._index.search(mq & query)
Expand All @@ -1468,11 +1439,9 @@ def _update_helper(

# Update with the help of the index.
if use_index:

j = 0

for i, item in enumerate(self._storage):

# Not a query match, pass item through.
if j == len(index_rst.items) or i not in index_rst._items:
self._storage.append([item], temporary=True)
Expand Down Expand Up @@ -1501,9 +1470,7 @@ def _update_helper(

# Update without the help of the index.
else:

for item in self._storage:

# Filter by measurement.
if (
_measurement
Expand All @@ -1517,14 +1484,13 @@ def _update_helper(

# No query specified, or query match.
if update_all or query(_point):

# Attempt update.
u = perform_update(_point)

# Attributes changed. Serialize and add to memory.
if u:
self._storage.append(
[self._storage._deserialize_storage_item(_point)],
[self._storage._serialize_point(_point)],
temporary=True,
)

Expand Down
Loading

0 comments on commit 13f80d7

Please sign in to comment.