From: Eric Schulte <schulte.eric@gmail.com>
To: Torsten Wagner <torsten.wagner@gmail.com>
Cc: Org Mode Mailing List <emacs-orgmode@gnu.org>
Subject: Re: execute sbe macro fails
Date: Sun, 14 Jul 2013 16:24:04 -0600 [thread overview]
Message-ID: <87mwpowzjv.fsf@gmail.com> (raw)
In-Reply-To: <CAPaq-gM1WWCxfWMj3JSGJb2Y1nJvzM3sGZ=yuHuABb0-igjt9g@mail.gmail.com> (Torsten Wagner's message of "Sat, 13 Jul 2013 22:57:44 +0200")
[-- Attachment #1: Type: text/plain, Size: 242 bytes --]
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.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: it.org --]
[-- Type: text/x-org, Size: 1394 bytes --]
| 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
[-- Attachment #3: Type: text/plain, Size: 1745 bytes --]
Torsten Wagner <torsten.wagner@gmail.com> 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
next prev parent reply other threads:[~2013-07-14 22:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-13 20:57 execute sbe macro fails Torsten Wagner
2013-07-14 22:24 ` Eric Schulte [this message]
2013-07-15 9:35 ` Torsten Wagner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87mwpowzjv.fsf@gmail.com \
--to=schulte.eric@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=torsten.wagner@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.