Skip to content

Commit

Permalink
dont reset db if timestamp before first timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
Der-Henning committed Mar 31, 2024
1 parent cb62557 commit 676a47b
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 40 deletions.
22 changes: 7 additions & 15 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,15 @@
"workspaceFolder": "/workspace",

// Set *default* container specific settings.json values on container create.
"settings": {
"python.defaultInterpreterPath": "/usr/local/bin/python",
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": ["tests"],
"python.linting.enabled": true,
"python.linting.flake8Enabled": true,
"python.linting.flake8Args": ["--max-line-length=100"],
"python.formatting.provider": "autopep8",
"python.formatting.autopep8Args": ["--in-place", "--max-line-length=100"]
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"njpwerner.autodocstring"
]
}
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python",
"njpwerner.autodocstring"
],

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

Expand Down
17 changes: 13 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
files: ^src/
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v2.0.1
hooks:
- id: autopep8
files: ^(src|tests)/
args:
- --in-place
- --max-line-length=100
- --in-place
- --max-line-length=79
- repo: https://github.com/PyCQA/isort
rev: 5.11.4
hooks:
- id: isort
files: ^(src|tests)/
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
files: ^(src|tests)/
args:
- --max-line-length=100
- --max-line-length=79
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ addopts = [
"--import-mode=importlib",
]
pythonpath = [
"src"
"src",
"tests"
]
26 changes: 13 additions & 13 deletions src/worker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
from datetime import datetime
# from datetime import datetime

from binance import helpers
# from binance import helpers

from config import Config

Expand All @@ -22,17 +22,17 @@ def run(self):
pass

start_time = self.config.start_time
start_timestamp = helpers.convert_ts_str(start_time) / 1000
first_time = self.config.timescaledb.getFirstTimestamp(
self.config.database, symbol)

if start_timestamp and first_time and start_timestamp < datetime.timestamp(first_time):
self.logger.warning(
"Start time before first timestamp in database")
self.logger.warning(
"Recreating table {}".format(symbol.lower()))
self.config.timescaledb.createTable(
self.config.database, symbol, True)
# start_timestamp = helpers.convert_ts_str(start_time) / 1000
# first_time = self.config.timescaledb.getFirstTimestamp(
# self.config.database, symbol)

# if start_timestamp and first_time and start_timestamp < datetime.timestamp(first_time):
# self.logger.warning(
# "Start time before first timestamp in database")
# self.logger.warning(
# "Recreating table {}".format(symbol.lower()))
# self.config.timescaledb.createTable(
# self.config.database, symbol, True)

last_time = self.config.timescaledb.getLastTimestamp(
self.config.database, symbol)
Expand Down
12 changes: 7 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import pytest
import requests
import json
from os import environ
import pickle
from os import environ

import pandas as pd
from sources import Binance
from sinks import TimescaleDB
import pytest
import requests

from config import Config
from sinks import TimescaleDB
from sources import Binance


@pytest.fixture(scope='function')
Expand Down
3 changes: 2 additions & 1 deletion tests/test_binance.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from sources.binance import Binance, columns
import pandas as pd

from sources.binance import Binance, columns


def test_make_dataframe(binance: Binance, test_data: list):
df = binance.make_dataframe(test_data)
Expand Down
1 change: 1 addition & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest

from config import Config
from sinks import TimescaleDB
from sources import Binance
Expand Down
1 change: 1 addition & 0 deletions tests/test_timescaledb.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pandas as pd

from sinks.timescaledb import TimescaleDB


Expand Down
3 changes: 2 additions & 1 deletion tests/test_worker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime, timezone
from worker import Worker

from config import Config
from worker import Worker


def test_worker(config: Config, responses, binance_ping_response, binance_get_klines_response):
Expand Down

0 comments on commit 676a47b

Please sign in to comment.