Skip to content

Commit 5260805

Browse files
authored
🚑 Fixes calculation for average processing time (#82)
The AdGuard Home API returns the value in seconds. To correctly convert that value into milliseconds, the multiplication should be 1000.
1 parent 49e4d39 commit 5260805

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

adguardhome/stats.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async def replaced_safesearch(self) -> int:
4545
async def avg_processing_time(self) -> float:
4646
"""Return avarage processing time of DNS queries (in ms)."""
4747
response = await self._adguard._request("stats")
48-
return round(response["avg_processing_time"] * 100, 2)
48+
return round(response["avg_processing_time"] * 1000, 2)
4949

5050
async def period(self) -> int:
5151
"""Return the time period to keep data (in days)."""

tests/test_stats.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,13 @@ async def test_avg_processing_time(aresponses):
153153
aresponses.Response(
154154
status=200,
155155
headers={"Content-Type": "application/json"},
156-
text='{"avg_processing_time": 0.0314}',
156+
text='{"avg_processing_time": 0.03141}',
157157
),
158158
)
159159
async with aiohttp.ClientSession() as session:
160160
adguard = AdGuardHome("example.com", session=session)
161161
result = await adguard.stats.avg_processing_time()
162-
assert result == 3.14
162+
assert result == 31.41
163163

164164

165165
@pytest.mark.asyncio
@@ -215,10 +215,10 @@ async def test_content_type_workarond(aresponses):
215215
aresponses.Response(
216216
status=200,
217217
headers={"Content-Type": "text/plain; charset=utf-8"},
218-
text='{"avg_processing_time": 0.0314}',
218+
text='{"avg_processing_time": 0.03141}',
219219
),
220220
)
221221
async with aiohttp.ClientSession() as session:
222222
adguard = AdGuardHome("example.com", session=session)
223223
result = await adguard.stats.avg_processing_time()
224-
assert result == 3.14
224+
assert result == 31.41

0 commit comments

Comments
 (0)