-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
50 lines (41 loc) · 1.26 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2020/7/9 0009 11:01
# @Author : Hadrianl
# @File : utils
from mongoengine import Document, StringField, FloatField, IntField, DateTimeField
import json
from pathlib import Path
from tensorboardX import SummaryWriter
Writer = SummaryWriter('run/ppo')
Writer_test = SummaryWriter('run/test')
CURDIR = Path.cwd()
def load_json_settings(filename: str):
"""
Load data from json file in temp path.
"""
filepath = CURDIR.joinpath(filename)
if filepath.exists():
with open(filepath, mode='r') as f:
data = json.load(f)
return data
else:
save_json_settings(filename, {})
return {}
def save_json_settings(filename: str, data: dict):
"""
Save data into json file in temp path.
"""
filepath = CURDIR.joinpath(filename)
with open(filepath, mode='w+') as f:
json.dump(data, f, indent=4)
class HKMarketDataBaseDocument(Document):
code = StringField(required=True)
datetime = DateTimeField(required=True, unique_with='code')
open = FloatField()
high = FloatField()
low = FloatField()
close = FloatField()
volume = IntField()
trade_date = DateTimeField()
meta = {'db_alias': 'HKFuture', 'abstract': True}