From mboxrd@z Thu Jan 1 00:00:00 1970 From: Torsten Wagner Subject: execute sbe macro fails Date: Sat, 13 Jul 2013 22:57:44 +0200 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7b62432c073e0c04e16ae1fa Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:39805) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uy6t1-0006Sz-HK for emacs-orgmode@gnu.org; Sat, 13 Jul 2013 16:57:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uy6t0-0006JF-2V for emacs-orgmode@gnu.org; Sat, 13 Jul 2013 16:57:47 -0400 Received: from mail-ea0-x232.google.com ([2a00:1450:4013:c01::232]:43326) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uy6sz-0006J3-Se for emacs-orgmode@gnu.org; Sat, 13 Jul 2013 16:57:46 -0400 Received: by mail-ea0-f178.google.com with SMTP id l15so6900204eak.23 for ; Sat, 13 Jul 2013 13:57:45 -0700 (PDT) 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: Org Mode Mailing List --047d7b62432c073e0c04e16ae1fa Content-Type: text/plain; charset=ISO-8859-1 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 --047d7b62432c073e0c04e16ae1fa Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi,

I wrot= e a python code block which should translate scores into marks.
Th= e 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 tha= t, 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=A0=A0 | 1.1 | 1.2 | 1.3 | 1.4 | 2.1 | 2.2 | 2.3 | 2.4 | 2.5 | E= xtra | Sum | Mark |
|---------------------+------------+-----+-----+-----+-----+-----+-----+---= --+-----+-----+-------+-------+--------|
| Name1 |=A0=A0=A0=A0 111111 |= =A0 10 |=A0 10 |=A0 10 |=A0 12 |=A0 12 |=A0=A0 3 |=A0=A0 4 |=A0 12 |=A0=A0 = 3 |=A0=A0=A0=A0 2 |=A0=A0=A0 78 | #ERROR |
| Name2 |=A0=A0=A0=A0 22222 |=A0=A0=A0=A0 |=A0=A0=A0=A0 |=A0=A0=A0=A0 |=A0= =A0=A0=A0 |=A0=A0=A0=A0 |=A0=A0=A0=A0 |=A0=A0=A0=A0 |=A0=A0=A0=A0 |=A0=A0= =A0=A0 |=A0=A0=A0=A0=A0=A0 |=A0=A0=A0=A0 0 | #ERROR |
| Name3 |=A0=A0=A0= =A0 33333 |=A0=A0=A0=A0 |=A0=A0=A0=A0 |=A0=A0=A0=A0 |=A0=A0=A0=A0 |=A0=A0= =A0=A0 |=A0=A0=A0=A0 |=A0=A0=A0=A0 |=A0=A0=A0=A0 |=A0=A0=A0=A0 |=A0=A0=A0= =A0=A0=A0 |=A0=A0=A0=A0 0 | #ERROR |
#+TBLFM: $14=3D'(sbe score2mark= (score $13) (passscore 50))

#+name: score2mark(score, passscore)
#+begin_src python
def score= 2mark(score, passscore):
=A0=A0=A0 marklist =3D [5, 4.3, 4, 3.7, 3.3, 3,= 2.7 ,2.3, 2, 1.7, 1.3, 1]
=A0=A0=A0 step=3D(100-passscore)/(len(marklis= t)-1)
=A0=A0=A0 if=A0 score < passscore:
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return marklist[0]
=A0=A0=A0 for mark in = marklist[1:]:
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if round(passscore) <=3D= score <=3D round(passscore+step):
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0 return mark
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 else:
=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 passscore +=3D step
=A0=A0=A0 return -1
#+end_src

Any idea what I am doing wron= g? I tried different versions with "score2mark" some additional b= rackets etc. However, no luck yet.

Thanks for help

Torsten
=A0
--047d7b62432c073e0c04e16ae1fa--