Coverage for modules/org/openteacher/logic/loaders/t2k/t2k : 79%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
#! /usr/bin/env python3 # -*- coding: utf-8 -*-
# Copyright 2011-2012, 2014, Marten de Vries # Copyright 2011, Milan Boers # # This file is part of OpenTeacher. # # OpenTeacher is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # OpenTeacher is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with OpenTeacher. If not, see <http://www.gnu.org/licenses/>.
"default": 648, }
self._mm.mods(type="translator"), ) self._mm.mods(type="mimicryTypefaceConverter"), )
def _convertMimicryTypeface(self):
else: self._mm.resourcePath("translations") ) #TRANSLATORS: This is the name of an application. For more info #TRANSLATORS: about Teach2000: http://www.teach2000.org/
else:
for path in getattr(self, "_tempPaths", []): os.remove(path)
return "topo" else: #also support other formats in the future? Well, #everything that's left can be opened like it's of type 'words'...
"""Loads a .t2k file into the OpenTeacher data structure. http://www.teach2000.nl/help/00513_advanced_file_format.htm
""" return self._loadTopo(root) else:
#create one test to save all results in that are in the t2k file #(t2k doesn't have enough information to know which word was #wrong in which test, so we can have only one test.) "finished": True, "results": [], } #add a result for every time this word was wrong "itemId": self._getId(item), "result": "wrong", }) #add a result for every time this word was right "itemId": self._getId(item), "result": "right", })
#if there were results #get the time of the first start result and the one of the #last for a global idea of the time range of this 'mega' #test. Duration isn't used, since it's way off anyway. else:
#store those times in the first and last result. (which may #be the same, technically, but that doesn't matter...) "start": startTime, "end": startTime, } "start": endTime, "end": endTime }
placesList = { "items": [], "tests": [], }
for item in root.findall("message_data/items/item"): answers = item.find(".//answers") answerTexts = [a.text for a in answers.findall(".//answer")] place = { "id": self._getId(item), "x": int(answers.get("x") or 0), "y": int(answers.get("y") or 0), "name": self._stripBBCode(u", ".join(answerTexts)), } placesList["items"].append(place)
#append the test to the list test = self._loadResults(root) if test["results"]: placesList["tests"] = [test]
mapElement = root.find("message_data/mapquizfile") fd, mapPath = tempfile.mkstemp("." + mapElement.get("ext")) os.close(fd) self._tempPaths.add(mapPath) with open(mapPath, "wb") as f: f.write(base64.b64decode(mapElement.text))
return { "resources": { "mapPath": mapPath, }, "list": placesList, }
"items": [], "tests": [], }
#append the test to the list
"resources": {}, "list": wordList, }
"questions": [], "answers": [], }
#id
#questions #strip BBCode for now
#answers #strip BBCode for now
#remarks (comment in OT) word["comment"] = comment
#remarks_aa (commentAfterAnswering in OT) word["commentAfterAnswering"] = commentAfterAnswering
"""Strips all BBCode tags"""
"""Parses a date string as found in T2K files to a datetime object."""
|