-
-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathtasks.py
More file actions
164 lines (141 loc) · 4.02 KB
/
Copy pathtasks.py
File metadata and controls
164 lines (141 loc) · 4.02 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
from collections.abc import Sequence
from typing import TYPE_CHECKING, cast
from sqlalchemy import Row, text
from routers.types import Identifier
if TYPE_CHECKING:
from sqlalchemy.ext.asyncio import AsyncConnection
async def get(id_: Identifier, 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: Identifier, 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_task_type_name(task_id: int, expdb: AsyncConnection) -> str | None:
"""Fetch the human-readable task type name for the task associated with a run.
Joins `task` and `task_type` on `ttid` to resolve the name
(e.g. "Supervised Classification").
"""
row = await expdb.execute(
text(
"""
SELECT `tt`.`name`
FROM `task` `t`
JOIN `task_type` `tt` ON `t`.`ttid` = `tt`.`ttid`
WHERE `t`.`task_id` = :task_id
""",
),
parameters={"task_id": task_id},
)
result = row.one_or_none()
return result.name if result else None
async def get_task_evaluation_measure(task_id: int, expdb: AsyncConnection) -> str | None:
"""Fetch the evaluation measure configured for a task, if any.
Queries `task_inputs` for the row where `input = 'evaluation_measures'`.
Returns None (not an empty string) when no such row exists, so callers
can treat a falsy result uniformly.
"""
row = await expdb.execute(
text(
"""
SELECT `value`
FROM `task_inputs`
WHERE `task_id` = :task_id
AND `input` = 'evaluation_measures'
""",
),
parameters={"task_id": task_id},
)
result = row.one_or_none()
return result.value if result else 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_: Identifier, 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: Identifier,
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_: Identifier, 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]