diff options
author | Tony Anderson <tony@traveler.(none)> | 2011-02-01 14:22:28 (GMT) |
---|---|---|
committer | Tony Anderson <tony@traveler.(none)> | 2011-02-01 14:22:28 (GMT) |
commit | b8e67d0ea510559565aa1e74bb85da02b89791d7 (patch) | |
tree | bb7b76c7601bf07ba84c1a62d396f37601d3a95c | |
parent | f13c6f5a9c7cb2ffa8fc544c0687870d535283b8 (diff) |
version 11.14
-rwxr-xr-x | activity/activity.info | 2 | ||||
-rwxr-xr-x | cgi-bin/saveFile.py | 66 | ||||
-rwxr-xr-x | content/css/global.css | 2 | ||||
-rwxr-xr-x | content/js/learner_subject.js | 2 | ||||
-rwxr-xr-x | content/js/math.js | 274 | ||||
-rwxr-xr-x | content/js/subject.js | 6 | ||||
-rwxr-xr-x | launch.py | 1 |
7 files changed, 310 insertions, 43 deletions
diff --git a/activity/activity.info b/activity/activity.info index ee2852d..460cf54 100755 --- a/activity/activity.info +++ b/activity/activity.info @@ -1,5 +1,5 @@ [Activity] -#version = 11.13 +#version = 11.14 name = Learn service_name = org.olerwanda.Learn icon = activity-learn diff --git a/cgi-bin/saveFile.py b/cgi-bin/saveFile.py index 33a2a9f..d26419a 100755 --- a/cgi-bin/saveFile.py +++ b/cgi-bin/saveFile.py @@ -86,7 +86,6 @@ def process_images(txt): while not done: pos1 = txt.find('<!--I') if pos1 < 0: - print >> log, 'images done', txt done = True continue pos2 = txt[pos1:].find('-->') @@ -95,10 +94,19 @@ def process_images(txt): done = True continue comment = txt[pos1:pos1+pos2+3] - txt = txt[:pos1]+txt[pos1+pos2+3:] + pos3 = comment.find('_') + pos4 = comment.find('I') + imgno = comment[pos4+1:pos3] + if 'left' in comment: + class_insert = "class='image_left'" + elif 'right' in comment: + class_insert = "class='image_right'" + else: + class_insert = '' + insert = "<span id='I"+imgno+"' "+class_insert+"></span>\n" + txt = txt[:pos1]+insert+txt[pos1+pos2+3:] imagelist.append(comment) - print >> log, 'imagelist done', len(imagelist), imagelist - return imagelist + return txt, imagelist def process_audio(txt): done = False @@ -115,32 +123,22 @@ def process_audio(txt): audiolist.append(comment) return audiolist -def generate_image(imagelist,src,tgt): +def generate_image(imagelist): lessontxt = '' for image in imagelist: #parse string pos = image.find('I') pos1 = image.find('_') imgn = image[pos:pos1] - pos2 = image[pos1+1:].find('_') - if pos2 > -1: - pos1 = pos1 + pos2 - pos3 = image[pos:].find('.') + pos3 = image[pos1:].find('.') img = image[pos1+1:pos1+pos3] if 'right' in image: position = 'image_right' else: position = 'image_left' - #copy image to from source to assets - tpth = path(tgt) / 'assets' / 'image' - if not (tpth / img).exists(): - if (spth / img).exists(): - spth = path(src) / 'source' / img - subprocess.call('cp ' + spth + ' ' + tpth, shell=True) #create lessontxt - lessontxt = "$('<span id="+'"'+imgn+'" class = "'+position+'" />'+"')\n" - lessontxt = lessontxt + " .append(karma.createImg(" + img + "))\n" - lessontxt = lessontxt + " .appendTo('#content')" + lessontxt = lessontxt + " $('#"+imgn+"')\n" + lessontxt = lessontxt + " .append(karma.createImg('" + img + "'))\n" return lessontxt def generate_audio(audiolist, src, tgt): @@ -181,7 +179,7 @@ txt = form.getfirst('content', default='no text found') soup = BeautifulSoup(txt) imgs = soup.findAll('img') for img in imgs: - img['src']= path(img['src']).name + soup.img.extract() txtout = soup.prettify() fout = open(savepth,'w') fout.write(txtout) @@ -199,15 +197,12 @@ else: nscreen = 1 subprocess.call('rm -rf ' + fpth / 'a*.txt', shell = True) for screen in screens: - print >> log, 'processing assets' - imagelist = process_images(screen) + screen, imagelist = process_images(screen) for image in imagelist: masterimagelist.append(image) audiolist = process_audio(screen) for clip in audiolist: masteraudiolist.append(clip) - print >> log, 'images', len(masterimagelist), masterimagelist - print >> log, 'audio', len(masteraudiolist), masteraudiolist questionstrings = scanquiz(screen) quiztxt = makequiz(questionstrings) if len(quiztxt) > 0: @@ -235,12 +230,13 @@ print >> log, 'rewrite lesson.js' #rewrite lesson.js if nscreen < 1: lessontxt = "function initialize(karma){\n" - for image in imagelist: - lessontxt = lessontxt + generate_image(imagelist) lessontxt = lessontxt + " $('<div id = " + '"txtMain"/>' + "')\n" + lessontxt = lessontxt + " .appendTo('#content')\n" lessontxt = lessontxt + " .load('http://localhost:8008/cgi-bin/getFile.py',\n" - lessontxt = lessontxt + " {'filename':'" + fpth + "/a.txt'})\n" - lessontxt = lessontxt + " .appendTo('#content')\n};\n\n" + lessontxt = lessontxt + " {'filename':'" + fpth + "/a.txt'},\n" + lessontxt = lessontxt + " function(){\n" + lessontxt = lessontxt + generate_image(imagelist) + lessontxt = lessontxt + " });\n};\n" for audio in audiolist: lessontxt = lessontxt + generate_audio(audiolist) lessontxt = lessontxt + "function startGame(karma) {\n" @@ -287,6 +283,7 @@ else: #write lesson.css, if necessary print >> log, 'write lesson.css, if necessary', len(masterimagelist) +print >> log, 'masterimagelist', len(masterimagelist), masterimagelist if len(masterimagelist) > 0: txtout = '' for image in masterimagelist: @@ -299,13 +296,14 @@ if len(masterimagelist) > 0: if pos1 < 0: pos1 = image[pos:].find('-->') height = image[pos:pos+pos1] - pos = image.find('width')+7 + pos = image.find('width')+6 pos1 = image[pos:].find(' ') if pos1 < 0: pos1 = image[pos:].find('-->') width = image[pos:pos+pos1] + print >>log, 'img',imgn,'height',height,'width',width #write txtout - txtout = txtout+'#I'+imgn+'{height:'+height+'px; width:'+width+'px;}\n' + txtout = txtout+'#I'+imgn+'{height: '+height+'px; width: '+width+'px;}\n' #write file pth = fpth/ 'css' / 'lesson.css' fout = open(pth,'w') @@ -313,18 +311,16 @@ if len(masterimagelist) > 0: fout.close() #write lesson-karma.js +print >> log, 'write lesson-karma.js', len(masterimagelist) txtlk = "image: [\n" for img in masterimagelist: #parse pos1 = img.find('_') - pos2 = img[pos1+1:].find('_') - if pos2 > -1: - pos1 = pos1+pos2+1 pos2 = img[pos1:].find('.') pos3 = img[pos1:].find(' ') - imgn = img[pos1+1:pos2] - imgf = img[pos1+1:pos3] - txtlk = txtlk + "{name:"+imgn+"', file:'"+imgf+"'},\n" + imgn = img[pos1+1:pos1+pos2] + imgf = img[pos1+1:pos1+pos3] + txtlk = txtlk + "{name:'"+imgn+"', file:'"+imgf+"'},\n" txtlk = txtlk + " ],\naudio: [\n" for clip in masteraudiolist: #parse diff --git a/content/css/global.css b/content/css/global.css index 8560230..c65a74d 100755 --- a/content/css/global.css +++ b/content/css/global.css @@ -28,7 +28,7 @@ body { margin-top: 75px;
background-color: #FFFFCC;
width: 1200px;
- height:748px;
+ height: 798px;
overflow-y:scroll;
overflow-x:hidden;
z-index: 0;
diff --git a/content/js/learner_subject.js b/content/js/learner_subject.js index a4ff737..1c45220 100755 --- a/content/js/learner_subject.js +++ b/content/js/learner_subject.js @@ -4,8 +4,6 @@ $(document).ready( k.ready(function() { - logos; - activities; k.ready(function(){ diff --git a/content/js/math.js b/content/js/math.js new file mode 100755 index 0000000..a0b9da4 --- /dev/null +++ b/content/js/math.js @@ -0,0 +1,274 @@ +var ctx, xs, ys, columnWidth, rowHeight, solution, steps, typeFlag; +var decimalNumber,words,ask,txtComment,spaces; +var digits, WBDigits, WBTeen, WBTens; +var whole, decimal,wholeDigits,dcmlDigits; +var caseno, cases; + +txtComment = ''; +spaces = ' '; +WBDigits=['zero','one','two','three','four','five','six','seven','eight','nine']; +WBTeens=['ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen']; +WBTens=['','','twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety']; + +function word(s){ + n = parseInt(s); + if (n<10){ + return WBDigits[n] + } else if (n<20) { + return WBTeens[n-10] + } else { + x = Math.floor(n/10); + y = n%10; + if (y>1){ + return WBTens[x] + '-' + WBDigits[y]; + } else { + return WBTens[x]; + }; + }; +}; + +function getUnits(theDigits){ + s = ""; + units = theDigits.length+""; + switch(units){ + case "1": + if(theDigits[0] != '0'){ + s = word(theDigits[0]); + }; + break; + case "2": + indx = theDigits[1]*10+parseInt(theDigits[0]); + s = word(indx); + break; + case "3": + s = s + word(theDigits[2]) + ' hundred '; + indx = theDigits[1]*10+parseInt(theDigits[0]); + if(indx>0){ + s = s + word(indx); + }; + break; + }; + return s; +}; + +function getDecimals(theDigits){ + s = ""; + decimals = theDigits.length+""; + switch(decimals){ + case "1": + s = word(theDigits[0]) + ' tenths'; + break; + case "2": + indx = theDigits[1]*10+parseInt(theDigits[0]); + s = word(indx) + ' hundredths'; + break; + case "3": + if(parseInt(theDigits[2])>0){ + s = word(theDigits[2]) + ' hundred '; + }; + indx = theDigits[1]*10+parseInt(theDigits[0]); + s = s + word(indx) + ' thousandths'; + break; + default: + alert(decimals+' should not happen'); + }; + return s; +}; + +function getWords(theDigits){ + test=theDigits.join(""); + if (test.indexOf('.')>0){ + parts = test.split('.'); + decimalDigits=parts[0].split(""); + unitDigits=parts[1].split(""); + }else{ + decimalDigits = []; + unitDigits=test.split(""); + }; + decimals = decimalDigits.length; + units = unitDigits.length; + if(units>0){ + words = getUnits(unitDigits); + }else{ + words = ''; + }; + if(decimals>0){ + dwords = getDecimals(decimalDigits); + if(dwords.length>0){ + if(words.length>0){ + words = words + ' and ' + dwords; + }else{ + words = dwords; + }; + }; + }; + return words +}; + +function getWholeWords(words){ + pos = words.indexOf(' and '); + if(pos>0){ + txt = words.substring(0,pos); + return txt; + }else{ + return ""; + } +}; + +function getRandom(a,b) { + c = Math.random() + return Math.floor(c * (b-a) + a) +}; + +function generate_compare(op1,op2){ + if (op1 == op2){ + return '='; + } else if (op1 < op2){ + return '<'; + } else { + return '>'; + }; +}; + +function expandNumber(number){ + position = 0; + rest = number; + digits = []; + while (rest > 0) { + digit = rest%10; + digits[position] = digit; + position += 1; + rest = (rest - digit) / 10; + }; + return digits; +}; + +function drawDigits(row, xunits, theDigits){ + y = ys + (row+2)*50; + xl = xunits - 20; + for(i=0;i<theDigits.length;i++){ + x = xl-(i*columnWidth); + ctx.fillText(theDigits[i],x,y-10); + ctx.stroke(); + }; +}; + +function drawHighlight(row,x,number,color){ + y = ys + (row+2)*50; + save = ctx.fillStyle; + ctx.fillStyle = color; + ctx.fillText(number,x,y-10); + ctx.stroke(); + ctx.fillStyle = save; +}; + +function drawBlanks(row,col,cols){ + y = ys + (row+2)*50; + x = xs + 50 + col*columnWidth; + ctx.clearRect(x,y-50,x+50-col*columnWidth,y); +}; + +function drawNumber(row, x, number){ + y = ys + (row+2)*50; + ctx.fillText(number,x,y-10); + ctx.stroke() +}; + +function drawLine(xs,ys,xf,yf){ + ctx.moveTo(xs,ys) + ctx.lineTo(xf,yf) + ctx.stroke() +}; + +function drawTotal(row, xunits, sub, cols){ + //draw heavier line at base of row for cols columns from right + //if sub is true, draw not so bold a line + y = ys + (row+2)*50; + xl = xunits; + drawLine(xl - cols * columnWidth, y, xl, y); +}; + +function drawComment(row, xunits, txt){ + if(row==0){ + y = ys; + x = xs; + align=ctx.textAlign; + ctx.textAlign='left'; + ctx.fillText(spaces,x,y-10); + ctx.stroke(); + }else{ + y = ys + (row+2)*50; + x = xunits + 25; + align = ctx.textAlign; + }; + ctx.fillText(txt,x,y-10); + ctx.stroke(); + ctx.textAlign = align; +}; + +function drawPanel(name){ + // draw lines + xf = xs+3*columnWidth + yf = ys+rows*rowHeight + first = xs+columnWidth + second = xs+2*columnWidth + // horizontal + drawLine(xs,ys,xf,ys); + drawLine(xs,ys+rowHeight,xf,2*rowHeight); + drawLine(xs,ys+2*rowHeight,xf,3*rowHeight); + //drawLine(xs,yf,xf,yf); + // vertical + drawLine(xs,ys,xs,yf); + drawLine(xf,ys,xf,yf); + drawLine(first,ys+rowHeight,first,yf); + drawLine(second,ys+rowHeight,second,yf); + // text + font = ctx.font; + align = ctx.textAlign; + ctx.font = "12pt Arial"; + ctx.textAlign = "left"; + ctx.fillText(name[0], first+10, ys+40); + ctx.stroke(); + ctx.fillText(name[1],xs+10, ys+90); + ctx.stroke(); + ctx.fillText(name[2], first+10, ys+90); + ctx.stroke(); + ctx.fillText(name[3], second+10, ys+90); + ctx.stroke(); + ctx.font = font; + ctx.textAlign = align; +}; + +//draw place value table +function draw(){ + // set up canvas + var canvas = document.getElementById('placeValue'); + if (canvas.getContext){ + ctx = canvas.getContext('2d'); + var maxx = 1198; + var maxy = 700; + canvas.setAttribute('width', maxx); + canvas.setAttribute('height', maxy); + ctx.fillStyle = 'black'; + ctx.strokeStyle = 'black'; + ctx.font = "20pt Arial"; + ctx.textAlign = "center"; + // draw panels + columnWidth = 100; + rowHeight = 50; + rows = 7; + xs = 50 + 6*columnWidth; + ys = 50 + decimals = ['thousandths','10ths','100ths','1000ths'] + drawPanel(decimals); + xs = 50 + 3*columnWidth; + units = ['units','hundreds','tens','ones'] + drawPanel(units); + xs = 50; + thousands = ['thousands','hundreds','tens','ones'] + drawPanel(thousands); + drawComment(1,30+6*columnWidth,'.') + } else { + alert('oops'); + }; +}; diff --git a/content/js/subject.js b/content/js/subject.js index cc3917f..3d42a65 100755 --- a/content/js/subject.js +++ b/content/js/subject.js @@ -13,10 +13,10 @@ $(document).ready( var canvas = document.getElementById('ladder'); if (canvas.getContext){ var ctx = canvas.getContext('2d'); - var cells = 6; + var cells = 8; var rows = 2 + (activities.length / cells); var maxx = 1200; - var cellsize = 64; + var cellsize = 56; var sz = cellsize; var maxy = rows * 1.5 * cellsize; if (maxy < 500){ maxy = 800; }; @@ -26,7 +26,7 @@ $(document).ready( var x = 0; var y = 0; var odd = 1; - var xstart = 1.7 * cellsize; + var xstart = 64; var ystart = maxy - 0.5*cellsize; var row = 0; var cell = 0; @@ -18,7 +18,6 @@ try: import gconf except ImportError: _using_gconf = False - self.using_gconf = _using_gconf DATAPATH = path(activity.get_activity_root()) / "data" WORKPATH = DATAPATH / "work" |