-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
88 lines (72 loc) · 2.76 KB
/
main.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import typer
from platforms_discoveries.ark.download import download_dataset as ark_dataset
from platforms_discoveries.ark.discoveries import get_nodes_links as ark_nodes_links
from platforms_discoveries.ripe.download import download_dataset as ripe_dataset
from platforms_discoveries.ripe.discoveries import get_nodes_links as ripe_nodes_links
from datetime import datetime
from datetimerange import DateTimeRange
from pathlib import Path
from typing import List
app = typer.Typer()
@app.command()
def ark(
credentials: str = typer.Argument(
..., help="Caida credentials (e.g., <email>:<password>)"
),
time_range_start: str = typer.Option(
..., help="Time range start in isoformat (e.g., 2021-08-06T11:59:59)"
),
time_range_stop: str = typer.Option(
..., help="Time range end in isoformat (e.g., 2021-08-06T16:35:31)"
),
cycle: List[str] = typer.Option(
None, help="Filter to a specific cycle in the specified time range"
),
dataset_dir: Path = typer.Option(
Path("./data/ark"), help="Directory where to store dataset"
),
processes: int = typer.Option(
None, help="Number of processes for the multiprocessing pool"
),
):
"""Compute the number of nodes and links from Ark dataset."""
dataset_dir.mkdir(parents=True, exist_ok=True)
time_range = DateTimeRange(
datetime.fromisoformat(time_range_start),
datetime.fromisoformat(time_range_stop),
)
# Download Ark files
ark_dataset(dataset_dir, credentials, time_range, cycle, processes)
# Compute nodes and links
nodes, links = ark_nodes_links(dataset_dir, time_range, cycle, processes)
typer.echo(f"Nodes: {len(nodes)}")
typer.echo(f"Links: {len(links)}")
@app.command()
def ripe(
time_range_start: str = typer.Option(
..., help="Time range start in isoformat (e.g., 2021-08-06T11:59:59)"
),
time_range_stop: str = typer.Option(
..., help="Time range end in isoformat (e.g., 2021-08-06T16:35:31)"
),
dataset_dir: Path = typer.Option(
Path("./data/ripe"), help="Directory where to store dataset"
),
processes: int = typer.Option(
None, help="Number of processes for the multiprocessing pool"
),
):
"""Compute the number of nodes and links from RIPE dataset."""
dataset_dir.mkdir(parents=True, exist_ok=True)
time_range = DateTimeRange(
datetime.fromisoformat(time_range_start),
datetime.fromisoformat(time_range_stop),
)
# Download RIPE files
ripe_dataset(dataset_dir, time_range, processes)
# Compute nodes and links
nodes, links = ripe_nodes_links(dataset_dir, time_range, processes)
typer.echo(f"Nodes: {len(nodes)}")
typer.echo(f"Links: {len(links)}")
if __name__ == "__main__":
app()