From 87af9199cef72d88d1ce677672b78419f2fc01bf Mon Sep 17 00:00:00 2001 From: tomyyyD Date: Thu, 8 Jun 2023 13:35:39 -0400 Subject: [PATCH 01/12] creating function that will query any field --- src/rexdb.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/rexdb.py b/src/rexdb.py index acdd002..0258176 100644 --- a/src/rexdb.py +++ b/src/rexdb.py @@ -56,6 +56,10 @@ def log(self, data) -> bool: self._prev_timestamp = self._timestamp return success + @staticmethod + def int_cmp(x, y): + return (x > y) - (x < y) + def nth(self, n): with open(self._file_manager.current_file, "rb") as fd: fd.seek(n*self._packer.line_size) @@ -124,3 +128,63 @@ def get_data_at_range(self, start_time: time.struct_time, end_time: time.struct_ print(f"could not search file: {e}") return entries + + def get_data_at_field_threshold(self, field: str, threshold, goal, cmp_fn=int_cmp, start_time=None, end_time=None): + """ + string * 'a * ('a * 'a -> ORDER) * struct_time * struct_time -> list + + field is a string and is the name of the field you want to query on. + + Threshold is the value that you want to compare the data to and the + goal is if you want the data to be less than, equal to, or greater + than your threshold. Threshold should be the same type as the data stored + in field, while goal should be -1, 0, or 1. -1 meaning less than, 0 meaning + equal to, 1 meaning greater than. + + cmp_fn is an optional field. It is the comparison function you are using + to compare your threshold with the data stored in the database. The default + is an integer comparison function. + + the start_time and end_time fields are optional fields to limit your search + to a specific time range. + + The complexity of this function if O(n). This function does not benefit from + the speed increase that the map files provide. + """ + + entries = [] + filepaths = [] + # get files to search + if start_time and end_time: + # If start and end times were specified only search files that fall within that range. + start = time.mktime(start_time) + end = time.mktime(end_time) + elif start_time: + # if only start time specified search from start time to now + start = time.mktime(start_time) + end = time.mktime(self._timer_function()) + else: + # if neither are specified search from the database's start to now + start = time.mktime(self._init_time) + end = time.mktime(self._timer_function()) + + filepaths = self._file_manager.locations_from_range(start, end) + # get the correct field index for comparison + for i, f in enumerate(self._field_names): + if field.lower() == f.lower(): + field_index = i + + # access every file + for filepath in filepaths: + try: + with open(filepath, "rb") as file: + for _ in range(self._file_manager.lines_per_file): + raw_data = file.read(self._packer.line_size) + data = self._packer.unpack(raw_data) + # compare entry and threshold and see if they match the goal + if (cmp_fn(data[field_index], threshold) == goal): + entries.append(data) + except Exception as e: + print(f"could not search file: {e}") + + return entries \ No newline at end of file From 183f548ac9701a29b622d6b7a20ceef8adf4134b Mon Sep 17 00:00:00 2001 From: tomyyyD Date: Thu, 8 Jun 2023 13:40:22 -0400 Subject: [PATCH 02/12] test case and bug fixes --- src/rexdb.py | 6 +++--- tests/test_threshold_query.py | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 tests/test_threshold_query.py diff --git a/src/rexdb.py b/src/rexdb.py index 0258176..8bccbd2 100644 --- a/src/rexdb.py +++ b/src/rexdb.py @@ -18,8 +18,8 @@ def __init__(self, fstring, field_names: tuple, bytes_per_file=1000, self._field_names = ("timestamp", *field_names) self._cursor = cursor self._timer_function = time_method - self._init_time = time.mktime(self._timer_function()) - self._prev_timestamp = self._init_time + self._init_time = self._timer_function() + self._prev_timestamp = time.mktime(self._init_time) self._timestamp = 0 self._file_manager = FileManager( "i" + fstring, self._field_names, bytes_per_file, files_per_folder) @@ -187,4 +187,4 @@ def get_data_at_field_threshold(self, field: str, threshold, goal, cmp_fn=int_cm except Exception as e: print(f"could not search file: {e}") - return entries \ No newline at end of file + return entries diff --git a/tests/test_threshold_query.py b/tests/test_threshold_query.py new file mode 100644 index 0000000..feaa22a --- /dev/null +++ b/tests/test_threshold_query.py @@ -0,0 +1,21 @@ +from pyfakefs import fake_filesystem_unittest +from src.rexdb import RexDB +import random +import time + + +class QueryTests(fake_filesystem_unittest.TestCase): + def setUp(self) -> None: + self.setUpPyfakefs() + + def test_query_basic(self): + db = RexDB("ifc", ("index", "super precise number", "initial"), 26, 2) + for i in range(50): + db.log((i, random.random(), bytes(chr(i % 26 + 65), "utf-8"))) + time.sleep(0.5) + + data = db.get_data_at_field_threshold("index", 40, 1) + + self.assertEqual(len(data), 9) + for i in range(9): + self.assertEqual(data[i][1], 41 + i) From 78d66a5ceee0d99dfca020d933426732b4e3b218 Mon Sep 17 00:00:00 2001 From: tomyyyD Date: Thu, 8 Jun 2023 13:43:57 -0400 Subject: [PATCH 03/12] unit tests uses faketime --- tests/test_threshold_query.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_threshold_query.py b/tests/test_threshold_query.py index feaa22a..6639a9b 100644 --- a/tests/test_threshold_query.py +++ b/tests/test_threshold_query.py @@ -1,18 +1,19 @@ from pyfakefs import fake_filesystem_unittest from src.rexdb import RexDB import random -import time +from tests.faketime import FakeTime class QueryTests(fake_filesystem_unittest.TestCase): def setUp(self) -> None: self.setUpPyfakefs() + self.time = FakeTime() def test_query_basic(self): db = RexDB("ifc", ("index", "super precise number", "initial"), 26, 2) for i in range(50): db.log((i, random.random(), bytes(chr(i % 26 + 65), "utf-8"))) - time.sleep(0.5) + self.time.sleep(0.5) data = db.get_data_at_field_threshold("index", 40, 1) From dca1450ac08aaa590b3c06aca84b7be6559dc31c Mon Sep 17 00:00:00 2001 From: tomyyyD Date: Wed, 21 Jun 2023 14:50:15 -0400 Subject: [PATCH 04/12] update get_data_at_time uses new init time scheme --- src/rexdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rexdb.py b/src/rexdb.py index 3fa50f3..a214be4 100644 --- a/src/rexdb.py +++ b/src/rexdb.py @@ -90,7 +90,7 @@ def get_data_at_time(self, t: time.struct_time): """ tfloat = time.mktime(t) filepath = self._file_manager.location_from_time(tfloat) - if tfloat < self._init_time: + if tfloat < time.mktime(self._init_time): raise ValueError("time is before database init time") try: with open(filepath, "rb") as fd: From 659fc8d1721cd6d23111b6da2654b659efb7b13f Mon Sep 17 00:00:00 2001 From: tomyyyD Date: Wed, 21 Jun 2023 15:14:16 -0400 Subject: [PATCH 05/12] cleanup and more tests --- src/rexdb.py | 8 +++++++- tests/test_threshold_query.py | 11 ++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/rexdb.py b/src/rexdb.py index a214be4..63d2557 100644 --- a/src/rexdb.py +++ b/src/rexdb.py @@ -129,7 +129,13 @@ def get_data_at_range(self, start_time: time.struct_time, end_time: time.struct_ return entries - def get_data_at_field_threshold(self, field: str, threshold, goal, cmp_fn=int_cmp, start_time=None, end_time=None): + def get_data_at_field_threshold(self, + field: str, + threshold, + goal, + cmp_fn=int_cmp, + start_time=None, + end_time=None): """ string * 'a * ('a * 'a -> ORDER) * struct_time * struct_time -> list diff --git a/tests/test_threshold_query.py b/tests/test_threshold_query.py index 6639a9b..06ba6f9 100644 --- a/tests/test_threshold_query.py +++ b/tests/test_threshold_query.py @@ -11,8 +11,12 @@ def setUp(self) -> None: def test_query_basic(self): db = RexDB("ifc", ("index", "super precise number", "initial"), 26, 2) + rand_test_answer_key = [] for i in range(50): - db.log((i, random.random(), bytes(chr(i % 26 + 65), "utf-8"))) + num = random.random() + db.log((i, num, bytes(chr(i % 26 + 65), "utf-8"))) + if num > 0.75: + rand_test_answer_key.append(i) self.time.sleep(0.5) data = db.get_data_at_field_threshold("index", 40, 1) @@ -20,3 +24,8 @@ def test_query_basic(self): self.assertEqual(len(data), 9) for i in range(9): self.assertEqual(data[i][1], 41 + i) + + data = db.get_data_at_field_threshold("super precise number", 0.75, 1) + + for i in range(len(rand_test_answer_key)): + self.assertEqual(data[i][1], rand_test_answer_key[i]) From 5efd5cdb42c82073602ba8e89f2b59253b75c10a Mon Sep 17 00:00:00 2001 From: tomyyyD Date: Thu, 29 Jun 2023 15:38:45 -0400 Subject: [PATCH 06/12] more tests and le ge support --- src/rexdb.py | 30 ++++++++++++------- tests/test_threshold_query.py | 54 +++++++++++++++++++++++++++++++++-- 2 files changed, 71 insertions(+), 13 deletions(-) diff --git a/src/rexdb.py b/src/rexdb.py index 63d2557..50a5324 100644 --- a/src/rexdb.py +++ b/src/rexdb.py @@ -137,19 +137,27 @@ def get_data_at_field_threshold(self, start_time=None, end_time=None): """ - string * 'a * ('a * 'a -> ORDER) * struct_time * struct_time -> list + string * 'a * int set * ('a * 'a -> ORDER) * struct_time * struct_time -> list - field is a string and is the name of the field you want to query on. + field + - str + - is a string and is the name of the field you want to query on. - Threshold is the value that you want to compare the data to and the - goal is if you want the data to be less than, equal to, or greater - than your threshold. Threshold should be the same type as the data stored - in field, while goal should be -1, 0, or 1. -1 meaning less than, 0 meaning - equal to, 1 meaning greater than. + Threshold: + - 'a + - is the value that you want to compare the data to - cmp_fn is an optional field. It is the comparison function you are using - to compare your threshold with the data stored in the database. The default - is an integer comparison function. + goal: + - any subset of {-1, 0, 1} + - The integers used in this set should be -1, 0, 1. + - -1 corresponds to less than, 0 corresponds to equal to, 1 corresponds to + greater that. put in your set each operation you would like to include. + + cmp_fn: + - 'a * 'a -> (some x in the set {-1, 0, 1}) + - is an optional field. It is the comparison function you are using + to compare your threshold with the data stored in the database. The default + is an integer comparison function. the start_time and end_time fields are optional fields to limit your search to a specific time range. @@ -188,7 +196,7 @@ def get_data_at_field_threshold(self, raw_data = file.read(self._packer.line_size) data = self._packer.unpack(raw_data) # compare entry and threshold and see if they match the goal - if (cmp_fn(data[field_index], threshold) == goal): + if (cmp_fn(data[field_index], threshold) in goal): entries.append(data) except Exception as e: print(f"could not search file: {e}") diff --git a/tests/test_threshold_query.py b/tests/test_threshold_query.py index 06ba6f9..5596de5 100644 --- a/tests/test_threshold_query.py +++ b/tests/test_threshold_query.py @@ -19,13 +19,63 @@ def test_query_basic(self): rand_test_answer_key.append(i) self.time.sleep(0.5) - data = db.get_data_at_field_threshold("index", 40, 1) + data = db.get_data_at_field_threshold("index", 40, {1}) self.assertEqual(len(data), 9) for i in range(9): self.assertEqual(data[i][1], 41 + i) - data = db.get_data_at_field_threshold("super precise number", 0.75, 1) + data = db.get_data_at_field_threshold("super precise number", 0.75, {1}) for i in range(len(rand_test_answer_key)): self.assertEqual(data[i][1], rand_test_answer_key[i]) + + def test_verbose(self): + db = RexDB("if", ("index", "rand_num")) + random_low_answer_key = [] + random_high_answer_key = [] + for i in range(5000): + num = random.random() + db.log((i, num)) + if num < 0.1: + random_low_answer_key.append((i, num)) + elif num > 0.9: + random_high_answer_key.append((i, num)) + + self.time.sleep(1) + + # test that the first entries can be retrieved successfully and less than operation + data = db.get_data_at_field_threshold("index", 100, {-1}) + self.assertEqual(len(data), 100) + for i in range(100): + self.assertEqual(data[i][1], i) + + # test less than or equal to operation + data = db.get_data_at_field_threshold("index", 100, {-1, 0}) + self.assertEqual(len(data), 101) + for i in range(101): + self.assertEqual(data[i][1], i) + + # test that the last entries can be retrieved successfully and greater than operation + data = db.get_data_at_field_threshold("index", 4899, {1}) + self.assertEqual(len(data), 100) + for i in range(100): + self.assertEqual(data[i][1], i + 4900) + + # test greater than or equal to operation + data = db.get_data_at_field_threshold("index", 4899, {0, 1}) + self.assertEqual(len(data), 101) + for i in range(101): + self.assertEqual(data[i][1], i + 4899) + + # test against the random_low_answer_key + data = db.get_data_at_field_threshold("rand_num", 0.1, {-1}) + self.assertEqual(len(data), len(random_low_answer_key)) + for i in range(len(random_low_answer_key)): + self.assertEqual(data[i][1], random_low_answer_key[i][0]) + + # test against the random_high_answer_key + data = db.get_data_at_field_threshold("rand_num", 0.9, {1}) + self.assertEqual(len(data), len(random_high_answer_key)) + for i in range(len(random_high_answer_key)): + self.assertEqual(data[i][1], random_high_answer_key[i][0]) From 8ab5da37ae3abc7753d6cf18965a6438a912cc92 Mon Sep 17 00:00:00 2001 From: tomyyyD Date: Thu, 29 Jun 2023 15:46:46 -0400 Subject: [PATCH 07/12] documentation --- README.md | 51 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 9132b47..273a0d1 100644 --- a/README.md +++ b/README.md @@ -3,12 +3,15 @@ A very simple Python database with time as the primary method of querying. ## table of contents -- [Overview](#how-it-works) -- [Methods](#methods) - - [\_\_init\_\_](#constructor-init) - - [log](#log) - - [get_data_at_time](#get_data_at_time) - - [get_data_at_range](#get_data_at_range) +- [RexDB](#rexdb) + - [table of contents](#table-of-contents) + - [How it works.](#how-it-works) + - [Methods](#methods) + - [**Constructor** (\_\_init\_\_)](#constructor-__init__) + - [**log**](#log) + - [**get\_data\_at\_time**](#get_data_at_time) + - [**get\_data\_at\_range**](#get_data_at_range) + - [**get\_data\_at\_field\_threshold**](#get_data_at_field_threshold) ## How it works. RexDB works in a very straightforward manner. It works through the operating system file structure. The database is stored in a directory called db\_\, this is so that multiple databases could be stored in the same directory. inside the database folder is another set of folders and within those folders are the files that contain your entries. However, these files are unreadable as they are just structs packed into bytes. @@ -80,7 +83,7 @@ Will log your data in the database and mark it with an automatically generated t arguments - time - - time.struct_time + - `time.struct_time` - the time of the entry which you want to retrieve. functionality @@ -96,12 +99,40 @@ Given a time, this function will return the data entry logged at that time. If t arguments - start_time - - time.struct_time + - `time.struct_time` - the start of your specified range - end_time - - time.struct_time + - `time.struct_time` - the end of your specified range functionality -Will return all entries within a specified time range, if there are no entries within the specified range, will return an empty list. \ No newline at end of file +Will return all entries within a specified time range, if there are no entries within the specified range, will return an empty list. + +### **get_data_at_field_threshold** + +type + +- `str * 'a * int set -> ('a * 'a -> {-1, 0, 1}) -> time.struct_time -> time.struct_time` + +arguments + +- field + - `str` + - the field name you are querying on +- theshold + - `'a` + - the cutoff you are using +- goal + - The integers used in this set should be -1, 0, 1. + - -1 corresponds to less than, 0 corresponds to equal to, 1 corresponds to greater than. put in your set each operation you would like to include. +- cmp_fn + - `'a * 'a -> {-1, 0, 1}` + - the comparison function you will use + - must return some integer x in the set {-1, 0, 1} +- start_time + - time.struct_time + - when you want to start looking +- end_time + - time.struct_time + - when you want to end looking From cb02015e5fe7b48891ee804b97baf2036dc813fb Mon Sep 17 00:00:00 2001 From: thetazero Date: Thu, 29 Jun 2023 20:13:12 -0700 Subject: [PATCH 08/12] update python version --- .github/workflows/unittest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index a523ee1..89320a5 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -22,7 +22,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v1 with: - python-version: 3.8 + python-version: 3.10.6 - name: Install dependencies run: pip install -r requirements.txt From b5e7dc70f10d52e67250fc03315711007ba93bef Mon Sep 17 00:00:00 2001 From: thetazero Date: Thu, 29 Jun 2023 20:15:31 -0700 Subject: [PATCH 09/12] bump py version again --- .github/workflows/unittest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index 89320a5..4f52582 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -22,7 +22,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v1 with: - python-version: 3.10.6 + python-version: 3.10.12 - name: Install dependencies run: pip install -r requirements.txt From 8caea81553d6497e3b6a4e9d66ba441cee2ad82d Mon Sep 17 00:00:00 2001 From: tomyyyD Date: Fri, 21 Jul 2023 09:17:29 -0400 Subject: [PATCH 10/12] update with filter function --- src/rexdb.py | 21 +++++++++---------- tests/test_threshold_query.py | 39 ++++++++++++++++++----------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/rexdb.py b/src/rexdb.py index 50a5324..7cc586b 100644 --- a/src/rexdb.py +++ b/src/rexdb.py @@ -129,13 +129,11 @@ def get_data_at_range(self, start_time: time.struct_time, end_time: time.struct_ return entries - def get_data_at_field_threshold(self, - field: str, - threshold, - goal, - cmp_fn=int_cmp, - start_time=None, - end_time=None): + def get_field_filtered(self, + field: str, + filter_fn, + start_time=None, + end_time=None): """ string * 'a * int set * ('a * 'a -> ORDER) * struct_time * struct_time -> list @@ -194,10 +192,11 @@ def get_data_at_field_threshold(self, with open(filepath, "rb") as file: for _ in range(self._file_manager.lines_per_file): raw_data = file.read(self._packer.line_size) - data = self._packer.unpack(raw_data) - # compare entry and threshold and see if they match the goal - if (cmp_fn(data[field_index], threshold) in goal): - entries.append(data) + if len(raw_data) == self._packer.line_size: + data = self._packer.unpack(raw_data) + # use filter function + if filter_fn(data[field_index]): + entries.append(data) except Exception as e: print(f"could not search file: {e}") diff --git a/tests/test_threshold_query.py b/tests/test_threshold_query.py index 5596de5..6a9b23b 100644 --- a/tests/test_threshold_query.py +++ b/tests/test_threshold_query.py @@ -9,23 +9,31 @@ def setUp(self) -> None: self.setUpPyfakefs() self.time = FakeTime() + def less_than(self, x): + return lambda y: y < x + + def greater_than(self, x): + return lambda y: y > x + def test_query_basic(self): db = RexDB("ifc", ("index", "super precise number", "initial"), 26, 2) rand_test_answer_key = [] + f = self.greater_than(0.75) + g = self.greater_than(40) for i in range(50): num = random.random() db.log((i, num, bytes(chr(i % 26 + 65), "utf-8"))) - if num > 0.75: + if f(num): rand_test_answer_key.append(i) self.time.sleep(0.5) - data = db.get_data_at_field_threshold("index", 40, {1}) + data = db.get_field_filtered("index", g) self.assertEqual(len(data), 9) for i in range(9): self.assertEqual(data[i][1], 41 + i) - data = db.get_data_at_field_threshold("super precise number", 0.75, {1}) + data = db.get_field_filtered("super precise number", f) for i in range(len(rand_test_answer_key)): self.assertEqual(data[i][1], rand_test_answer_key[i]) @@ -34,6 +42,11 @@ def test_verbose(self): db = RexDB("if", ("index", "rand_num")) random_low_answer_key = [] random_high_answer_key = [] + l_10p = self.less_than(0.1) + g_90p = self.greater_than(0.9) + l_100 = self.less_than(100) + g_4899 = self.greater_than(4899) + for i in range(5000): num = random.random() db.log((i, num)) @@ -45,37 +58,25 @@ def test_verbose(self): self.time.sleep(1) # test that the first entries can be retrieved successfully and less than operation - data = db.get_data_at_field_threshold("index", 100, {-1}) + data = db.get_field_filtered("index", l_100) self.assertEqual(len(data), 100) for i in range(100): self.assertEqual(data[i][1], i) - # test less than or equal to operation - data = db.get_data_at_field_threshold("index", 100, {-1, 0}) - self.assertEqual(len(data), 101) - for i in range(101): - self.assertEqual(data[i][1], i) - # test that the last entries can be retrieved successfully and greater than operation - data = db.get_data_at_field_threshold("index", 4899, {1}) + data = db.get_field_filtered("index", g_4899) self.assertEqual(len(data), 100) for i in range(100): self.assertEqual(data[i][1], i + 4900) - # test greater than or equal to operation - data = db.get_data_at_field_threshold("index", 4899, {0, 1}) - self.assertEqual(len(data), 101) - for i in range(101): - self.assertEqual(data[i][1], i + 4899) - # test against the random_low_answer_key - data = db.get_data_at_field_threshold("rand_num", 0.1, {-1}) + data = db.get_field_filtered("rand_num", l_10p) self.assertEqual(len(data), len(random_low_answer_key)) for i in range(len(random_low_answer_key)): self.assertEqual(data[i][1], random_low_answer_key[i][0]) # test against the random_high_answer_key - data = db.get_data_at_field_threshold("rand_num", 0.9, {1}) + data = db.get_field_filtered("rand_num", g_90p) self.assertEqual(len(data), len(random_high_answer_key)) for i in range(len(random_high_answer_key)): self.assertEqual(data[i][1], random_high_answer_key[i][0]) From 455ae7d9c86247a81282094d46584fa4e0954cb4 Mon Sep 17 00:00:00 2001 From: tomyyyD Date: Fri, 28 Jul 2023 13:24:48 -0400 Subject: [PATCH 11/12] docstring updated --- src/rexdb.py | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/rexdb.py b/src/rexdb.py index 7cc586b..3d24ea1 100644 --- a/src/rexdb.py +++ b/src/rexdb.py @@ -141,21 +141,10 @@ def get_field_filtered(self, - str - is a string and is the name of the field you want to query on. - Threshold: - - 'a - - is the value that you want to compare the data to - - goal: - - any subset of {-1, 0, 1} - - The integers used in this set should be -1, 0, 1. - - -1 corresponds to less than, 0 corresponds to equal to, 1 corresponds to - greater that. put in your set each operation you would like to include. - - cmp_fn: - - 'a * 'a -> (some x in the set {-1, 0, 1}) - - is an optional field. It is the comparison function you are using - to compare your threshold with the data stored in the database. The default - is an integer comparison function. + filter_fn: + - 'a -> bool + - The function you want to use to filter your data. Should return a bool that represents + if you want to take that entry as part of the returned set. the start_time and end_time fields are optional fields to limit your search to a specific time range. From 9288d84db1e413257d73ec00bf3e9404cbee4890 Mon Sep 17 00:00:00 2001 From: tomyyyD Date: Fri, 28 Jul 2023 13:32:22 -0400 Subject: [PATCH 12/12] update to time method --- src/rexdb.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/rexdb.py b/src/rexdb.py index 286ece4..464e554 100644 --- a/src/rexdb.py +++ b/src/rexdb.py @@ -108,7 +108,7 @@ def get_data_at_time(self, t: time.struct_time): """ tfloat = time.mktime(t) filepath = self._file_manager.location_from_time(tfloat) - if tfloat < time.mktime(self._init_time): + if tfloat < self._init_time: raise ValueError("time is before database init time") try: with open(filepath, "rb") as fd: @@ -176,15 +176,15 @@ def get_field_filtered(self, # get files to search if start_time and end_time: # If start and end times were specified only search files that fall within that range. - start = time.mktime(start_time) - end = time.mktime(end_time) + start = start_time + end = end_time elif start_time: # if only start time specified search from start time to now - start = time.mktime(start_time) + start = start_time end = time.mktime(self._timer_function()) else: # if neither are specified search from the database's start to now - start = time.mktime(self._init_time) + start = self._init_time end = time.mktime(self._timer_function()) filepaths = self._file_manager.locations_from_range(start, end)