Skip to content

Commit

Permalink
Time is relative
Browse files Browse the repository at this point in the history
  • Loading branch information
nothingface0 committed Sep 4, 2023
1 parent f9fbb70 commit 27365d8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
19 changes: 14 additions & 5 deletions db.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
### DQM^2 Mirror DB === >
import os
import sys
import psycopg2
import sqlalchemy
from sqlalchemy_utils import database_exists
Expand All @@ -7,6 +9,10 @@
from datetime import datetime
from exceptions import DatabaseNotFoundError

sys.path.append(os.path.join(os.path.dirname(__file__), "."))

from dqmsquare_cfg import TZ


class DQM2MirrorDB:
"""
Expand Down Expand Up @@ -165,10 +171,12 @@ def fill_graph(self, header: dict, document: dict) -> int:

rev = header.get("_rev", -1)
timestamp = extra.get(
"timestamp", datetime(2012, 3, 3, 10, 10, 10, 0).timestamp()
"timestamp",
TZ.localize(datetime(2012, 3, 3, 10, 10, 10, 0), is_dst=None).timestamp(),
)
global_start = extra.get(
"global_start", datetime(2012, 3, 3, 10, 10, 10, 0).timestamp()
"global_start",
TZ.localize(datetime(2012, 3, 3, 10, 10, 10, 0), is_dst=None).timestamp(),
)

stream_data = str(extra.get("streams", ""))
Expand Down Expand Up @@ -224,8 +232,8 @@ def get_graphs_data(self, run) -> list:
answer = list(answer[0])
if answer[-2]:
answer[-2] = eval(answer[-2]) # TODO: Not secure!!!!!!
answer[3] = answer[3].timestamp()
answer[4] = answer[4].timestamp()
answer[3] = TZ.localize(answer[3], is_dst=None).timestamp()
answer[4] = TZ.localize(answer[4], is_dst=None).timestamp()

return answer

Expand Down Expand Up @@ -253,7 +261,8 @@ def fill(self, header: dict, document: dict) -> int:
pass
fi_state = document.get("fi_state", "")
timestamp = header.get(
"timestamp", datetime(2012, 3, 3, 10, 10, 10, 0).timestamp()
"timestamp",
TZ.localize(datetime(2012, 3, 3, 10, 10, 10, 0), is_dst=None).timestamp(),
)
try:
timestamp = datetime.fromtimestamp(timestamp)
Expand Down
3 changes: 3 additions & 0 deletions dqmsquare_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
"""

import os
import pytz
import tempfile
from dotenv import load_dotenv

TZ = pytz.timezone("Europe/Zurich")


def format_db_uri(
username: str = "postgres",
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ sqlalchemy-utils
gunicorn<21.0.0
psycopg2-binary
werkzeug
python-dotenv<2.0.0
python-dotenv<2.0.0
pytz
6 changes: 3 additions & 3 deletions tests/test_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from sqlalchemy import create_engine, insert
from sqlalchemy_utils import create_database, database_exists, drop_database
from custom_logger import dummy_log
from dqmsquare_cfg import format_db_uri, load_cfg
from dqmsquare_cfg import format_db_uri, TZ


def format_entry_to_db_entry(graph_entry: list, datetime_cols: list):
Expand Down Expand Up @@ -236,8 +236,8 @@ def test_db_10(testing_database):
123456,
-1,
"id",
datetime(2012, 3, 3, 10, 10, 10).timestamp(),
datetime(2012, 3, 3, 10, 10, 10).timestamp(),
TZ.localize(datetime(2012, 3, 3, 10, 10, 10), is_dst=None).timestamp(),
TZ.localize(datetime(2012, 3, 3, 10, 10, 10), is_dst=None).timestamp(),
"",
"",
]
Expand Down

0 comments on commit 27365d8

Please sign in to comment.