Related scripts to the Master's Thesis "Exploring Sonification in Website Navigation on Smartphones"
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.9 KiB

3 months ago
  1. import os
  2. import json
  3. import pandas as pd
  4. import matplotlib.pyplot as plt
  5. import seaborn as sns
  6. data_dir = './'
  7. all_data = []
  8. all_tap_logs = []
  9. for filename in os.listdir(data_dir):
  10. if filename.endswith('.json'):
  11. file_path = os.path.join(data_dir, filename)
  12. with open(file_path, encoding='utf-8') as file:
  13. data = json.load(file)
  14. tap_logs = data.get('sensorLog', {}).get('tapLog', [])
  15. for entry in tap_logs:
  16. entry['participant_id'] = filename
  17. all_tap_logs.append(entry)
  18. df = pd.DataFrame(all_tap_logs)
  19. df['timestamp'] = pd.to_datetime(df['timestamp'])
  20. df['path'] = df['url'].apply(lambda x: x.split('://')[-1].split('/', 1)[-1])
  21. # Mapping with tour_operators being mergeable to study page 2. :)
  22. path_to_label = {
  23. "study-page-1": "Study Page 1",
  24. "study-page-2": "Study Page 2",
  25. "study-page-3": "Study Page 3",
  26. "study-page-4": "Study Page 4",
  27. "study-page-5": "Study Page 5",
  28. "study-page-6": "Study Page 6",
  29. #"tour_operators": "Study Page 2"
  30. }
  31. df['label'] = df['path'].map(path_to_label)
  32. grouped = df.groupby('label')
  33. # JSON list structure
  34. def generate_heatmap_data(group):
  35. heatmap_data = group[['x', 'y']].copy()
  36. heatmap_data['radius'] = 40
  37. heatmap_data['value'] = 5
  38. heatmap_data['x'] = heatmap_data['x'].astype(str)
  39. heatmap_data['y'] = heatmap_data['y'].astype(str)
  40. heatmap_data_list = heatmap_data.to_dict(orient='records')
  41. min_value = 1
  42. max_value = 9999
  43. return {
  44. "min": min_value,
  45. "max": max_value,
  46. "data": heatmap_data_list
  47. }
  48. for label, group in grouped:
  49. heatmap_data = generate_heatmap_data(group.apply(lambda x: round(x)))
  50. json_filename = f"{label.replace(' ', '_').lower()}.json"
  51. with open(json_filename, 'w', encoding='utf-8') as json_file:
  52. json.dump(heatmap_data, json_file, indent=4)
  53. print(f"Generated {json_filename} with {len(heatmap_data)} records.")