-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
70 lines (55 loc) · 1.69 KB
/
Copy pathutils.py
File metadata and controls
70 lines (55 loc) · 1.69 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import logging
import time
import os
from pathlib import Path
from datetime import timedelta
import pandas as pd
from datetime import datetime as dt
from pandas import Timestamp
import numpy as np
import torch
#from clean_data import create_csv, create_xlsx
#from clean_data import csv_process, xlsx_process
def fcall(fun):
"""
Convenience decorator used to measure the time spent while executing
the decorated function.
:param fun:
:return:
"""
def wrapper(*args, **kwargs):
logging.info("[{}] ...".format(fun.__name__))
start_time = time.perf_counter()
res = fun(*args, **kwargs)
end_time = time.perf_counter()
runtime = end_time - start_time
logging.info("[{}] Done! {}s\n".format(fun.__name__, timedelta(seconds=runtime)))
return res
return wrapper
def time_idx(dates, earliest_time = Timestamp("2022-03-01 00:00:00")):
"""
Compute half hours from start.
Args:
dates (list[pandas.Timestamp]) : list of dates
earliest_time (pd.Timestamp) : earliest time
Return:
list: List of half hours from start with each date
"""
result = []
for date in dates:
half_hours = (date - earliest_time).total_seconds() / 60 / 30
result.append(int(half_hours))
return result
def rmr_score(actual, predict):
"""データフレームから残差平均割合を計算する。
Args:
actual (np.array): 実績
predict (np.array): 予測
Returns:
float: 残差平均割合
"""
eps = 1e-9
actual = actual + eps
diff = actual - predict
mx = sum(abs(diff) / sum(actual))
return mx * 100