Skip to content

Commit fa1a5fb

Browse files
committed
Deal with unexpected problems in data when calculating statistics, and fix some bugs
1 parent 46fd00b commit fa1a5fb

File tree

4 files changed

+75
-9
lines changed

4 files changed

+75
-9
lines changed

api/dashboard/js/cumulative-user-count.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ d3.json("/statistics/cumulative-user-count", function (error, data) {
5151
});
5252

5353
d3.json(
54-
"/statistics/cumulative-user-count?platform=BrainScaleS",
54+
"/statistics/cumulative-user-count?hardware_platform=BrainScaleS",
5555
function (error, data) {
5656
if (error) return console.warn(error);
5757

@@ -104,7 +104,7 @@ d3.json(
104104
);
105105

106106
d3.json(
107-
"/statistics/cumulative-user-count?platform=BrainScaleS-2",
107+
"/statistics/cumulative-user-count?hardware_platform=BrainScaleS-2",
108108
function (error, data) {
109109
if (error) return console.warn(error);
110110

@@ -157,7 +157,7 @@ d3.json(
157157
);
158158

159159
d3.json(
160-
"/statistics/cumulative-user-count?platform=SpiNNaker",
160+
"/statistics/cumulative-user-count?hardware_platform=SpiNNaker",
161161
function (error, data) {
162162
if (error) return console.warn(error);
163163

@@ -210,7 +210,7 @@ d3.json(
210210
);
211211

212212
d3.json(
213-
"/statistics/cumulative-user-count?platform=Spikey",
213+
"/statistics/cumulative-user-count?hardware_platform=Spikey",
214214
function (error, data) {
215215
if (error) return console.warn(error);
216216

api/simqueue/db.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ async def update_log(job_id, log, append=False):
291291

292292

293293
def get_list_filter(attr, value):
294-
if len(value) > 0:
294+
assert isinstance(value, list)
295+
if len(value) > 1:
295296
return attr.in_(value)
296297
else:
297298
return attr == value[0]

api/simqueue/resources/statistics.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ async def job_count(start: date = None, end: date = None, interval: int = 7):
5858
[
5959
(timestamp["timestamp_completion"].date() - start).days
6060
for timestamp in completion_timestamps
61+
if timestamp["timestamp_completion"]
6162
],
6263
dtype=int,
6364
)
@@ -178,6 +179,7 @@ async def job_duration(requested_max: int = None, n_bins: int = 50, scale: str =
178179
status=[status],
179180
hardware_platform=[platform],
180181
size=100000,
182+
fields=["timestamp_completion", "timestamp_submission"],
181183
)
182184

183185
durations = np.array(
@@ -236,7 +238,7 @@ async def cumulative_project_count(
236238

237239
submission_dates = [
238240
res["submission_date"]
239-
for res in await db.query_projects(fields=["submission_date"], status=status)
241+
for res in await db.query_projects(fields=["submission_date"], status=status, size=10000)
240242
]
241243

242244
submission_dates.append(date.today())
@@ -265,10 +267,16 @@ async def resource_usage(start: date = None, end: date = None, interval: int = 7
265267
fields=["timestamp_completion", "resource_usage"],
266268
)
267269
completed = np.array(
268-
[(job["timestamp_completion"].date() - start).days for job in completed_jobs],
270+
[
271+
(job["timestamp_completion"].date() - start).days
272+
for job in completed_jobs
273+
if job["timestamp_completion"]
274+
],
269275
dtype=int,
270276
)
271-
usage_per_job = np.array([job["resource_usage"] for job in completed_jobs])
277+
usage_per_job = np.array(
278+
[job["resource_usage"] for job in completed_jobs if job["timestamp_completion"]]
279+
)
272280
index = completed // interval
273281
usage_per_interval[platform] = np.zeros((n_bins,))
274282
for i, usage in zip(index, usage_per_job):
@@ -281,6 +289,7 @@ async def resource_usage(start: date = None, end: date = None, interval: int = 7
281289
interval_end = interval_start + timedelta(interval)
282290
for platform in STANDARD_QUEUES:
283291
usage_cumul[platform] += usage_per_interval[platform][i]
284-
new_obj = {"start": interval_start, "end": interval_end, "value": usage_cumul}
292+
new_obj = {"start": interval_start, "end": interval_end, "value": usage_cumul.copy()}
285293
results.append(new_obj)
294+
286295
return results

api/simqueue/tests/test_statistics_router.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,28 @@
1212
"timestamp_completion": datetime.fromisoformat("2022-10-03T02:44:28+00:00"),
1313
"user_id": "haroldlloyd",
1414
"status": "finished",
15+
"resource_usage": 7.07,
1516
},
1617
{
1718
"timestamp_submission": datetime.fromisoformat("2022-10-11T02:44:23+00:00"),
1819
"timestamp_completion": datetime.fromisoformat("2022-10-11T02:44:38+00:00"),
1920
"user_id": "charliechaplin",
2021
"status": "finished",
22+
"resource_usage": 13.13,
2123
},
2224
{
2325
"timestamp_submission": datetime.fromisoformat("2022-10-12T02:44:23+00:00"),
2426
"timestamp_completion": datetime.fromisoformat("2022-10-12T02:44:28+00:00"),
2527
"user_id": "haroldlloyd",
2628
"status": "finished",
29+
"resource_usage": 19.19,
2730
},
2831
{
2932
"timestamp_submission": datetime.fromisoformat("2022-10-16T02:44:23+00:00"),
3033
"timestamp_completion": datetime.fromisoformat("2022-10-16T02:44:48+00:00"),
3134
"user_id": "haroldlloyd",
3235
"status": "error",
36+
"resource_usage": 23.23,
3337
},
3438
]
3539

@@ -206,3 +210,55 @@ def test_job_duration(mocker):
206210
"max": 30,
207211
},
208212
]
213+
214+
215+
def test_resource_usage(mocker):
216+
mocker.patch("simqueue.db.query_jobs", mock_query_jobs)
217+
response = client.get("/statistics/resource-usage?interval=7&start=2022-10-01&end=2022-10-28")
218+
assert response.status_code == 200
219+
assert response.json() == [
220+
{
221+
"start": "2022-10-01",
222+
"end": "2022-10-08",
223+
"value": {
224+
"BrainScaleS": 0.0,
225+
"BrainScaleS-ESS": 0.0,
226+
"Spikey": 0.0,
227+
"SpiNNaker": 7.07,
228+
"BrainScaleS-2": 0.0,
229+
},
230+
},
231+
{
232+
"start": "2022-10-08",
233+
"end": "2022-10-15",
234+
"value": {
235+
"BrainScaleS": 0.0,
236+
"BrainScaleS-ESS": 0.0,
237+
"Spikey": 0.0,
238+
"SpiNNaker": 39.39,
239+
"BrainScaleS-2": 0.0,
240+
},
241+
},
242+
{
243+
"start": "2022-10-15",
244+
"end": "2022-10-22",
245+
"value": {
246+
"BrainScaleS": 0.0,
247+
"BrainScaleS-ESS": 0.0,
248+
"Spikey": 0.0,
249+
"SpiNNaker": 62.620000000000005,
250+
"BrainScaleS-2": 0.0,
251+
},
252+
},
253+
{
254+
"start": "2022-10-22",
255+
"end": "2022-10-29",
256+
"value": {
257+
"BrainScaleS": 0.0,
258+
"BrainScaleS-ESS": 0.0,
259+
"Spikey": 0.0,
260+
"SpiNNaker": 62.620000000000005,
261+
"BrainScaleS-2": 0.0,
262+
},
263+
},
264+
]

0 commit comments

Comments
 (0)