broken tests
This commit is contained in:
parent
56e34902bb
commit
7b2f6e5b0e
@ -2,6 +2,9 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
from datetime import datetime
|
||||||
|
from zoneinfo import ZoneInfo
|
||||||
|
from pytz import timezone
|
||||||
|
|
||||||
import psycopg
|
import psycopg
|
||||||
|
|
||||||
@ -42,18 +45,24 @@ def create_or_find_device_id(name):
|
|||||||
|
|
||||||
|
|
||||||
def parse_attrlog_file(filename, device_id=None):
|
def parse_attrlog_file(filename, device_id=None):
|
||||||
|
tz = timezone("Europe/Tallinn")
|
||||||
|
utc = timezone("UTC")
|
||||||
fd = open(filename)
|
fd = open(filename)
|
||||||
file_size = fd.seek(0, os.SEEK_END)
|
file_size = fd.seek(0, os.SEEK_END)
|
||||||
fd.seek(0)
|
fd.seek(0)
|
||||||
while fd.tell() != file_size:
|
while fd.tell() != file_size:
|
||||||
line = fd.readline()
|
line = fd.readline()
|
||||||
line_parts = [p for p in line.strip().split(";") if p.strip()]
|
line_parts = [p for p in line.strip().split(";") if p.strip()]
|
||||||
dt = line_parts.pop(0)+"+0200"
|
#dt = line_parts.pop(0)+"+0200"
|
||||||
|
dt = datetime.strptime(line_parts.pop(0), "%Y-%m-%d %H:%M:%S")#.replace(tzinfo=tz)
|
||||||
|
dtz = dt.replace(tzinfo=tz)
|
||||||
|
dtu = dt.astimezone(utc)
|
||||||
|
print(dt, dtz, dtu, sep='; ')
|
||||||
while line_parts:
|
while line_parts:
|
||||||
id = int(line_parts.pop(0))
|
id = int(line_parts.pop(0))
|
||||||
norm = int(line_parts.pop(0))
|
norm = int(line_parts.pop(0))
|
||||||
raw = int(line_parts.pop(0))
|
raw = int(line_parts.pop(0))
|
||||||
yield dt, id, norm, raw, device_id
|
yield dtu, id, norm, raw, device_id
|
||||||
if fd.tell() % 100 == 0:
|
if fd.tell() % 100 == 0:
|
||||||
print(f"{int((fd.tell() / file_size)*100):>5}%", end='\r')
|
print(f"{int((fd.tell() / file_size)*100):>5}%", end='\r')
|
||||||
print()
|
print()
|
||||||
@ -65,9 +74,15 @@ def import_attrlog_file(filename):
|
|||||||
device_id = create_or_find_device_id(drive_name)
|
device_id = create_or_find_device_id(drive_name)
|
||||||
with conn.cursor() as cur:
|
with conn.cursor() as cur:
|
||||||
cur.execute("START TRANSACTION")
|
cur.execute("START TRANSACTION")
|
||||||
with cur.copy("copy attrlog (time, id, norm, raw, device_id) FROM STDIN") as copy:
|
|
||||||
for row in parse_attrlog_file(filename, device_id):
|
for row in parse_attrlog_file(filename, device_id):
|
||||||
copy.write_row(row)
|
cur.execute("""
|
||||||
|
INSERT INTO attrlog (time, id, norm, raw, device_id)
|
||||||
|
VALUES (%s, %s, %s, %s, %s)
|
||||||
|
""", row)
|
||||||
|
# with cur.copy("copy attrlog (time, id, norm, raw, device_id) FROM STDIN") as copy:
|
||||||
|
# for row in parse_attrlog_file(filename, device_id):
|
||||||
|
# #print(row)
|
||||||
|
# copy.write_row(row)
|
||||||
cur.execute("COMMIT")
|
cur.execute("COMMIT")
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user