You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

84 lines
1.9 KiB

from read_db import get_from_db
import pickle
from treeplot import *
print("Loading")
DATA_CACHE = "treedata.b"
from pathlib import Path
import os
# data = {}
# path = "/home/alistair/Documents/UQ/"
# path = "/home/alistair/Documents/UQ/2023/COSC3000"
# path = "/run/media/alistair/storj/linux"
#
# for p in Path(path).glob("**"):
# size = os.path.getsize(p)
# p = tuple(x for x in str(p).split("/") if len(x) > 0)
# if len(p) == 0:
# continue
# data[p] = size
#
#
# for i in range(10000):
# if len({p[i+1:]:None}) == len(data):
# end = i
# break
# i = 0
# while len({k[i + 2 :]: None for k in data}) == len(data):
# i += 1
#
# data = {k[i:]: v for k, v in data.items()}
# clean = {}
# for p, size in data.items():
# clean[p] = DataFrame(p, size, size)
#
padding = 3
tm = None
if not os.path.exists(DATA_CACHE):
clean = get_from_db()
print("Building Tree")
map = TreeMap(clean)
print("MAP:", list(map.levels.values())[0:10])
tm = map.to_tree()
for x in list(tm.items())[0:8]:
print(x.weight)
tm = tm.pack(Rect(0, 0, WIDTH, HEIGHT), padding=padding)
for x in list(tm.items())[0:8]:
print(x.weight)
exit(1)
print("Setting labels")
for t in tm.items():
t.attribs["label"] = "/".join(t.path)
tm.attribs["label"] = "root"
print("Done.")
print("Saving to file", DATA_CACHE)
with open(DATA_CACHE, "wb") as f:
pickle.dump(tm, f)
else:
print("Loading from file", DATA_CACHE)
with open(DATA_CACHE, "rb") as f:
tm = pickle.load(f)
print("Packing tree")
tm: TreeMap = tm.pack(Rect(0, 0, WIDTH, HEIGHT), padding=padding)
print("Shrinking tree. Size:", tm.count_children())
tm = tm.trim(threshold=0.1)
print("New size:", tm.count_children())
tm: TreeMap = tm.pack(Rect(0, 0, WIDTH, HEIGHT), padding=padding)
rerooted = tm
parent = [rerooted]
child_frame = rerooted
levels = 3