voices_to_csv.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. headers = ['id', 'shape id', 'age', 'gender', 'education', 'birth place', 'current place', 'non native', 'area name', 'sound example', 'associations', 'correctness', 'friendliness', 'pleasantness', 'trustworthiness']
  2. EDUCATION = {
  3. '1': 'High school or lower',
  4. '2': 'Bachelors',
  5. '3': 'Masters',
  6. '4': 'Doctorate'
  7. }
  8. NON_NATIVE = {
  9. '1': 'Less than two years',
  10. '2': '3-5 years',
  11. '3': '6-10 years',
  12. '4': '10+ years'
  13. }
  14. AGE = {
  15. '1': '16 - 17',
  16. '2': '18 - 25',
  17. '3': '26 - 45',
  18. '4': '46 - 65',
  19. '5': '66 - 75',
  20. '6': '75+'
  21. }
  22. def map_entry_to_rows(entry, _id):
  23. pi = entry['personalInformation']
  24. personalInformation = [
  25. AGE[pi['age']],
  26. pi['genderCustom'] if pi['gender'] == 'other' else pi['gender'],
  27. ', '.join(list(map(lambda e: EDUCATION[e], pi['levelEducation']))),
  28. pi['birthPlace'],
  29. pi['currentPlace'],
  30. NON_NATIVE.get(pi['nonNative'], '-'),
  31. ]
  32. for i, subentry in enumerate(entry['canvas']):
  33. form = subentry['form']
  34. ret = personalInformation + [
  35. form['name'],
  36. form['soundExample'] or '-',
  37. ', '.join(form['associations']),
  38. form['correctness'],
  39. form['friendliness'],
  40. form['pleasantness'],
  41. form['trustworthiness']
  42. ]
  43. yield [_id, i] + ret