Browse Source

feat: Added tap log as a backup measure.

master
Denis Thiessen 4 months ago
parent
commit
7e85253aa4
  1. 1
      src/App.js
  2. 31
      src/components/webpage_container/StudySite.jsx
  3. 15
      src/core/log/SensorLogger.jsx

1
src/App.js

@ -63,6 +63,7 @@ export const sensorLogState = createStore(
() => ({ () => ({
sensorLog: { sensorLog: {
mouseLog: [], mouseLog: [],
tapLog: [],
clickedElements: [], clickedElements: [],
visitedSites: [], visitedSites: [],
playedSonifications: [], playedSonifications: [],

31
src/components/webpage_container/StudySite.jsx

@ -1,6 +1,7 @@
import React, { useEffect } from "react"; import React, { useEffect } from "react";
import h337 from "heatmap.js"; import h337 from "heatmap.js";
import { HEATMAP_MAX } from "../../core/Constants"; import { HEATMAP_MAX } from "../../core/Constants";
import { pushToTapLog } from "../../core/log/SensorLogger";
var stopInput = false; var stopInput = false;
@ -50,13 +51,15 @@ export function StudySite(props) {
// Add data to the heatmap // Add data to the heatmap
const currentTime = new Date(); const currentTime = new Date();
const websiteLocation = window.location.href; const websiteLocation = window.location.href;
heatmapInstance.addData({
const data = {
x: x, x: x,
y: y, y: y,
value: 1, value: 1,
timestamp: currentTime, timestamp: currentTime,
url: websiteLocation, url: websiteLocation,
});
};
heatmapInstance.addData(data);
pushToTapLog(data);
}); });
document.addEventListener("scroll", function (event) { document.addEventListener("scroll", function (event) {
@ -71,13 +74,15 @@ export function StudySite(props) {
// Add more value for clicks // Add more value for clicks
const currentTime = new Date(); const currentTime = new Date();
const websiteLocation = window.location.href; const websiteLocation = window.location.href;
heatmapInstance.addData({
const data = {
x: x, x: x,
y: y, y: y,
value: 5, value: 5,
timestamp: currentTime, timestamp: currentTime,
url: websiteLocation, url: websiteLocation,
});
};
heatmapInstance.addData(data);
pushToTapLog(data);
updateHeatmapSize(); updateHeatmapSize();
}); });
@ -115,13 +120,15 @@ export function StudySite(props) {
ongoingTouches.push(copyTouch(touches[i])); ongoingTouches.push(copyTouch(touches[i]));
const currentTime = new Date(); const currentTime = new Date();
const websiteLocation = window.location.href; const websiteLocation = window.location.href;
heatmapInstance.addData({
const data = {
x: touches[i].pageX, x: touches[i].pageX,
y: touches[i].pageY, y: touches[i].pageY,
value: 5, value: 5,
timestamp: currentTime, timestamp: currentTime,
url: websiteLocation, url: websiteLocation,
});
};
heatmapInstance.addData(data);
pushToTapLog(data);
} }
}; };
@ -134,13 +141,15 @@ export function StudySite(props) {
if (idx >= 0) { if (idx >= 0) {
const currentTime = new Date(); const currentTime = new Date();
const websiteLocation = window.location.href; const websiteLocation = window.location.href;
heatmapInstance.addData({
const data = {
x: touches[i].pageX, x: touches[i].pageX,
y: touches[i].pageY, y: touches[i].pageY,
value: 5, value: 5,
timestamp: currentTime, timestamp: currentTime,
url: websiteLocation, url: websiteLocation,
});
};
heatmapInstance.addData(data);
pushToTapLog(data);
ongoingTouches.splice(idx, 1, copyTouch(touches[i])); // swap in the new touch record ongoingTouches.splice(idx, 1, copyTouch(touches[i])); // swap in the new touch record
} else { } else {
@ -158,13 +167,15 @@ export function StudySite(props) {
if (idx >= 0) { if (idx >= 0) {
const currentTime = new Date(); const currentTime = new Date();
const websiteLocation = window.location.href; const websiteLocation = window.location.href;
heatmapInstance.addData({
const data = {
x: touches[i].pageX, x: touches[i].pageX,
y: touches[i].pageY, y: touches[i].pageY,
value: 5, value: 5,
timestamp: currentTime, timestamp: currentTime,
url: websiteLocation, url: websiteLocation,
});
};
heatmapInstance.addData(data);
pushToTapLog(data);
ongoingTouches.splice(idx, 1); // remove it; we're done ongoingTouches.splice(idx, 1); // remove it; we're done
} else { } else {

15
src/core/log/SensorLogger.jsx

@ -7,12 +7,20 @@ export function pushToMouseLog(logElement) {
const mouseLogElement = { const mouseLogElement = {
mouseLog: logElement, mouseLog: logElement,
timestamp: currentTime, timestamp: currentTime,
url: websiteLocation
url: websiteLocation,
}; };
sensorLog.mouseLog.push(mouseLogElement); sensorLog.mouseLog.push(mouseLogElement);
setState({ sensorLog: sensorLog }); setState({ sensorLog: sensorLog });
} }
// Only exists as a backup for tracking, due to heatmap.js deleting other values in object.
export function pushToTapLog(logElement) {
const sensorLog = getState().sensorLog;
// It already has time and URL data at this point. :)
sensorLog.tapLog.push(logElement);
setState({ sensorLog: sensorLog });
}
export function pushToClickLog(logElement) { export function pushToClickLog(logElement) {
// Filter out dummy body objects // Filter out dummy body objects
if (logElement.target.localName === "body") { if (logElement.target.localName === "body") {
@ -28,7 +36,7 @@ export function pushToClickLog(logElement) {
x: el.x, x: el.x,
y: el.y, y: el.y,
timestamp: currentTime, timestamp: currentTime,
url: websiteLocation
url: websiteLocation,
}; };
}; };
@ -74,7 +82,7 @@ export function pushToSonificationLog(logElement) {
const sonificationLogElement = { const sonificationLogElement = {
sonificationLog: logElement, sonificationLog: logElement,
timestamp: currentTime, timestamp: currentTime,
url: websiteLocation
url: websiteLocation,
}; };
sensorLog.playedSonifications.push(sonificationLogElement); sensorLog.playedSonifications.push(sonificationLogElement);
setState({ sensorLog: sensorLog }); setState({ sensorLog: sensorLog });
@ -88,6 +96,7 @@ export function resetSensorLog() {
setState({ setState({
sensorLog: { sensorLog: {
mouseLog: [], mouseLog: [],
tapLog: [],
clickedElements: [], clickedElements: [],
visitedSites: [], visitedSites: [],
playedSonifications: [], playedSonifications: [],

Loading…
Cancel
Save