fix timezone
This commit is contained in:
parent
4f49c2c4ac
commit
04586fa3bc
2 changed files with 43 additions and 9 deletions
50
emfit/__init__.py
Normal file → Executable file
50
emfit/__init__.py
Normal file → Executable file
|
@ -1,18 +1,17 @@
|
||||||
from datetime import datetime
|
#!/usr/bin/env python3
|
||||||
|
from datetime import datetime, time
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
import logging
|
import logging
|
||||||
|
from collections import OrderedDict as odict
|
||||||
from datetime import timedelta, datetime, date
|
from datetime import timedelta, datetime, date
|
||||||
from typing import List, Dict, Iterator, NamedTuple
|
from typing import List, Dict, Iterator, NamedTuple
|
||||||
import json
|
import json
|
||||||
|
import pytz
|
||||||
from collections import OrderedDict as odict
|
|
||||||
|
|
||||||
from kython import cproperty
|
from kython import cproperty
|
||||||
|
|
||||||
|
|
||||||
fromts = datetime.fromtimestamp
|
|
||||||
|
|
||||||
def get_logger():
|
def get_logger():
|
||||||
return logging.getLogger('emfit-provider')
|
return logging.getLogger('emfit-provider')
|
||||||
|
|
||||||
|
@ -30,6 +29,15 @@ EXCLUDED = [
|
||||||
|
|
||||||
AWAKE = 4
|
AWAKE = 4
|
||||||
|
|
||||||
|
# TODO use tz provider for that? although emfit is always in london...
|
||||||
|
|
||||||
|
_TZ = pytz.timezone('Europe/London')
|
||||||
|
|
||||||
|
def fromts(ts) -> datetime:
|
||||||
|
dt = datetime.fromtimestamp(ts)
|
||||||
|
return _TZ.localize(dt)
|
||||||
|
|
||||||
|
|
||||||
class Emfit:
|
class Emfit:
|
||||||
def __init__(self, sid: str, jj):
|
def __init__(self, sid: str, jj):
|
||||||
self.sid = sid
|
self.sid = sid
|
||||||
|
@ -78,7 +86,6 @@ class Emfit:
|
||||||
eps.append(e)
|
eps.append(e)
|
||||||
return tss, eps
|
return tss, eps
|
||||||
|
|
||||||
# TODO are these utc?? should be visible on big plot
|
|
||||||
@cproperty
|
@cproperty
|
||||||
def sleep_start(self) -> datetime:
|
def sleep_start(self) -> datetime:
|
||||||
for [ts, e] in self.epochs:
|
for [ts, e] in self.epochs:
|
||||||
|
@ -284,5 +291,34 @@ def by_night() -> Dict[date, Emfit]:
|
||||||
|
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
for d in get_datas():
|
datas = get_datas()
|
||||||
|
for d in datas:
|
||||||
assert len(d.epochs) > 0
|
assert len(d.epochs) > 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_tz():
|
||||||
|
datas = get_datas()
|
||||||
|
for d in datas:
|
||||||
|
assert d.start.tzinfo is not None
|
||||||
|
assert d.end.tzinfo is not None
|
||||||
|
assert d.sleep_start.tzinfo is not None
|
||||||
|
assert d.sleep_end.tzinfo is not None
|
||||||
|
|
||||||
|
# https://qs.emfit.com/#/device/presence/***REMOVED***
|
||||||
|
# this was winter time, so GMT, UTC+0
|
||||||
|
sid_20190109 = '***REMOVED***'
|
||||||
|
[s0109] = [s for s in datas if s.sid == sid_20190109]
|
||||||
|
assert s0109.end.time() == time(hour=6, minute=42)
|
||||||
|
|
||||||
|
# summer time, so UTC+1
|
||||||
|
sid_20190411 = '***REMOVED***'
|
||||||
|
[s0411] = [s for s in datas if s.sid == sid_20190411]
|
||||||
|
assert s0411.end.time() == time(hour=9, minute=30)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
for k, v in by_night().items():
|
||||||
|
print(k, v.start, v.end)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
2
run
2
run
|
@ -1,2 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
python3 -m emfit
|
|
Loading…
Add table
Reference in a new issue