From 4c12b34363163822bc05cefc4a39bd4f9534c058 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Tue, 16 Oct 2012 18:49:27 +0000 Subject: add Write scoring --- diff --git a/dsparse.py b/dsparse.py index 38f1b1b..9b8671a 100755 --- a/dsparse.py +++ b/dsparse.py @@ -47,6 +47,11 @@ class ParseMain(): if score: self._dsdict[os.path.basename(path)][-1][ 'score'] = score + if activity == 'AbiWordActivity': + score = hasmenuitems(dsobj) + if score: + self._dsdict[os.path.basename(path)][-1][ + 'score'] = score mime_type = hascomponent(dsobj, 'mime_type') if mime_type: self._dsdict[os.path.basename(path)][-1][ @@ -192,6 +197,42 @@ def hasturtleblocks(path): return str(score) +WRITEMENUS = {'image': 0, 'table': 1, 'font-style': 2, 'font-color': 2, + 'font': 2, 'fontsize': 2, 'bold': 2, 'italic': 2, 'underline': 2, + 'Heading': 4, 'List': 4, 'style-name': 2, 'Text': 4, + 'left-align': 3, 'right-align': 3, 'center-align': 3, + 'justify-align': 3} +WRITEPOINTS = [15, 15, 20, 10, 10] + + +def hasmenuitems(path): + ''' Parse Write data and generate score based on rubric ''' + + if not os.path.exists(os.path.join(path, 'metadata', 'menu items')): + return None + fd = open(os.path.join(path, 'metadata', 'menu items')) + menuitems = [] + for line in fd: + tokens = line.split(' ') + if len(tokens) > 0: + for token in tokens: + menuitems.append(token) + + scores = [] + for i in range(len(WRITEMENUS)): + scores.append(0) + + for i in menuitems: + if i in WRITEMENUS: + scores[WRITEMENUS[i]] = WRITEPOINTS[WRITEMENUS[i]] + + score = 0 + for i in scores: + score += i + + return score + + def isactivity(path): ''' Return activity name ''' activity = hascomponent(path, 'activity') diff --git a/olpcdsparse.py b/olpcdsparse.py index cfc71a5..178ffca 100755 --- a/olpcdsparse.py +++ b/olpcdsparse.py @@ -47,6 +47,11 @@ class ParseMain(): if score: self._dsdict[os.path.basename(path)][-1][ 'score'] = score + if activity == 'AbiWordActivity': + score = hasmenuitems(dsobj) + if score: + self._dsdict[os.path.basename(path)][-1][ + 'score'] = score mime_type = hascomponent(dsobj, 'mime_type') if mime_type: self._dsdict[os.path.basename(path)][-1][ @@ -191,6 +196,42 @@ def hasturtleblocks(path): return str(score) +WRITEMENUS = {'image': 0, 'table': 1, 'font-style': 2, 'font-color': 2, + 'font': 2, 'fontsize': 2, 'bold': 2, 'italic': 2, 'underline': 2, + 'Heading': 4, 'List': 4, 'style-name': 2, 'Text': 4, + 'left-align': 3, 'right-align': 3, 'center-align': 3, + 'justify-align': 3} +WRITEPOINTS = [15, 15, 20, 10, 10] + + +def hasmenuitems(path): + ''' Parse Write data and generate score based on rubric ''' + + if not os.path.exists(os.path.join(path, 'metadata', 'menu items')): + return None + fd = open(os.path.join(path, 'metadata', 'menu items')) + menuitems = [] + for line in fd: + tokens = line.split(' ') + if len(tokens) > 0: + for token in tokens: + menuitems.append(token) + + scores = [] + for i in range(len(WRITEMENUS)): + scores.append(0) + + for i in menuitems: + if i in WRITEMENUS: + scores[WRITEMENUS[i]] = WRITEPOINTS[WRITEMENUS[i]] + + score = 0 + for i in scores: + score += i + + return score + + def isactivity(path): ''' Return activity name ''' activity = hascomponent(path, 'activity') -- cgit v0.9.1