Browse Source

feat: Added log features and elements.

master
Denis Thiessen 5 months ago
parent
commit
e2341d15db
  1. 2
      src/components/DownloadButton.jsx
  2. 32
      src/components/webpage_container/StudySite.jsx
  3. 2
      src/core/Constants.jsx
  4. 6
      src/core/log/SensorLogger.jsx

2
src/components/DownloadButton.jsx

@ -3,7 +3,6 @@ import { getTranslation } from "../core/i18n/I18NHandler";
import { getSensorLog } from "../core/log/SensorLogger"; import { getSensorLog } from "../core/log/SensorLogger";
import { Button } from "@geist-ui/core"; import { Button } from "@geist-ui/core";
import { getUserID } from "./RandomIDComponent"; import { getUserID } from "./RandomIDComponent";
import { PARTICIPANT_NUMBER } from "../core/Constants";
function DownloadButton() { function DownloadButton() {
const downloadFile = ({ data, fileName, fileType }) => { const downloadFile = ({ data, fileName, fileType }) => {
@ -23,7 +22,6 @@ function DownloadButton() {
const userData = { const userData = {
participantId: getUserID(), participantId: getUserID(),
sensorLog: getSensorLog(), sensorLog: getSensorLog(),
participantNumber: PARTICIPANT_NUMBER,
}; };
const exportToJson = (e) => { const exportToJson = (e) => {

32
src/components/webpage_container/StudySite.jsx

@ -48,7 +48,15 @@ export function StudySite(props) {
var y = event.pageY; var y = event.pageY;
// Add data to the heatmap // Add data to the heatmap
heatmapInstance.addData({ x: x, y: y, value: 1 });
const currentTime = new Date();
const websiteLocation = window.location.href;
heatmapInstance.addData({
x: x,
y: y,
value: 1,
timestamp: currentTime,
url: websiteLocation,
});
}); });
document.addEventListener("scroll", function (event) { document.addEventListener("scroll", function (event) {
@ -61,7 +69,15 @@ export function StudySite(props) {
var y = event.pageY; var y = event.pageY;
// Add more value for clicks // Add more value for clicks
heatmapInstance.addData({ x: x, y: y, value: 5 });
const currentTime = new Date();
const websiteLocation = window.location.href;
heatmapInstance.addData({
x: x,
y: y,
value: 5,
timestamp: currentTime,
url: websiteLocation,
});
updateHeatmapSize(); updateHeatmapSize();
}); });
@ -97,10 +113,14 @@ export function StudySite(props) {
for (let i = 0; i < touches.length; i++) { for (let i = 0; i < touches.length; i++) {
ongoingTouches.push(copyTouch(touches[i])); ongoingTouches.push(copyTouch(touches[i]));
const currentTime = new Date();
const websiteLocation = window.location.href;
heatmapInstance.addData({ heatmapInstance.addData({
x: touches[i].pageX, x: touches[i].pageX,
y: touches[i].pageY, y: touches[i].pageY,
value: 5, value: 5,
timestamp: currentTime,
url: websiteLocation,
}); });
} }
}; };
@ -112,10 +132,14 @@ export function StudySite(props) {
const idx = ongoingTouchIndexById(touches[i].identifier); const idx = ongoingTouchIndexById(touches[i].identifier);
if (idx >= 0) { if (idx >= 0) {
const currentTime = new Date();
const websiteLocation = window.location.href;
heatmapInstance.addData({ heatmapInstance.addData({
x: touches[i].pageX, x: touches[i].pageX,
y: touches[i].pageY, y: touches[i].pageY,
value: 5, value: 5,
timestamp: currentTime,
url: websiteLocation,
}); });
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
@ -132,10 +156,14 @@ export function StudySite(props) {
let idx = ongoingTouchIndexById(touches[i].identifier); let idx = ongoingTouchIndexById(touches[i].identifier);
if (idx >= 0) { if (idx >= 0) {
const currentTime = new Date();
const websiteLocation = window.location.href;
heatmapInstance.addData({ heatmapInstance.addData({
x: touches[i].pageX, x: touches[i].pageX,
y: touches[i].pageY, y: touches[i].pageY,
value: 5, value: 5,
timestamp: currentTime,
url: websiteLocation,
}); });
ongoingTouches.splice(idx, 1); // remove it; we're done ongoingTouches.splice(idx, 1); // remove it; we're done

2
src/core/Constants.jsx

@ -1,4 +1,4 @@
export const MOUSE_MODE = true; export const MOUSE_MODE = true;
export const HEATMAP_MAX = 999; export const HEATMAP_MAX = 999;
export const PARTICIPANT_NUMBER = 9;
export const PARTICIPANT_NUMBER = 1;

6
src/core/log/SensorLogger.jsx

@ -3,9 +3,11 @@ import { getState, setState } from "../../App";
export function pushToMouseLog(logElement) { export function pushToMouseLog(logElement) {
const sensorLog = getState().sensorLog; const sensorLog = getState().sensorLog;
const currentTime = new Date(); const currentTime = new Date();
const websiteLocation = window.location.href;
const mouseLogElement = { const mouseLogElement = {
mouseLog: logElement, mouseLog: logElement,
timestamp: currentTime, timestamp: currentTime,
url: websiteLocation
}; };
sensorLog.mouseLog.push(mouseLogElement); sensorLog.mouseLog.push(mouseLogElement);
setState({ sensorLog: sensorLog }); setState({ sensorLog: sensorLog });
@ -19,12 +21,14 @@ export function pushToClickLog(logElement) {
const generateLogElement = (el) => { const generateLogElement = (el) => {
const currentTime = new Date(); const currentTime = new Date();
const websiteLocation = window.location.href;
return { return {
target: el.target.outerHTML, target: el.target.outerHTML,
type: el.type, type: el.type,
x: el.x, x: el.x,
y: el.y, y: el.y,
timestamp: currentTime, timestamp: currentTime,
url: websiteLocation
}; };
}; };
@ -66,9 +70,11 @@ export function pushToVisitLog(logElement) {
export function pushToSonificationLog(logElement) { export function pushToSonificationLog(logElement) {
const sensorLog = getState().sensorLog; const sensorLog = getState().sensorLog;
const currentTime = new Date(); const currentTime = new Date();
const websiteLocation = window.location.href;
const sonificationLogElement = { const sonificationLogElement = {
sonificationLog: logElement, sonificationLog: logElement,
timestamp: currentTime, timestamp: currentTime,
url: websiteLocation
}; };
sensorLog.playedSonifications.push(sonificationLogElement); sensorLog.playedSonifications.push(sonificationLogElement);
setState({ sensorLog: sensorLog }); setState({ sensorLog: sensorLog });

Loading…
Cancel
Save