forked from openml/server-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.py
More file actions
142 lines (123 loc) · 3.26 KB
/
tasks.py
File metadata and controls
142 lines (123 loc) · 3.26 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from collections.abc import Sequence
from typing import cast
from sqlalchemy import Row, RowMapping, text
from sqlalchemy.ext.asyncio import AsyncConnection
ALLOWED_LOOKUP_TABLES = ["estimation_procedure", "evaluation_measure", "task_type", "dataset"]
PK_MAPPING = {
"task_type": "ttid",
"dataset": "did",
}
async def get(id_: int, expdb: AsyncConnection) -> Row | None:
row = await expdb.execute(
text(
"""
SELECT *
FROM task
WHERE `task_id` = :task_id
""",
),
parameters={"task_id": id_},
)
return row.one_or_none()
async def get_task_types(expdb: AsyncConnection) -> Sequence[Row]:
rows = await expdb.execute(
text(
"""
SELECT `ttid`, `name`, `description`, `creator`
FROM task_type
""",
),
)
return cast(
"Sequence[Row]",
rows.all(),
)
async def get_task_type(task_type_id: int, expdb: AsyncConnection) -> Row | None:
row = await expdb.execute(
text(
"""
SELECT *
FROM task_type
WHERE `ttid`=:ttid
""",
),
parameters={"ttid": task_type_id},
)
return row.one_or_none()
async def get_input_for_task_type(task_type_id: int, expdb: AsyncConnection) -> Sequence[Row]:
rows = await expdb.execute(
text(
"""
SELECT *
FROM task_type_inout
WHERE `ttid`=:ttid AND `io`='input'
""",
),
parameters={"ttid": task_type_id},
)
return cast(
"Sequence[Row]",
rows.all(),
)
async def get_input_for_task(id_: int, expdb: AsyncConnection) -> Sequence[Row]:
rows = await expdb.execute(
text(
"""
SELECT `input`, `value`
FROM task_inputs
WHERE task_id = :task_id
""",
),
parameters={"task_id": id_},
)
return cast(
"Sequence[Row]",
rows.all(),
)
async def get_task_type_inout_with_template(
task_type: int,
expdb: AsyncConnection,
) -> Sequence[Row]:
rows = await expdb.execute(
text(
"""
SELECT *
FROM task_type_inout
WHERE `ttid`=:ttid AND `template_api` IS NOT NULL
""",
),
parameters={"ttid": task_type},
)
return cast(
"Sequence[Row]",
rows.all(),
)
async def get_tags(id_: int, expdb: AsyncConnection) -> list[str]:
rows = await expdb.execute(
text(
"""
SELECT `tag`
FROM task_tag
WHERE `id` = :task_id
""",
),
parameters={"task_id": id_},
)
tag_rows = rows.all()
return [row.tag for row in tag_rows]
async def get_lookup_data(table: str, id_: int, expdb: AsyncConnection) -> RowMapping | None:
if table not in ALLOWED_LOOKUP_TABLES:
msg = f"Table {table} is not allowed for lookup."
raise ValueError(msg)
pk = PK_MAPPING.get(table, "id")
result = await expdb.execute(
text(
f"""
SELECT *
FROM {table}
WHERE `{pk}` = :id_
""", # noqa: S608
),
parameters={"id_": id_},
)
return result.mappings().one_or_none()