🐛 fix: Updated AvgSpeed class to clear old data points and adjust download speed in test cases.
This commit is contained in:
parent
95481b89f0
commit
7098065704
3 changed files with 15 additions and 10 deletions
|
|
@ -65,7 +65,7 @@ public class AvgSpeed {
|
||||||
|
|
||||||
// Remove old points outside the interval
|
// Remove old points outside the interval
|
||||||
long cutoffTime = timestamp - interval * 1000L; // Convert interval to milliseconds
|
long cutoffTime = timestamp - interval * 1000L; // Convert interval to milliseconds
|
||||||
speedPoints.headMap(cutoffTime);
|
speedPoints.headMap(cutoffTime).clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private long calculateSpeed(long downloadedSize, long timestamp) {
|
private long calculateSpeed(long downloadedSize, long timestamp) {
|
||||||
|
|
|
||||||
|
|
@ -46,8 +46,8 @@ class AvgSpeedTest {
|
||||||
|
|
||||||
|
|
||||||
// Download at 100 bytes/sec
|
// Download at 100 bytes/sec
|
||||||
avgSpeed.update(0L, baseTime);
|
avgSpeed.update(1L, baseTime);
|
||||||
avgSpeed.update(1000L, baseTime + 10000); // 100 bytes/sec
|
avgSpeed.update(1001L, baseTime + 10000); // 100 bytes/sec
|
||||||
|
|
||||||
// Pause for 10 seconds
|
// Pause for 10 seconds
|
||||||
avgSpeed.update(1000L, baseTime + 20000);
|
avgSpeed.update(1000L, baseTime + 20000);
|
||||||
|
|
@ -66,12 +66,12 @@ class AvgSpeedTest {
|
||||||
|
|
||||||
|
|
||||||
// Initial download
|
// Initial download
|
||||||
avgSpeed.update(0L, baseTime);
|
avgSpeed.update(1L, baseTime);
|
||||||
avgSpeed.update(1000L, baseTime + 10000); // 100 bytes/sec
|
avgSpeed.update(1001L, baseTime + 10000); // 100 bytes/sec
|
||||||
|
|
||||||
// Restart download
|
// Restart download
|
||||||
avgSpeed.update(0L, baseTime + 15000);
|
avgSpeed.update(1L, baseTime + 15000);
|
||||||
avgSpeed.update(500L, baseTime + 20000); // 100 bytes/sec after restart
|
avgSpeed.update(501L, baseTime + 20000); // 100 bytes/sec after restart
|
||||||
|
|
||||||
AvgSpeed.SpeedStats stats = avgSpeed.getSpeedStats();
|
AvgSpeed.SpeedStats stats = avgSpeed.getSpeedStats();
|
||||||
assertTrue(stats.maxSpeed() >= 100,
|
assertTrue(stats.maxSpeed() >= 100,
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@ import {
|
||||||
} from "@/components/ui/card";
|
} from "@/components/ui/card";
|
||||||
import { request } from "@/lib/api";
|
import { request } from "@/lib/api";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import Lottie from "lottie-react";
|
|
||||||
import TGDuck16HeyOut from "@/components/animations/tg-duck16_hey_out.json";
|
import TGDuck16HeyOut from "@/components/animations/tg-duck16_hey_out.json";
|
||||||
|
import dynamic from "next/dynamic";
|
||||||
|
|
||||||
interface VersionData {
|
interface VersionData {
|
||||||
version: string;
|
version: string;
|
||||||
|
|
@ -23,6 +23,7 @@ interface GitHubReleaseData {
|
||||||
|
|
||||||
const fetcher = (url: string) => fetch(url).then((res) => res.json());
|
const fetcher = (url: string) => fetch(url).then((res) => res.json());
|
||||||
|
|
||||||
|
const Lottie = dynamic(() => import("lottie-react"), { ssr: false });
|
||||||
export default function About() {
|
export default function About() {
|
||||||
const { data: apiData, error: apiError } = useSWR<VersionData, Error>(
|
const { data: apiData, error: apiError } = useSWR<VersionData, Error>(
|
||||||
"/version",
|
"/version",
|
||||||
|
|
@ -46,7 +47,7 @@ export default function About() {
|
||||||
githubData && githubData.tag_name !== currentVersion;
|
githubData && githubData.tag_name !== currentVersion;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex justify-center md:items-center md:h-full">
|
<div className="flex justify-center md:h-full md:items-center">
|
||||||
<Card className="w-full bg-[radial-gradient(ellipse_at_bottom_left,_var(--tw-gradient-stops))] from-[#7900ff] via-[#548cff] to-[#93ffd8] md:w-1/2">
|
<Card className="w-full bg-[radial-gradient(ellipse_at_bottom_left,_var(--tw-gradient-stops))] from-[#7900ff] via-[#548cff] to-[#93ffd8] md:w-1/2">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="text-white">About This Project</CardTitle>
|
<CardTitle className="text-white">About This Project</CardTitle>
|
||||||
|
|
@ -55,7 +56,11 @@ export default function About() {
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="relative">
|
<CardContent className="relative">
|
||||||
<Lottie className="absolute bottom-3 right-3 w-28 h-28" animationData={TGDuck16HeyOut} loop={true} />
|
<Lottie
|
||||||
|
className="absolute bottom-3 right-3 h-28 w-28"
|
||||||
|
animationData={TGDuck16HeyOut}
|
||||||
|
loop={true}
|
||||||
|
/>
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div className="flex flex-col items-center justify-center">
|
<div className="flex flex-col items-center justify-center">
|
||||||
<p className="text-sm font-medium text-white">Author</p>
|
<p className="text-sm font-medium text-white">Author</p>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue