block.py: add progress reporting based on num_chunks
We don't know the number of blocks on each chunk beforehand, but we know the number of chunks which is precise enough for a status report. Also use a wall clock to give an eta for the conversion. See #6
This commit is contained in:
parent
9e9aa02b23
commit
37f3f33bf2
23
block.py
23
block.py
@ -1,7 +1,9 @@
|
|||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import zlib
|
import zlib
|
||||||
import nbt
|
import nbt
|
||||||
import random
|
import random
|
||||||
|
import time
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from serialize import *
|
from serialize import *
|
||||||
@ -36,16 +38,29 @@ class MCMap:
|
|||||||
if bytesToInt(f.read(3)) != 0:
|
if bytesToInt(f.read(3)) != 0:
|
||||||
self.chunk_pos.append((chkx, chkz))
|
self.chunk_pos.append((chkx, chkz))
|
||||||
chunkCountb += 1
|
chunkCountb += 1
|
||||||
# print('Total Chunks: ' + str(len(self.chunk_pos)))
|
|
||||||
|
|
||||||
def getChunk(self, chkx, chkz):
|
def getChunk(self, chkx, chkz):
|
||||||
return MCChunk(chkx, chkz, self.world_path, self.ext)
|
return MCChunk(chkx, chkz, self.world_path, self.ext)
|
||||||
|
|
||||||
def getBlocksIterator(self):
|
def getBlocksIterator(self):
|
||||||
|
num_chunks = len(self.chunk_pos)
|
||||||
|
chunk_ix = 0
|
||||||
|
t0 = time.time()
|
||||||
for chkx, chkz in self.chunk_pos:
|
for chkx, chkz in self.chunk_pos:
|
||||||
|
if chunk_ix%10 == 0:
|
||||||
|
if chunk_ix > 0:
|
||||||
|
td = time.time() - t0 # wall clock time spent
|
||||||
|
tr = ((num_chunks * td) / chunk_ix) - td # time remaining
|
||||||
|
eta = time.strftime("%H:%M:%S", time.gmtime(tr))
|
||||||
|
else:
|
||||||
|
eta = "??:??:??"
|
||||||
|
print('Processed %d / %d chunks, ETA %s h:m:s' % (chunk_ix, num_chunks, eta), end='\r')
|
||||||
|
sys.stdout.flush()
|
||||||
|
chunk_ix += 1
|
||||||
blocks = self.getChunk(chkx, chkz).blocks
|
blocks = self.getChunk(chkx, chkz).blocks
|
||||||
for block in blocks:
|
for block in blocks:
|
||||||
yield block
|
yield block
|
||||||
|
print()
|
||||||
|
|
||||||
class MCChunk:
|
class MCChunk:
|
||||||
"""A 16x16 column of nodes"""
|
"""A 16x16 column of nodes"""
|
||||||
@ -414,8 +429,8 @@ class MTBlock:
|
|||||||
# Node timer
|
# Node timer
|
||||||
writeU8(os, 2+4+4) # Timer data len
|
writeU8(os, 2+4+4) # Timer data len
|
||||||
writeU16(os, len(self.timers)) # Number of timers
|
writeU16(os, len(self.timers)) # Number of timers
|
||||||
if len(self.timers) > 0:
|
#if len(self.timers) > 0:
|
||||||
print('wrote ' + str(len(self.timers)) + ' node timers')
|
# print('wrote ' + str(len(self.timers)) + ' node timers')
|
||||||
for i in range(len(self.timers)):
|
for i in range(len(self.timers)):
|
||||||
writeU16(os, self.timers[i][0])
|
writeU16(os, self.timers[i][0])
|
||||||
writeU32(os, self.timers[i][1])
|
writeU32(os, self.timers[i][1])
|
||||||
@ -452,7 +467,7 @@ class MTMap:
|
|||||||
num_saved = 0
|
num_saved = 0
|
||||||
for block in self.blocks:
|
for block in self.blocks:
|
||||||
if num_saved%100 == 0:
|
if num_saved%100 == 0:
|
||||||
print("Saved", num_saved, "blocks")
|
#print("Saved", num_saved, "blocks")
|
||||||
conn.commit()
|
conn.commit()
|
||||||
num_saved += 1
|
num_saved += 1
|
||||||
cur.execute("INSERT INTO blocks VALUES (?,?)",
|
cur.execute("INSERT INTO blocks VALUES (?,?)",
|
||||||
|
Loading…
Reference in New Issue
Block a user