-
Notifications
You must be signed in to change notification settings - Fork 6
/
utils.py
55 lines (41 loc) · 1.55 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
51
52
53
54
"""
These utility functions are used to download the official dataset from a public bucket
and make it available to the rest of the code (see EvalRSRunner.py)
You should not need to modify this script: if in doubt, ask the organizers first.
"""
from appdirs import *
from pathlib import Path
import requests
from tqdm import tqdm
import zipfile
from datetime import datetime
LFM_DATASET_PATH="https://evalrs.object.lga1.coreweave.com/evalrs_dataset_KDD_2023.zip"
def download_with_progress(url, destination):
"""
Downloads a file with a progress bar
:param url: url from which to download from
:destination: file path for saving data
"""
print(f"Downloading to {destination}...")
try:
response = requests.get(url, stream=True)
response.raise_for_status()
except requests.exceptions.RequestException as e:
raise SystemExit(e)
with tqdm.wrapattr(open(destination, "wb"), "write",
miniters=1, desc=url.split('/')[-1],
total=int(response.headers.get('content-length', 0))) as fout:
for chunk in response.iter_content(chunk_size=4096):
fout.write(chunk)
def decompress_zipfile(file, outfile):
with zipfile.ZipFile(file , 'r') as zip_ref:
zip_ref.extractall(outfile)
def get_cache_directory():
"""
Returns the cache directory on the system
"""
appname = "evalrs"
appauthor = "evalrs"
cache_dir = user_cache_dir(appname, appauthor)
Path(cache_dir).mkdir(parents=True, exist_ok=True)
return cache_dir