emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* execute sbe macro fails
@ 2013-07-13 20:57 Torsten Wagner
  2013-07-14 22:24 ` Eric Schulte
  0 siblings, 1 reply; 3+ messages in thread
From: Torsten Wagner @ 2013-07-13 20:57 UTC (permalink / raw)
  To: Org Mode Mailing List

[-- Attachment #1: Type: text/plain, Size: 1570 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 1830 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: execute sbe macro fails
  2013-07-13 20:57 execute sbe macro fails Torsten Wagner
@ 2013-07-14 22:24 ` Eric Schulte
  2013-07-15  9:35   ` Torsten Wagner
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Schulte @ 2013-07-14 22:24 UTC (permalink / raw)
  To: Torsten Wagner; +Cc: Org Mode Mailing List

[-- 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: execute sbe macro fails
  2013-07-14 22:24 ` Eric Schulte
@ 2013-07-15  9:35   ` Torsten Wagner
  0 siblings, 0 replies; 3+ messages in thread
From: Torsten Wagner @ 2013-07-15  9:35 UTC (permalink / raw)
  To: Eric Schulte; +Cc: Org Mode Mailing List

[-- Attachment #1: Type: text/plain, Size: 844 bytes --]

Dear Eric,

thanks a lot. That was really insightful. I didn't use babel for several
month and I always struggle to get into it again.
I clearly was confused about the variable definition. Using a function like
I did, one has to do it basically twice, once for babel and once for the
target language. I never used the sbe-macro (Actually, I was not even aware
of it). Thus, I thought the problem was somehow there.

Furthermore, I missed that I should at least call the function once ;)

Would it be possible that the error-message contains more infos? E.g. some
hints within the mini-buffer or *Messages*-buffer. That would make it
easier to debug what is going wrong.

Thanks again, that was really helpful.

Torsten





On 15 July 2013 00:24, Eric Schulte <schulte.eric@gmail.com> wrote:

> $14='(sbe score2mark (score $13) (passscore 50))

[-- Attachment #2: Type: text/html, Size: 1523 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-07-15  9:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-13 20:57 execute sbe macro fails Torsten Wagner
2013-07-14 22:24 ` Eric Schulte
2013-07-15  9:35   ` Torsten Wagner

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).