Compare commits
1
Commits
40d53cbb66
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4eb2566c7 |
Generated
+10
@@ -0,0 +1,10 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Ignored default folder with query files
|
||||
/queries/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="25" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/main.iml" filepath="$PROJECT_DIR$/main.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -24,8 +24,6 @@ public class DownloadWorker implements Runnable {
|
||||
chunkStatus.setStartTimeMs(System.currentTimeMillis());
|
||||
double downloaded = 0.0;
|
||||
|
||||
System.out.println("Chunk " + chunkStatus.getChunkId() + " started downloading.");
|
||||
|
||||
while (downloaded < chunkStatus.getChunkSizeMB()) {
|
||||
try {
|
||||
int delay = config.getMinStepDelayMs()
|
||||
@@ -50,7 +48,6 @@ public class DownloadWorker implements Runnable {
|
||||
}
|
||||
chunkStatus.setCompleted(true);
|
||||
chunkStatus.setEndTimeMs(System.currentTimeMillis());
|
||||
System.out.println("[Worker-" + chunkStatus.getChunkId() + "] Download completed.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,16 +16,7 @@ public class ProgressMonitor implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// TODO:
|
||||
// Repeatedly check chunk progress until all chunks are completed.
|
||||
// In each loop:
|
||||
// 1. Read the downloaded size from every chunk
|
||||
// 2. Add all downloaded amounts to totalDownloadedMB
|
||||
// 3. Count completed chunks
|
||||
// 4. Print a progress message
|
||||
// 5. If completedChunks == chunks.size(), print a final monitor message and stop
|
||||
// 6. Otherwise sleep for monitorDelayMs and continue
|
||||
|
||||
long startTimeMs = System.currentTimeMillis();
|
||||
|
||||
while (true) {
|
||||
double totalDownloadedMB = 0.0;
|
||||
@@ -33,29 +24,49 @@ public class ProgressMonitor implements Runnable {
|
||||
|
||||
for (ChunkStatus chunk : chunks) {
|
||||
totalDownloadedMB += chunk.getDownloadedMB();
|
||||
|
||||
if (chunk.isCompleted()) {
|
||||
completedChunks++;
|
||||
}
|
||||
}
|
||||
|
||||
double percent = 0.0;
|
||||
if (totalSizeMB > 0) {
|
||||
percent = (totalDownloadedMB * 100.0) / totalSizeMB;
|
||||
}
|
||||
long elapsedMs = System.currentTimeMillis() - startTimeMs;
|
||||
double elapsedSeconds = elapsedMs / 1000.0;
|
||||
|
||||
double speedMBps = elapsedSeconds > 0.0
|
||||
? totalDownloadedMB / elapsedSeconds
|
||||
: 0.0;
|
||||
|
||||
double percent = totalSizeMB > 0
|
||||
? totalDownloadedMB * 100.0 / totalSizeMB
|
||||
: 100.0;
|
||||
percent = Math.max(0.0, Math.min(100.0, percent));
|
||||
|
||||
double remainingMB = Math.max(0.0, totalSizeMB - totalDownloadedMB);
|
||||
long etaSeconds = speedMBps > 0.0
|
||||
? (long) Math.ceil(remainingMB / speedMBps)
|
||||
: 0L;
|
||||
|
||||
int barWidth = 40;
|
||||
int filled = (int) Math.round(percent / 100.0 * barWidth);
|
||||
filled = Math.max(0, Math.min(barWidth, filled));
|
||||
|
||||
String bar = "#".repeat(filled) + "-".repeat(barWidth - filled);
|
||||
|
||||
System.out.printf(
|
||||
"Progress for %s: %.1f/%.1f MB (%.2f%%), completed chunks: %d/%d%n",
|
||||
fileName,
|
||||
totalDownloadedMB,
|
||||
(double) totalSizeMB,
|
||||
"\r[%s] %6.2f%% %7.1f/%d MB | %6.2f MB/s | ETA %s | chunks %d/%d",
|
||||
bar,
|
||||
percent,
|
||||
totalDownloadedMB,
|
||||
totalSizeMB,
|
||||
speedMBps,
|
||||
formatEta(etaSeconds),
|
||||
completedChunks,
|
||||
chunks.size()
|
||||
);
|
||||
|
||||
System.out.flush();
|
||||
|
||||
if (completedChunks == chunks.size()) {
|
||||
System.out.println();
|
||||
System.out.println("All chunks completed.");
|
||||
break;
|
||||
}
|
||||
@@ -63,9 +74,22 @@ public class ProgressMonitor implements Runnable {
|
||||
try {
|
||||
Thread.sleep(monitorDelayMs);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
System.out.println();
|
||||
System.out.println("Progress monitor interrupted.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String formatEta(long totalSeconds) {
|
||||
long minutes = totalSeconds / 60;
|
||||
long seconds = totalSeconds % 60;
|
||||
|
||||
if (minutes > 0) {
|
||||
return String.format("%dm %02ds", minutes, seconds);
|
||||
}
|
||||
|
||||
return String.format("%ds", seconds);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user