Error Rendering Custom CSV Export File

54 views
Skip to first unread message

lucas s

unread,
Nov 29, 2021, 12:27:03 PM11/29/21
to oTree help & discussion
When trying to Render the custom data field in the final App.
It will get stuck on the loading icon with no progress.

If exporting the Raw CSV file it Renders fine with the (Participant.identification) listed in the correct spot.

The Table in the html file also Renders it correctly using sessions.get_players()

If taking out the identification it Renders fine. With it Renders load time (infinite).

Any idea of how to fix this? 


--------------- custom export----------------
def custom_export(players):
# header row
yield ['session', 'participant_code', 'round_number', 'id_in_group', 'contribution', 'payoff', 'participant id', 'identification']
for p in players:
participant = p.participant
session = p.session
yield [session.code, participant.code, p.round_number, p.id_in_group, p.contribution, p.payoff, participant.id, participant.identification]

-----------------session-----------------------
PARTICIPANT_FIELDS = ['identification']

----------------results.html------------------
{{ for player in subsession.get_players() }}
{{ player.participant.identification }} {{ player.id_in_group }}
{{ endfor }}

-----------------compilation------------------

class IdentificationNumber(Page):
form_model = 'player'
form_fields = ['birth', 'cell']

@staticmethod
def error_message(player, values):
if len(values['birth']) != 4 or not values['birth'].isdigit():
return 'Enter the Date in Correct Format'
if len(values['cell']) != 4 or not values['cell'].isdigit():
return 'Enter the Last 4 Digits in Correct Format'
else:
participant = player.participant
participant.identification = str(values['birth'] + "-" + values['cell'])

Chris @ oTree

unread,
Nov 29, 2021, 12:32:56 PM11/29/21
to oTree help & discussion
Try putting a print statement inside the for-loop of your custom_export to print out each participant.identification, then run it on the devserver. What does it output to the console?

Chris @ oTree

unread,
Nov 29, 2021, 12:33:35 PM11/29/21
to oTree help & discussion
Also check your console for errors in general.

lucas s

unread,
Nov 29, 2021, 1:31:22 PM11/29/21
to oTree help & discussion
I dug around a little more and still unsure how to pass the data back in the Custom CSV.
From what I can tell the (participant.identification) has a value stored inside for each player
This would be player.participant.indentification = Str()
So calling the player.participant.identicification  returns a value? 

----------------p.indentification----------------
File "----------\anaconda3\lib\site-packages\otree\database.py", line 253, in __get__
    return obj.vars[self.attr]
KeyError: 'identification'

Chris @ oTree

unread,
Nov 29, 2021, 1:42:26 PM11/29/21
to lucas s, oTree help & discussion
If you get a KeyError, that means some participants don’t have an identification. You can work around this by doing participant.vars.get("identification"), which will return None when it is missing.

Sent from my phone

On Nov 29, 2021, at 10:31 AM, lucas s <stott....@gmail.com> wrote:


--
You received this message because you are subscribed to the Google Groups "oTree help & discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to otree+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/1d6c4e70-b5c7-44ac-8640-189e6d91807bn%40googlegroups.com.

lucas s

unread,
Nov 29, 2021, 2:09:56 PM11/29/21
to oTree help & discussion
I just threw the participant.vars.get("identification") and it started working.
I was looking at this code on the github
Just a little confused on the difference between these 2 syntax's.
They are not the same?

--------------github code----------------

self.player.participant.vars['first name'] = 'Chris'

Then in a future subsession, you would retrieve this value like this:

self.player.participant.vars['first name'] # returns 'Chris'

-------------otree hub------------------

(Internally, all participant fields are stored in a dict called participant.vars. participant.xyz is equivalent to participant.vars['xyz'].)

Chris @ oTree

unread,
Nov 29, 2021, 2:17:42 PM11/29/21
to lucas s, oTree help & discussion
You can use either syntax. 

Sent from my phone

On Nov 29, 2021, at 11:10 AM, lucas s <stott....@gmail.com> wrote:

I just threw the participant.vars.get("identification") and it started working.
You received this message because you are subscribed to a topic in the Google Groups "oTree help & discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/otree/b9ckLH-FAHs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to otree+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages