This repository has been archived by the owner on Dec 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added function for clearing the db
faster than destroying it
- Loading branch information
1 parent
dd6b852
commit 957ceda
Showing
3 changed files
with
80 additions
and
3 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
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
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,67 @@ | ||
import time | ||
import logging | ||
import datetime | ||
import pprint | ||
|
||
from data.routines import ( | ||
destroy_database, | ||
init_database, | ||
create_user, | ||
save_posture, | ||
Posture, | ||
get_users, | ||
get_postures, | ||
clear_database, | ||
) | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def main(): | ||
logging.basicConfig(level=logging.INFO) | ||
logger.info("Destroying database") | ||
destroy_database() | ||
|
||
logger.info("Initialising database") | ||
start_time = time.time() | ||
init_database() | ||
total_time = time.time() - start_time | ||
logger.info("Done init database in %f seconds", total_time) | ||
|
||
logger.info("Filling with some data") | ||
|
||
for _ in range(10): | ||
_fill_database() | ||
|
||
logger.info( | ||
"Example data\n%s\n%s", | ||
pprint.pformat(get_users(), width=50), | ||
pprint.pformat(get_postures(), width=50), | ||
) | ||
|
||
logger.info("Reseting data by dropping rows") | ||
start_time = time.time() | ||
clear_database() | ||
total_time = time.time() - start_time | ||
logger.info("Done clearing data in %f", total_time) | ||
|
||
logger.info( | ||
"Example data\n%s\n%s", | ||
pprint.pformat(get_users(), width=50), | ||
pprint.pformat(get_postures(), width=50), | ||
) | ||
|
||
|
||
def _fill_database() -> None: | ||
create_user() | ||
example_id = create_user() | ||
create_user() | ||
|
||
example_posture = Posture( | ||
None, example_id, 0.8, 0.8, datetime.datetime.now(), datetime.datetime.now() | ||
) | ||
save_posture(example_posture) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |