-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatistics.py
More file actions
47 lines (29 loc) · 1.32 KB
/
Copy pathstatistics.py
File metadata and controls
47 lines (29 loc) · 1.32 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
import datetime
import json
import pathlib
import numpy as np
listings_path = pathlib.Path('downloads/listings_v2.json').resolve()
def to_timestamp(isotime: str) -> float:
return datetime.datetime.fromisoformat(isotime).timestamp()
def to_strftime(timestamp: int) -> str:
return datetime.datetime.fromtimestamp(timestamp).strftime("%H:%M:%S")
def load_listings() -> tuple[list[dict], list[dict]]:
listings = json.load(open(listings_path))
return listings['active'], listings['reserved']
def print_time_hist(data: list[float], name: str):
bin_width = 3600
start_hour = datetime.datetime.fromtimestamp(min(data)).replace(microsecond=0, second=0, minute=0)
start = start_hour.timestamp()
values, edges = np.histogram(data, bins=np.arange(start, max(data) + bin_width, bin_width))
print(f"----- Histogram {name} -----")
for i, v in enumerate(values):
print(f"{to_strftime(edges[i])} - {to_strftime(edges[i + 1])}: {v}")
print()
def time_hist():
active, reserved = load_listings()
active_times = [to_timestamp(x['listed at']) for x in active + reserved]
reserved_times = [to_timestamp(x['reserved at']) for x in reserved]
print_time_hist(active_times, "active times")
print_time_hist(reserved_times, "reserved times")
if __name__ == '__main__':
time_hist()