Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from os import listdir
- paths = listdir('results')
- battleshipFile = open('BattleshipData.csv', 'w')
- resultsPerDate = open('BattleshipPerDate.csv', 'w')
- ipAddresses = {}
- participantsPerDate = {}
- for path in paths:
- file = open('results/' + path, 'r')
- contentLines = file.readlines()
- # format condition
- condition = contentLines[0].strip(' ').strip('\n').lower()
- print(condition)
- # format date
- dateString = contentLines[1]
- date = dateString.partition(':')[2].strip(' ')
- formattedDate = date[0:2] + '-' + date[2:4] + '-' + date[4:8]
- print(formattedDate)
- # format ip address
- ipString = contentLines[2]
- ip = ipString.partition(':')[2].strip(' ').strip('\n')
- print(ip)
- # name-age-gender
- participantList = contentLines[3].split(',')
- name = participantList[0]
- age = participantList[1]
- genderString = participantList[2].lower().strip('\n')
- if ip in ipAddresses:
- print(f'{name} with ip {ip} has already been used by {ipAddresses[ip]}')
- continue
- else:
- ipAddresses[ip] = name
- # gender to integer
- gender = 0
- if genderString == 'male':
- gender = 1
- else:
- gender = 2
- print('Not protected by GDPR')
- print(f'{name},{age},{genderString}')
- totalTrials = 0
- totalNearMiss = 0
- totalFullMiss = 0
- totalHit = 0
- happinessNearMiss = 0
- happinessFullMiss = 0
- happinessHit = 0
- willingnessNearMiss = 0
- willingnessFullMiss = 0
- willingnessHit = 0
- minHappiness = 99
- minHappinessTrial = 0
- maxHappiness = 0
- maxHappinessTrial = 0
- for trialLine in contentLines:
- trialList = trialLine.split(',')
- trialIndication = trialList[0].strip(' ')
- # if the lion is a trial
- if trialIndication == 'trial':
- totalTrials += 1
- result = trialList[4].strip(' ')
- happiness = int(trialList[7].strip(' '))
- willingness = int(trialList[8].strip(' '))
- # stats hits / full misses / near misses
- if result == 'nearMiss':
- totalNearMiss += 1
- happinessNearMiss += happiness
- willingnessNearMiss += willingness
- elif result == 'fullMiss':
- totalFullMiss += 1
- happinessFullMiss += happiness
- willingnessFullMiss += willingness
- elif result == 'hit':
- totalHit += 1
- happinessHit += happiness
- willingnessHit += willingness
- # min happiness
- if minHappiness > happiness:
- minHappiness = happiness
- minHappinessTrial = totalTrials
- # max happiness
- if maxHappiness < happiness:
- maxHappiness = happiness
- maxHappinessTrial = totalTrials
- print(f'Proportion of hits/near misses/full misses over to trials: {totalHit / totalTrials:.2f}/{totalNearMiss / totalTrials:.2f}/{totalFullMiss / totalTrials:.2f}')
- print(f'Mean happiness per hit/near miss/full miss: {happinessHit / totalHit:.2f}/{happinessNearMiss / totalNearMiss:.2f}/{happinessFullMiss / totalFullMiss:.2f}')
- print(f'Mean willingness per hit/near miss/full miss: {willingnessHit / totalHit:.2f}/{willingnessNearMiss / totalNearMiss:.2f}/{willingnessFullMiss / totalFullMiss:.2f}')
- print(f'Maximum happiness levels is: {maxHappiness} on the trial {maxHappinessTrial}')
- print(f'Minimum happiness levels is: {minHappiness} on the trial {minHappinessTrial}')
- battleshipFile.write(f'{condition},{name},{age},{gender},{totalHit / totalTrials:.2f},{totalNearMiss / totalTrials:.2f},{totalFullMiss / totalTrials:.2f},')
- battleshipFile.write(f'{happinessHit / totalHit:.2f},{happinessNearMiss / totalNearMiss:.2f},{happinessFullMiss / totalFullMiss:.2f},')
- battleshipFile.write(f'{willingnessHit / totalHit:.2f},{willingnessNearMiss / totalNearMiss:.2f},{willingnessFullMiss / totalFullMiss:.2f},')
- battleshipFile.write(f'{maxHappiness},{maxHappinessTrial},{minHappiness},{minHappinessTrial}\n')
- # fill in the information per date
- # number of participants, participants skill, participants luck, participants mixed, number of trials
- if formattedDate in participantsPerDate:
- participants = participantsPerDate[formattedDate]
- participants[0] += 1
- participants[4] += totalTrials
- if condition == 'skill':
- participants[1] += 1
- elif condition == 'luck':
- participants[2] += 1
- elif condition == 'mixed':
- participants[3] += 1
- else: # the case for the first participant on that date
- participants = [1, 0, 0, 0, totalTrials]
- if condition == 'skill':
- participants[1] = 1
- elif condition == 'luck':
- participants[2] = 1
- elif condition == 'mixed':
- participants[3] = 1
- participantsPerDate[formattedDate] = participants
- battleshipFile.close()
- for date in participantsPerDate:
- participants = participantsPerDate[date]
- resultsPerDate.write(f'{date},{participants[0]},{participants[1]},{participants[2]},{participants[3]},{participants[4]/participants[0]:.2f}\n')
- resultsPerDate.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement