From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: execute sbe macro fails Date: Sun, 14 Jul 2013 16:24:04 -0600 Message-ID: <87mwpowzjv.fsf@gmail.com> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:51975) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UyUk7-0008VG-CN for emacs-orgmode@gnu.org; Sun, 14 Jul 2013 18:26:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UyUk5-00085F-H9 for emacs-orgmode@gnu.org; Sun, 14 Jul 2013 18:26:11 -0400 Received: from mail-pb0-x22c.google.com ([2607:f8b0:400e:c01::22c]:38835) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UyUk5-00084x-9s for emacs-orgmode@gnu.org; Sun, 14 Jul 2013 18:26:09 -0400 Received: by mail-pb0-f44.google.com with SMTP id uo1so10620626pbc.3 for ; Sun, 14 Jul 2013 15:26:08 -0700 (PDT) In-Reply-To: (Torsten Wagner's message of "Sat, 13 Jul 2013 22:57:44 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Torsten Wagner Cc: Org Mode Mailing List --=-=-= Content-Type: text/plain Hi Torsten, There are numerous syntactic issues in your example, try the attached version which works. Additionally, I've pushed up a change which makes the sbe macro somewhat more robust so that the quotes around 50 could now be removed. --=-=-= Content-Type: text/x-org Content-Disposition: inline; filename=it.org | Name | ID | 1.1 | 1.2 | 1.3 | 1.4 | 2.1 | 2.2 | 2.3 | 2.4 | 2.5 | Extra | | | | Sum | Mark | | | | | | | | | | | | | |-------+--------+--------+-----+-----+-----+-----+-----+-----+-----+-----+-------+---+---| | Name1 | 111111 | 10 | 10 | 10 | 12 | 12 | 3 | 4 | 12 | 3 | | 1 | 5 | | 2 | 78 | #ERROR | | | | | | | | | | 2 | 5 | | Name2 | 22222 | | | | | | | | | | | 3 | 5 | | | 0 | #ERROR | | | | | | | | | | 4 | 5 | | Name3 | 33333 | | | | | | | | | | | 5 | 5 | | | 0 | #ERROR | | | | | | | | | | 6 | 5 | #+TBLFM: $14='(sbe score2mark (score $13) (passscore "50")) #+name: score2mark #+begin_src python :var score=0 :var passscore=0 def score2mark(score, passscore): marklist = [5, 4.3, 4, 3.7, 3.3, 3, 2.7 ,2.3, 2, 1.7, 1.3, 1] step=(100-passscore)/(len(marklist)-1) if score < passscore: return marklist[0] for mark in marklist[1:]: if round(passscore) <= score <= round(passscore+step): return mark else: passscore += step return -1 return score2mark(score, passscore) #+end_src --=-=-= Content-Type: text/plain Torsten Wagner writes: > Hi, > > I wrote a python code block which should translate scores into marks. > The python code seems to work. It takes two arguments. The reached score > (out of 100) as well as how many scores where needed to pass. Starting from > that, higher grades are calculated on a even base. > > I want to call the python block for each row using the sbe macro > However, this results in an error and I can't see why > > | Name | ID | 1.1 | 1.2 | 1.3 | 1.4 | 2.1 | 2.2 | 2.3 | 2.4 | 2.5 | Extra > | Sum | Mark | > |---------------------+------------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-------+-------+--------| > | Name1 | 111111 | 10 | 10 | 10 | 12 | 12 | 3 | 4 | 12 | 3 > | 2 | 78 | #ERROR | > | Name2 | 22222 | | | | | | | | | > | | 0 | #ERROR | > | Name3 | 33333 | | | | | | | | | > | | 0 | #ERROR | > #+TBLFM: $14='(sbe score2mark (score $13) (passscore 50)) > > #+name: score2mark(score, passscore) > #+begin_src python > def score2mark(score, passscore): > marklist = [5, 4.3, 4, 3.7, 3.3, 3, 2.7 ,2.3, 2, 1.7, 1.3, 1] > step=(100-passscore)/(len(marklist)-1) > if score < passscore: > return marklist[0] > for mark in marklist[1:]: > if round(passscore) <= score <= round(passscore+step): > return mark > else: > passscore += step > return -1 > #+end_src > > Any idea what I am doing wrong? I tried different versions with > "score2mark" some additional brackets etc. However, no luck yet. > > Thanks for help > > Torsten -- Eric Schulte http://cs.unm.edu/~eschulte --=-=-=--