Denis Thiessen
6 months ago
10 changed files with 140 additions and 92 deletions
-
43package-lock.json
-
3package.json
-
75src/App.js
-
2src/components/webpage_container/StudySite.jsx
-
5src/core/audio/AudioHandler.jsx
-
15src/core/log/RouteTracker.jsx
-
54src/core/log/SensorLogger.jsx
-
4src/index.css
-
7src/index.js
-
20src/pages/TestPage.jsx
@ -0,0 +1,15 @@ |
|||
import React, { useEffect } from 'react'; |
|||
import { useLocation } from 'react-router-dom'; |
|||
import { pushToVisitLog } from './SensorLogger'; |
|||
|
|||
const RouteTracker = () => { |
|||
const location = useLocation(); |
|||
|
|||
useEffect(() => { |
|||
pushToVisitLog({ pathname: location.pathname, timestamp: new Date() }); |
|||
}, [location.pathname]); |
|||
|
|||
return null; |
|||
}; |
|||
|
|||
export default RouteTracker; |
@ -1,33 +1,47 @@ |
|||
import {Component} from 'react'; |
|||
import { getState, setState } from '../../App'; |
|||
|
|||
export class SensorLogger extends Component { |
|||
static sensorLog = {mouseLog: [], orientationLog: [], clickedElements: [], visitedSites: [], playedSonifications: []}; |
|||
|
|||
static pushToMouseLog(logElement) { |
|||
this.sensorLog.mouseLog.push(logElement); |
|||
export function pushToMouseLog(logElement) { |
|||
const sensorLog = getState().sensorLog; |
|||
sensorLog.mouseLog.push(logElement); |
|||
setState({ sensorLog: sensorLog }); |
|||
} |
|||
|
|||
static pushToOrientationLog(logElement) { |
|||
this.sensorLog.orientationLog.push(logElement); |
|||
} |
|||
export function pushToClickLog(logElement) { |
|||
// Filter out dummy body objects |
|||
if(logElement.target.localName === "body") { |
|||
return; |
|||
} |
|||
|
|||
static pushToClickLog(logElement) { |
|||
this.sensorLog.clickedElements.push(logElement); |
|||
const sensorLog = getState().sensorLog; |
|||
sensorLog.clickedElements.push(logElement); |
|||
setState({ sensorLog: sensorLog }); |
|||
} |
|||
|
|||
static pushToVisitLog(logElement) { |
|||
this.sensorLog.visitedSites.push(logElement); |
|||
export function pushToVisitLog(logElement) { |
|||
const sensorLog = getState().sensorLog; |
|||
|
|||
// Filter out double visit pushes... |
|||
const visitedSitesAmount = sensorLog.visitedSites.length; |
|||
if(visitedSitesAmount > 0) { |
|||
const lastVisitedElement = sensorLog.visitedSites[visitedSitesAmount - 1]; |
|||
if(lastVisitedElement.path === logElement.path && logElement.timestamp - lastVisitedElement.timestamp < 500) { |
|||
return; |
|||
} |
|||
sensorLog.visitedSites.push(logElement); |
|||
setState({ sensorLog: sensorLog }); |
|||
} |
|||
} |
|||
|
|||
static pushToSonificationLog(logElement) { |
|||
this.sensorLog.playedSonifications.push(logElement); |
|||
export function pushToSonificationLog(logElement) { |
|||
const sensorLog = getState().sensorLog; |
|||
sensorLog.playedSonifications.push(logElement); |
|||
setState({ sensorLog: sensorLog }); |
|||
} |
|||
|
|||
static getSensorLog() { |
|||
return this.sensorLog; |
|||
export function getSensorLog() { |
|||
return getState().sensorLog; |
|||
} |
|||
|
|||
static resetSensorLog() { |
|||
this.sensorLog = {mouseLog: [], orientationLog: [], clickedElements: [], visitedSites: [], playedSonifications: []}; |
|||
export function resetSensorLog() { |
|||
setState({ sensorLog: {mouseLog: [], clickedElements: [], visitedSites: [], playedSonifications: []}}); |
|||
} |
|||
} |
@ -1,18 +1,16 @@ |
|||
import React from "react"; |
|||
import { getTranslation } from "../core/i18n/I18NHandler"; |
|||
import WebpageBanner from "../components/webpage_container/WebpageBanner"; |
|||
import { SensorLogger } from "../core/log/SensorLogger"; |
|||
import { StudySite, getHeatmapData } from "../components/webpage_container/StudySite"; |
|||
import { pushToMouseLog, getSensorLog } from "../core/log/SensorLogger"; |
|||
|
|||
export default class TestPage extends React.Component { |
|||
|
|||
|
|||
|
|||
render() { |
|||
var clickFunction = function(){ |
|||
SensorLogger.pushToMouseLog(getHeatmapData()); |
|||
console.log(SensorLogger.getSensorLog()); |
|||
function TestPage() { |
|||
var clickFunction = function() { |
|||
pushToMouseLog(getHeatmapData()); |
|||
console.log(getSensorLog()); |
|||
alert(JSON.stringify(getSensorLog())); |
|||
}; |
|||
return (<StudySite><WebpageBanner translationKey="hello_world" /><p onMouseOver={clickFunction}>{getTranslation("hello_world")}</p><button>Teeest</button></StudySite>); |
|||
} |
|||
return (<StudySite><WebpageBanner translationKey="hello_world" /><p onClick={clickFunction}>{getTranslation("hello_world")}</p><button>Teeest</button></StudySite>); |
|||
} |
|||
|
|||
export default TestPage; |
Write
Preview
Loading…
Cancel
Save
Reference in new issue