All possible and correct answers in English and French.
In [ ]:
%run "../Functions/0.2 GF French localization.ipynb"
In [ ]:
processGForm = not ('gform' in globals())
if processGForm:
gformFR1522.columns = gformEN1522.columns
In [ ]:
#type(gformFR1522.index), type(gformEN1522.index)
if processGForm: localizedForm = gformFR1522.copy() localizedPossibleAnswers = questionsAnswersTranslationsFR.copy()
#def getTranslatedForm( localizedForm, localizedPossibleAnswers ):
result = localizedForm.copy()
result.index = pd.Series(result.index).apply(str)
localizedPossibleAnswers.index = pd.Series(localizedPossibleAnswers.index).apply(str)
# translate answers
for question in result.columns:
for index in result.index:
answer = result.loc[index, question]
if (
0 != len(localizedPossibleAnswers.loc[question])
and
(answer in localizedPossibleAnswers.loc[question][0])
):
#print(result.loc[index, question])
#print(localizedPossibleAnswers.loc[question][0][answer])
result.loc[index, question] =\
localizedPossibleAnswers.loc[question][0][answer]
# translate questions
result = result.rename(columns=dict(zip(localizedForm.columns,gformEN1522.columns)))
#result
answer = gformFR.loc[index, question] answer
In [ ]:
if processGForm:
# returns an English-indexed, English-localized answer dataframe
# from a French-indexed, French-localized dataframe
def getTranslatedForm( _localizedForm, localizedPossibleAnswers ):
result = _localizedForm.copy()
result.index = pd.Series(result.index).apply(str)
localizedPossibleAnswers.index = pd.Series(localizedPossibleAnswers.index).apply(str)
# translate answers
for question in result.columns:
for index in result.index:
answer = result.loc[index, question]
if (
0 != len(localizedPossibleAnswers.loc[question])
and
(answer in localizedPossibleAnswers.loc[question][0])
):
#print(result.loc[index, question])
#print(localizedPossibleAnswers.loc[question][0][answer])
result.loc[index, question] =\
localizedPossibleAnswers.loc[question][0][answer]
# translate questions
result = result.rename(columns=dict(zip(_localizedForm.columns,gformEN1522.columns)))
return result
In [ ]:
if processGForm:
# plain possible answers
bioBrickPlainPossibleAnswers = [\
"None of these",
"1", # "TER",
"2", # "PR",
"3", # "CDS",
"4", # "RBS",
"5", # "Plasmid",
"I don't know",
]
# explicitation of BioBrick answers
bioBrickAnswersExplicitation = [\
"None of these",
"TER", # 1
"PR", # 2
"CDS", # 3
"RBS", # 4
"Plasmid", # 5
"I don't know",
]
biobrickExplicitation = [dict(zip(bioBrickPlainPossibleAnswers, bioBrickAnswersExplicitation))]
answersExplicitation = pd.Series(
[
# Timestamp
#'Timestamp', #01
[],
# Basic engagement questions
#'Are you interested in learning more about...Biology', #02
[],
#'Are you interested in learning more about...Synthetic biology', #03
[],
#'Are you interested in learning more about...Video games', #04
[],
#'Are you interested in learning more about...Engineering', #05
[],
# Experience with Hero.Coli
#'Have you ever played Hero.Coli?', #06
[],
# Basic demographics questions
#'How old are you?', #07
[],
#'What is your gender?', #08
[],
#'Are you interested in video games?', #09
[],
#'Are you interested in biology?', #10
[],
#'How long have you studied biology?', #11
[],
#'Do you play video games?', #12
[],
# Basic biology questions
#'Have you ever heard about synthetic biology or BioBricks, outside of Hero.Coli?', #13
[],
# Basic engagement questions
#'Do you volunteer to contribute to our study by answering 9 more questions? (5 min)', #14
[],
#'Did you enjoy playing the game?', #15
[],
# General mechanics of the game
#'In order to modify the abilities of the bacterium, you have to...', #16
[],
#'What are BioBricks and devices?', #17
[],
#'Find the antibiotic:', #18
[],
# BioBrick names and functions
#'Plasmid is...', #19
biobrickExplicitation,
#'Represents the end of a device... TER', #20
biobrickExplicitation,
#'Promoter is...', #21
biobrickExplicitation,
#'Represents the ability given... CDS', #22
biobrickExplicitation,
#'Terminator is...', #23
biobrickExplicitation,
#'Codes a protein... CDS', #24
biobrickExplicitation,
#'RBS is...', #25
biobrickExplicitation,
#'Can represent GFP... CDS', #26
biobrickExplicitation,
#'Coding Sequence is...', #27
biobrickExplicitation,
#'Controls when the device is active... PR', #28
biobrickExplicitation,
#'Controls the level of expression, and thus how much the ability will be affected... RBS', #29
biobrickExplicitation,
#'Makes it possible to equip an additional device. Plasmid', #30
biobrickExplicitation,
#'Operator is... XXX', #31
biobrickExplicitation,
# Device symbols
#'What does this device do? RBS:PCONS:FLHDC:TER XXX', #32
[],
#'What does this device do? PCONS:RBS:FLHDC:TER', #33
[],
#'What does this device do? PBAD:RBS:GFP:TER', #34
[],
#'What does this device do? PBAD:GFP:RBS:TER XXX', #35
[],
#'What does this device do? GFP:RBS:PCONS:TER XXX', #36
[],
#'What does this device do? PCONS:GFP:RBS:TER XXX', #37
[],
#'What does this device do? AMPR:RBS:PCONS:TER XXX', #38
[],
#'What does this device do? RBS:PCONS:AMPR:TER XXX', #39
[],
# Beyond the game
#'When does green fluorescence happen?', #40
[],
#'What happens when you unequip the movement device?', #41
[],
#'Last question. Next page only contains remarks.Guess: you have crafted a functional device containing an arabinose-induced promoter and an arabinose Coding Sequence (CDS). What will happen?', #42
[],
# Remarks
#'You can write down remarks here.', #43
[],
# Technical data
#'userId', #44
[],
#'Language', #45
[],
#'Temporality' #46
[],
], index = gformEN1522.columns
)
#answersExplicitation
#answersExplicitation.loc['Are you interested in video games?']['Beaucoup']
In [ ]:
# criterion: age != 0
def getWithoutTest(sample):
return sample[sample[QAge] != 0]
# not used to filter out tests due to false positives
def getContainString(sample, string):
return sample[sample[QRemarks].apply(lambda s: str(s).find(string) != -1)]
In [ ]:
if processGForm:
gform = pd.concat([gformEN1522, getTranslatedForm( gformFR1522, questionsAnswersTranslationsFR )])
gform.index = range(0, len(gform.index))
In [ ]:
if processGForm:
gform = getTranslatedForm( gform, answersExplicitation )
gform.index = range(0, len(gform.index))
In [ ]:
if processGForm:
# filter out test answers and add test users to testUsers DataFrame,
# which is defined in 0.0 RedMetrics data preparation.ipynb
gformTestUserIds = set(gform[gform[QAge] == 0][QUserId].unique())
#allTestUsers = set(testUsers.values[0])
allTestUsers = list(set(testUsers) | gformTestUserIds)
testUsers = pd.DataFrame(data=allTestUsers, columns=['userId'])
In [ ]:
if processGForm:
# filter out associated redmetrics events
rmdf1522 = rmdf1522[~rmdf1522[QUserId].isin(gformTestUserIds)]
rmdf160 = rmdf160[~rmdf160[QUserId].isin(gformTestUserIds)]
rmdfConcat = rmdfConcat[~rmdfConcat[QUserId].isin(gformTestUserIds)]
gform = getWithoutTest(gform)
In [ ]:
if processGForm:
writeTestUsers(testUsers)
writeRMDF(rmdf1522, processedRMDF1522Path)
writeRMDF(rmdf160, processedRMDF160Path)
In [ ]:
if processGForm:
gform.to_csv(mergedPath, encoding=csvEncoding)