-
Notifications
You must be signed in to change notification settings - Fork 0
Threshold queries #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tomyyyD
wants to merge
16
commits into
main
Choose a base branch
from
threshold_queries
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+178
−4
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
87af919
creating function that will query any field
tomyyyD 183f548
test case and bug fixes
tomyyyD 78d66a5
unit tests uses faketime
tomyyyD e31a6c5
Merge branch 'main' into threshold_queries
tomyyyD dca1450
update get_data_at_time
tomyyyD 659fc8d
cleanup and more tests
tomyyyD 5efd5cd
more tests and le ge support
tomyyyD 8ab5da3
documentation
tomyyyD cb02015
update python version
thetazero b5e7dc7
bump py version again
thetazero 4cb9708
Merge pull request #15 from PyCubed-Mini/unit_test_issues
tomyyyD 8caea81
update with filter function
tomyyyD a28740c
Merge branch 'threshold_queries' of https://github.com/PyCubed-Mini/R…
tomyyyD 455ae7d
docstring updated
tomyyyD cde5eaf
Merge branch 'main' into threshold_queries
tomyyyD 9288d84
update to time method
tomyyyD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,82 @@ | ||
| from pyfakefs import fake_filesystem_unittest | ||
| from src.rexdb import RexDB | ||
| import random | ||
| from tests.faketime import FakeTime | ||
|
|
||
|
|
||
| class QueryTests(fake_filesystem_unittest.TestCase): | ||
| 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 f(num): | ||
| rand_test_answer_key.append(i) | ||
| self.time.sleep(0.5) | ||
|
|
||
| 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_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]) | ||
|
|
||
| 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)) | ||
| 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_field_filtered("index", l_100) | ||
| self.assertEqual(len(data), 100) | ||
| for i in range(100): | ||
| self.assertEqual(data[i][1], i) | ||
|
|
||
| # test that the last entries can be retrieved successfully and greater than operation | ||
| 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 against the random_low_answer_key | ||
| 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_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]) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another thought, given our memory issues we probably want to require a limit on the number of entries you get back.
Otherwise calling
get_field_filteredis pretty dangerous, you have no idea how much memory will be allocated in the worst case.