From 47bd94ec66cc92ac182d86108c5627c960a3d959 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Fri, 28 Sep 2012 16:02:41 +0000 Subject: show score by palette --- diff --git a/pysamples/ta-stats.py b/pysamples/ta-stats.py index f8002a7..c4305ac 100755 --- a/pysamples/ta-stats.py +++ b/pysamples/ta-stats.py @@ -39,6 +39,9 @@ def myblock(tw, x): # ignore second argument for dsobj in dsobjs: if not isactivity(dsobj) == 'TurtleArtActivity': continue + if hascomponent(dsobj, 'mime_type') != \ + 'application/x-turtle-art': + continue score = hasturtleblocks(dsobj) if score: self._score.append(score) @@ -92,7 +95,7 @@ def myblock(tw, x): # ignore second argument 'ifelse': 'ifthen', 'while': 'ifthen', 'until': 'ifthen', 'hat': 'action', 'stack': 'action', 'storein': 'box', 'box': 'box', 'luminance': 'sensor', 'mousex': 'sensor', 'mousey': 'sensor', - 'moousebutton2': 'sensor', 'keyboard': 'sensor', 'kbinput': 'sensor', + 'mousebutton2': 'sensor', 'keyboard': 'sensor', 'kbinput': 'sensor', 'readpixel': 'sensor', 'see': 'sensor', 'time': 'sensor', 'sound': 'sensor', 'volume': 'sensor', 'pitch': 'sensor', 'resistance': 'sensor', 'voltage': 'sensor', 'video': 'media', @@ -105,13 +108,12 @@ def myblock(tw, x): # ignore second argument 'clearheap':'extras', 'isheapempty2':'extras', 'chr':'extras', 'int':'extras', 'myfunction': 'python', 'userdefined': 'python', 'loadblock': 'python', 'loadpalette': 'python'} - TAPAL = {'forward': 'turtlep', 'arc': 'turtlep', 'coord': 'turtlep', 'setxy': 'turtlep', 'pen': 'penp', 'fill': 'penp', 'number': 'numberp', - 'boolean': 'numberp', 'repeat': 'flowp', 'ifthen': 'flowp', - 'action': 'boxp', 'box': 'boxp', 'sensor': 'sensorp', - 'media': 'mediap', 'extras': 'extrasp', 'python': 'extrasp'} - + 'random': 'numberp', 'boolean': 'numberp', 'repeat': 'flowp', + 'ifthen': 'flowp', 'action': 'boxp', 'box': 'boxp', + 'sensor': 'sensorp', 'media': 'mediap', 'extras': 'extrasp', + 'python': 'extrasp'} TASCORE = {'forward': 3, 'arc': 3, 'setxy': 2.5, 'coord': 4, 'turtlep': 5, 'pen': 2.5, 'fill': 2.5, 'penp': 5, 'number': 2.5, 'boolean': 2.5, 'random': 2.5, 'numberp': 0, @@ -120,7 +122,8 @@ def myblock(tw, x): # ignore second argument 'media': 5, 'mediap': 0, 'python': 5, 'extras': 5, 'extrasp': 0, 'sensor': 5, 'sensorp': 0} - + PALS = ['turtlep', 'penp', 'numberp', 'flowp', 'boxp', 'sensorp', 'mediap', + 'extrasp'] def hasturtleblocks(path): ''' Parse turtle block data and generate score based on rubric ''' @@ -136,7 +139,9 @@ def myblock(tw, x): # ignore second argument token = tokens[1].strip('" [') blocks.append(token) - score = 0 + score = [] + for i in range(len(PALS)): + score.append(0) cats = [] pals = [] @@ -151,17 +156,19 @@ def myblock(tw, x): # ignore second argument for c in cats: if c in TASCORE: - score += TASCORE[c] + score[PALS.index(TAPAL[c])] += TASCORE[c] for p in pals: if p in TASCORE: - score += TASCORE[p] + score[PALS.index(p)] += TASCORE[p] - return str(score) + return score data = ParseJournal() - for a in data._score: - tw.lc.heap.append(float(a)) + n = min(40, len(data._score) / len(PALS)) + for i in range(n): + for j in range(len(PALS)): + tw.lc.heap.append(data._score[(n - i - 1)][len(PALS) - j - 1]) - tw.lc.heap.append(len(data._score)) + tw.lc.heap.append(n) return diff --git a/samples/media-turtle-stats.ta b/samples/media-turtle-stats.ta index 41f4b26..269b818 100644 --- a/samples/media-turtle-stats.ta +++ b/samples/media-turtle-stats.ta @@ -1,31 +1,86 @@ -[[0, ["start", 2.0], 397, 40, [null, 1]], -[1, ["userdefined", "pysamples/ta-stats.py"], 397, 86, [0, 2, 4]], -[2, ["number", 100], 455, 86, [1, null]], -[3, "pop", 465, 170, [4, null]], -[4, ["storein", 0], 397, 128, [1, 5, 3, 24]], -[5, ["string", "my box"], 465, 128, [4, null]], -[6, "box", 163, 239, [14, 7, null]], -[7, ["string", "my box"], 218, 239, [6, null]], -[8, "leftpos", 455, 296, [9, null]], -[9, ["setxy2", 0], 397, 296, [11, 8, 18, 12]], -[10, "forward", 122, 281, [14, 17, 13]], -[11, "penup", 397, 254, [24, 9]], -[12, "pendown", 397, 380, [9, 28]], -[13, ["setxy2", 20], 122, 323, [10, 16, 19, null]], -[14, ["repeat", 62], 104, 239, [26, 6, 10, null]], -[15, "xcor", 234, 323, [16, null]], -[16, ["plus2", 0], 180, 323, [13, 15, 23]], -[17, "pop", 193, 281, [10, null]], -[18, ["number", 0.0], 455, 338, [9, null]], -[19, ["number", 0.0], 180, 405, [13, null]], -[20, "box", 577, 254, [25, 21, null]], -[21, ["string", "my box"], 632, 254, [20, null]], -[22, "width", 553, 212, [25, null]], -[23, "pensize", 234, 365, [16, null]], -[24, "setpensize", 397, 212, [4, 25, 11]], -[25, ["division2", 0], 499, 212, [24, 22, 20]], -[26, "hat", 104, 185, [null, 27, 14]], -[27, ["string", "action"], 162, 197, [26, null]], -[28, "stack", 397, 422, [12, 29, null]], -[29, ["string", "action"], 455, 422, [28, null]]] - +[[0, ["start", 2.0], 534, 124, [null, 84]], +[1, "pop", 602, 296, [2, null]], +[2, ["storein", 0], 534, 254, [28, 3, 1, 22]], +[3, ["string", "count"], 602, 254, [2, null]], +[4, "box", 72, 186, [12, 5, null]], +[5, ["string", "count"], 127, 186, [4, null]], +[6, "leftpos", 592, 422, [7, null]], +[7, ["setxy2", 0], 534, 422, [9, 6, 16, 10]], +[8, "forward", 934, 364, [75, 81, 71]], +[9, "penup", 534, 380, [22, 7]], +[10, "pendown", 534, 506, [7, 26]], +[11, ["setxy2", 20], 31, 312, [30, 14, 17, 31]], +[12, ["repeat", 104], 13, 186, [24, 4, 51, null]], +[13, "xcor", 143, 312, [14, null]], +[14, ["plus2", 0], 89, 312, [11, 13, 21]], +[15, "pop", 984, 214, [73, null]], +[16, ["number", 0], 592, 464, [7, null]], +[17, ["number", 0], 89, 394, [11, null]], +[18, "box", 714, 380, [23, 19, null]], +[19, ["string", "count"], 769, 380, [18, null]], +[20, "width", 690, 338, [23, null]], +[21, "pensize", 143, 354, [14, null]], +[22, "setpensize", 534, 338, [2, 23, 9]], +[23, ["division2", 0], 636, 338, [22, 20, 18]], +[24, "hat", 13, 132, [null, 25, 12]], +[25, ["string", "action"], 71, 144, [24, null]], +[26, "stack", 534, 548, [10, 27, null]], +[27, ["string", "action"], 592, 548, [26, null]], +[28, ["userdefined", "pysamples/ta-stats.py"], 534, 212, [84, 29, 2]], +[29, ["number", 100], 592, 212, [28, null]], +[30, "penup", 31, 270, [51, 11]], +[31, "pendown", 31, 436, [11, null]], +[32, "setcolor", 291, 180, [49, 33, 55]], +[33, "green", 368, 180, [32, null]], +[34, "setcolor", 291, 264, [55, 35, 57]], +[35, "cyan", 368, 264, [34, null]], +[36, "setcolor", 291, 348, [57, 43, 59]], +[37, "setcolor", 291, 432, [59, 44, 61]], +[38, "setcolor", 291, 516, [61, 45, 63]], +[39, "setcolor", 291, 600, [63, 46, 65]], +[40, "setcolor", 291, 684, [65, 47, 67]], +[41, "setcolor", 291, 768, [67, 48, 69]], +[42, "forward", 934, 448, [71, 83, 72]], +[43, "purple", 368, 348, [36, null]], +[44, "orange", 368, 432, [37, null]], +[45, "yellow", 368, 516, [38, null]], +[46, "red", 368, 600, [39, null]], +[47, "yellow", 368, 684, [40, null]], +[48, "red", 368, 768, [41, null]], +[49, "hat", 291, 126, [null, 50, 32]], +[50, ["string", "plot"], 349, 138, [49, null]], +[51, "stack", 31, 228, [12, 52, 30]], +[52, ["string", "plot"], 89, 228, [51, null]], +[53, "hat", 916, 118, [null, 54, 73]], +[54, ["string", "offset"], 974, 130, [53, null]], +[55, "stack", 291, 222, [32, 56, 34]], +[56, ["string", "offset"], 349, 222, [55, null]], +[57, "stack", 291, 306, [34, 58, 36]], +[58, ["string", "offset"], 349, 306, [57, null]], +[59, "stack", 291, 390, [36, 60, 37]], +[60, ["string", "offset"], 349, 390, [59, null]], +[61, "stack", 291, 474, [37, 62, 38]], +[62, ["string", "offset"], 349, 474, [61, null]], +[63, "stack", 291, 558, [38, 64, 39]], +[64, ["string", "offset"], 349, 558, [63, null]], +[65, "stack", 291, 642, [39, 66, 40]], +[66, ["string", "offset"], 349, 642, [65, null]], +[67, "stack", 291, 726, [40, 68, 41]], +[68, ["string", "offset"], 349, 726, [67, null]], +[69, "stack", 291, 810, [41, 70, null]], +[70, ["string", "offset"], 349, 810, [69, null]], +[71, "penup", 934, 406, [8, 42]], +[72, "pendown", 934, 490, [42, null]], +[73, ["storein", 0], 916, 172, [53, 74, 15, 80]], +[74, ["string", "value"], 984, 172, [73, null]], +[75, ["if", 63], 916, 298, [80, 76, 8, null]], +[76, ["greater2", 0], 972, 264, [75, 78, 77, null]], +[77, ["number", 0], 1042, 306, [76, null]], +[78, "box", 1018, 264, [76, 79, null]], +[79, ["string", "value"], 1073, 264, [78, null]], +[80, ["vspace", 0], 916, 256, [73, 75]], +[81, "box", 1005, 364, [8, 82, null]], +[82, ["string", "value"], 1060, 364, [81, null]], +[83, "pensize", 1005, 448, [42, null]], +[84, "setshade", 534, 170, [0, 85, 28]], +[85, ["number", 40.0], 619, 170, [84, null]]] -- cgit v0.9.1