Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. General的建议
  2.     1. handout里废话很少,但是排版很乱,所以如果卡在某个地方,学会用搜索功能,找到提到这个地方的内容,一般比较绕的地方都能找到解释和example;比如说update_rectangles的算法和流程,这个要看清楚handout上的流程
  3.     2. 每完成一个task, 记得做Progress check,测试你确实完成了这个task
  4.     3. 如果卡住了,而且找不到handout上的内容,看一下demo视频,你也许会有新的灵感;还没有灵感,在piazza上搜索卡住的function名,说不定之前有同学已经碰到了类似的坑
  5.  
  6. Task 2的坑
  7.     1. update_rectangles里那个for loop里,只要loop到subtrees[-2]为止, 最后一个subtree直接占满所有【剩下】的rect范围
  8.     2. recursion之后,别忘了update下一个subtree的开始x、y轴
  9.     3. treemap_visualiser.py里所有Task 2,需要uncomment掉一些东西才能正确跑起来
  10.  
  11. Task 3
  12.     1. get_tree_at_position
  13.         a. base case: 当是leaf并在pos的范围内,直接return self
  14.         b. for i in subtree,如果pos在i的rect范围里, pos的格式是(x, y), 则直接return i.get_tree_at_position(pos)
  15.         c. 因为你要一层一层的找下去,比如说最外面那层文件夹是(0, 0, 100, 100),然后里面有个文件是(0, 0, 2, 2),然后你的pos是(1, 1), 那个你return的应该是(0, 0, 2, 2)这个rect对应的tree
  16.     2. treemap_visualiser.py里所有Task 3,需要uncomment掉一些东西才能正确跑起来
  17.  
  18. Task 4
  19.     1. change_size
  20.         a. base case: 当有subtree时,啥都不做
  21.         b. self.data_size = self.data_size + math.ceil(self.data_size * factor)
  22.         c. 注意,这里有坑(math.ceil),请你在python里测试当factor是0.01和-0.01出来的data_size的结果分别是什么,并对b作出更改
  23.     2. move
  24.         a. base case: 当不满足(If this tree is a leaf, and <destination> is not a leaf)这个条件是,啥都不做
  25.         b. 把self._parent_tree._subtrees里的self remove掉
  26.         c. destination._subtrees append self
  27.         d. 改变self._parent_tree到destination
  28.         c. 注意,这个在没有写完task 5的时候是不好测试的
  29.     3. update_data_sizes
  30.         a. 当empty或者是leaf的情况,loop self._parent_tree._subtrees 并把所有subtree的size加起来,让self._parent_tree.data_size等于这个size, 并把self.data_size return出来
  31.         b. 否则,直接loop self.subtree, 然后recursively call update_data_sizes
  32.         c. 最后return self.data_size
  33.     4. treemap_visualiser.py里所有Task 4,需要uncomment掉一些东西才能正确跑起来
  34.  
  35.  
  36. Task 5
  37.     0. 开始Task 5之前请确保之前的task都已经测试没有问题
  38.     1. 需要做改动的method如下:__init__, get_rectangles, get_tree_at_position, 基本上都会用到self._expanded, 需要做的改动很小,基本上都是加一个判断就够了
  39.     2. expand
  40.         a. 当有subtree时,直接self._expand = True
  41.     3. expand_all
  42.         a. 首先expand自己
  43.         b. recursively expand所有自己的subtree
  44.     4. collapse
  45.         a. expand相反的操作
  46.     5. collapse_all
  47.         a. 这条题比较灵活,提供一个思路
  48.         b. 首先找到最上层的parent(与linklistd的traversal类似)
  49.         c. 写一个helper function, take a node, 然后如果这个node没有subtree, 直接call collapse(); 否则loop这个node的subtree, 并recursively call这个helper function, 把subtree丢进去
  50.         d. call part c写的按个helper function, 然后把最上层的parent丢进去
  51.         e. 最后让最上层的_expanded设为False
  52.     6. treemap_visualiser.py里所有Task 4,需要uncomment掉一些东西才能正确跑起来
  53.  
  54. //////
  55.  
  56. 1首先定义class mttree filesystem tree 根据doc写出来 会用到 os.path那些
  57. 第一,是不是文件夹
  58. 第二,传入string返回list,返回下面文件的名字stringlist(并不是所有文件,只是下面的child)
  59. 第三,文件路径加,两个路径不能直接加,mac和windows的表达方式不一样,不要用加法只用join
  60. 第四,获取文件大小
  61. 第五,basename传入一个路径,获取文件的文件名例如传入../abc.txt 返回 abc.txt用它检测对应的文件名
  62.  
  63.  
  64. 如果文件夹是size是0return list如果它是一个leaf的话,他肯定是一个文件,data size就是文件的大小,如果与一个或者多个subtree,它的大小是一个或者多个文件的总大小
  65. Update size一个文件的同时也要update parent size
  66. 一个文件是它的base name不是完整的path
  67.  
  68. Color = (random,randint(0,255),xxx,xxx)
  69.  
  70. self.data_size = loop sum
  71. loop的同时把他们的parent tree set成之前的
  72. For I in self.subtrees
  73. i.parent = self
  74.  
  75. 记得要un common掉v的东西不然测不出来
  76.  
  77.  
  78.  
  79. 给你一个path
  80. 判断是不是文件
  81. Base 文件
  82. super().init(name,subtrees, data_size)
  83.  
  84. Case 2文件夹
  85. List
  86. For I in 这个文件夹下的文件
  87.  list.append(Filesystem(path)) //joined path  当前path + I
  88.  
  89.  
  90. Task2
  91. 算法
  92. 如果tree size 0
  93. 是base case(leaf)
  94. 当是文件的时候 self.rect = rect
  95. 当是文件夹的时候
  96.  
  97. For I in subtrees
  98. x y width height = rect
  99.  
  100. 这个tuple有坑,
  101. i.data_size / self.data_size = scale
  102. 用这个比例x width
  103. 如果width >= height
  104. H = height;
  105. 否则
  106. W = width
  107. Height = 比例 x height
  108.  
  109. I update trangle()
  110.  
  111.  
  112. GetRectangle
  113. 找到所有leaf 然后
  114. Base case file/leave
  115. Return (self, rect,self_coor ,)
  116. 记得加逗号
  117.  
  118. List = []
  119. For I in self.subtree
  120. list.extend(i.getRect())
  121. Return list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement