Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. # Here, we're creating a .csv file that organises the data files in respect of the date participation occurred
  2. newDataFile = open('by_date_results.csv', 'w')
  3. allData = sorted(listdir('results'))
  4. participationDate = {}
  5. for file in allData:
  6. datum = open('results/' + file, 'r')
  7. allLines = datum.readlines()
  8.  
  9. day = allLines[1]
  10. day = day[6:14]
  11. day = day[:2] + '-' + day[2:4] + '-' + day[4:] # Formatting such that day/month/year are easily distinguished
  12. participationDate[day] = 0
  13. totalParticipants = 0
  14.  
  15. for day in participationDate: # Collating participant's condition on each day
  16. conditionByDay = [0, 0, 0]
  17. if 'luck' in allLines[0]:
  18. conditionByDay[0] += 1
  19. totalParticipants += 1 # Collating total number of participant's per day irrespective of condition
  20. elif 'mixed' in allLines[0]:
  21. conditionByDay[1] += 1
  22. totalParticipants += 1
  23. elif 'skill' in allLines[0]:
  24. conditionByDay[2] += 1
  25. totalParticipants += 1
  26.  
  27. if day in participationDate:
  28. if 'luck' in allLines[0]:
  29. conditionByDay[0] += 1
  30. totalParticipants += 1 # Collating total number of participant's per day irrespective of condition
  31. elif 'mixed' in allLines[0]:
  32. conditionByDay[1] += 1
  33. totalParticipants += 1
  34. elif 'skill' in allLines[0]:
  35. conditionByDay[2] += 1
  36. totalParticipants += 1
  37. participationDate[day] = conditionByDay
  38.  
  39. for day in participationDate:
  40. newDataFile.write(f'{day}, {conditionByDay[0]}, {conditionByDay[1]}, {conditionByDay[2]}, {totalParticipants}\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement