Untitled
unknown
javascript
a year ago
5.7 kB
6
Indexable
try { var pointModels = response.data.map((d) => PointModel.fromJson(d)); console.log("point models:", pointModels); const seenTimes = new Set(); pointModels = pointModels.filter((point) => { if (seenTimes.has(point.time)) { return false; } else { seenTimes.add(point.time); return true; } }); const frameWidth = this.childRef.current.webcamRef.current.video.width; const pxMeter = 10 / (frameWidth * 0.95); const isRight = !(pointModels[0].boxesfx.fx1 <= frameWidth * 0.5); const firstMean = isRight ? pointModels[0].boxesfx.fx1 : pointModels[0].boxesfx.fx2; const firstCenterMean = (pointModels[0].boxesfx.fx1 + pointModels[0].boxesfx.fx2) / 2; const bodyPx = Math.abs(pointModels[0].boxesfx.fy1 - pointModels[0].boxesfx.fy2); var startTime; var startCenterTime; var isFinish; var isFinishCenter; console.log("frameWidth", frameWidth); console.log("firstCenterMean", firstCenterMean); console.log("isRight", isRight); console.log("firstMean", firstMean); console.log("bodyPx", bodyPx); var chartValues = []; chartValues.push({ time: 0, distance: 0, velocity: 0 }); for (let i = 0; i < pointModels.length; i++) { const point = pointModels[i]; const currentMean = isRight ? point.boxesfx.fx1 : point.boxesfx.fx2; const currentCenterMean = (point.boxesfx.fx1 + point.boxesfx.fx2) / 2; if (i < pointModels.length - 1) { const pointPlus = pointModels[i + 1]; const currentPlusMean = isRight ? pointPlus.boxesfx.fx1 : pointPlus.boxesfx.fx2; const distance = Math.abs(currentPlusMean - currentMean) * pxMeter; const vel = distance / (pointPlus.time - point.time); chartValues.push({ time: pointPlus.time, distance: currentPlusMean * pxMeter, velocity: vel }); } if (startTime === undefined && Math.abs(firstMean - currentMean) > 0.1 * bodyPx) { startTime = point.time; } if (startCenterTime === undefined && Math.abs(firstCenterMean - currentCenterMean) > 0.1 * bodyPx) { startCenterTime = point.time; } if ( isFinish !== true && startTime !== undefined && isRight === false ? currentMean >= frameWidth * 0.95 : currentMean <= frameWidth * 0.05 ) { isFinish = true; const time = round(point.time - startTime, 2); const velocity = round(this.props.meter / time, 2); const acceleration = round(velocity / time, 2); const power = round((this.student.agirlik * this.props.meter) / time, 2); console.log("run time:", time); console.log("velocity:", velocity); console.log("acceleration:", acceleration); console.log("power:", power); var lastData = this.state.jumpDatas[this.state.jumpDatas.length - 1]; var newDatas = this.state.jumpDatas.filter((v, i) => i !== this.state.jumpDatas.length - 1); this.updateState({ jumpDatas: [ ...newDatas, new SprintTestStatesModel({ jumpType: this.jumpType, range: this.props.meter, actionTime: time, power: round(power, 2), velocity: round(velocity, 2), acceleration: round(acceleration, 2), heights: chartValues.map((d) => { return { time: d.time, value: d.distance }; }), velecities: ReportFuncs.modifyVelocityList( chartValues.map((d) => { return { time: d.time, value: d.velocity }; }) ), points: [], imgStanding: lastData.imgStanding, imgBraking: lastData.imgBraking, imgJumping: lastData.imgJumping, }), ], }); } if ( isFinishCenter !== true && startCenterTime !== undefined && isRight === false ? currentCenterMean >= frameWidth * 0.95 : currentCenterMean <= frameWidth * 0.05 ) { isFinishCenter = true; const time2 = round(point.time - startCenterTime, 2); const velocity2 = round(this.props.meter / time2, 2); const acceleration2 = round(velocity2 / time2, 2); const power2 = round((this.student.agirlik * this.props.meter) / time2, 2); console.log("center run time:", time2); console.log("center velocity:", velocity2); console.log("center acceleration:", acceleration2); console.log("center power:", power2); } } } catch (error) { console.error("Error response:", error); }
Editor is loading...
Leave a Comment