dschandra commited on
Commit
debd79d
·
verified ·
1 Parent(s): ce13d4f

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +37 -29
static/script.js CHANGED
@@ -7,8 +7,20 @@ document.getElementById('lbw-form').addEventListener('submit', function(e) {
7
  })
8
  .then(response => response.json())
9
  .then(data => {
10
- document.getElementById('decision').textContent = `Decision: ${data.decision} (Confidence: ${data.confidence})`;
11
- drawPitch(data.actual_path, data.projected_path, data.pitching, data.impact);
 
 
 
 
 
 
 
 
 
 
 
 
12
  });
13
  });
14
 
@@ -16,25 +28,20 @@ function drawPitch(actualPath, projectedPath, pitching, impact) {
16
  const canvas = document.getElementById('pitchCanvas');
17
  const ctx = canvas.getContext('2d');
18
 
19
- // Clear canvas
20
  ctx.clearRect(0, 0, canvas.width, canvas.height);
21
 
22
- // Draw pitch (22 yards scaled to 600px height, 10 feet scaled to 400px width)
23
- ctx.fillStyle = '#90EE90'; // Light green for pitch
24
  ctx.fillRect(50, 50, 300, 500);
25
 
26
- // Draw stumps (at y=1, scaled to canvas)
27
  ctx.fillStyle = '#FFF';
28
- ctx.fillRect(190, 50, 20, 10); // Top stumps
29
 
30
- // Draw creases
31
  ctx.strokeStyle = '#000';
32
  ctx.beginPath();
33
- ctx.moveTo(50, 150); ctx.lineTo(350, 150); // Popping crease
34
- ctx.moveTo(200, 50); ctx.lineTo(200, 150); // Middle stump line
35
  ctx.stroke();
36
 
37
- // Scale coordinates (x: 0-1 to 50-350, y: 0-1 to 550-50)
38
  function scalePoint(point) {
39
  return {
40
  x: 50 + point.x * 300,
@@ -42,33 +49,34 @@ function drawPitch(actualPath, projectedPath, pitching, impact) {
42
  };
43
  }
44
 
45
- // Draw actual path (red arc)
46
- ctx.strokeStyle = 'red';
47
- ctx.lineWidth = 2;
48
- ctx.beginPath();
49
- const actualScaled = actualPath.map(scalePoint);
50
- ctx.moveTo(actualScaled[0].x, actualScaled[0].y);
51
- for (let i = 1; i < actualScaled.length; i++) {
52
- ctx.lineTo(actualScaled[i].x, actualScaled[i].y);
 
 
53
  }
54
- ctx.stroke();
55
 
56
- // Draw projected path (blue line)
57
- ctx.strokeStyle = 'blue';
58
- ctx.beginPath();
59
- const projectedScaled = projectedPath.map(scalePoint);
60
- ctx.moveTo(projectedScaled[0].x, projectedScaled[0].y);
61
- ctx.lineTo(projectedScaled[1].x, projectedScaled[1].y);
62
- ctx.stroke();
 
 
63
 
64
- // Draw pitching point
65
  const pitchPt = scalePoint(pitching);
66
  ctx.fillStyle = 'black';
67
  ctx.beginPath();
68
  ctx.arc(pitchPt.x, pitchPt.y, 5, 0, 2 * Math.PI);
69
  ctx.fill();
70
 
71
- // Draw impact point
72
  const impactPt = scalePoint(impact);
73
  ctx.fillStyle = 'orange';
74
  ctx.beginPath();
 
7
  })
8
  .then(response => response.json())
9
  .then(data => {
10
+ if (data.error) {
11
+ document.getElementById('decision').textContent = `Error: ${data.error}`;
12
+ } else {
13
+ document.getElementById('decision').textContent = `Decision: ${data.decision} (Confidence: ${data.confidence})`;
14
+ document.getElementById('details').innerHTML = `
15
+ Pitching: ${data.pitching.status}<br>
16
+ Impact: ${data.impact.status}<br>
17
+ Wickets: ${data.wicket}
18
+ `;
19
+ drawPitch(data.actual_path, data.projected_path, data.pitching, data.impact);
20
+ }
21
+ })
22
+ .catch(error => {
23
+ document.getElementById('decision').textContent = `Error: ${error.message}`;
24
  });
25
  });
26
 
 
28
  const canvas = document.getElementById('pitchCanvas');
29
  const ctx = canvas.getContext('2d');
30
 
 
31
  ctx.clearRect(0, 0, canvas.width, canvas.height);
32
 
33
+ ctx.fillStyle = '#90EE90';
 
34
  ctx.fillRect(50, 50, 300, 500);
35
 
 
36
  ctx.fillStyle = '#FFF';
37
+ ctx.fillRect(190, 50, 20, 10);
38
 
 
39
  ctx.strokeStyle = '#000';
40
  ctx.beginPath();
41
+ ctx.moveTo(50, 150); ctx.lineTo(350, 150);
42
+ ctx.moveTo(200, 50); ctx.lineTo(200, 150);
43
  ctx.stroke();
44
 
 
45
  function scalePoint(point) {
46
  return {
47
  x: 50 + point.x * 300,
 
49
  };
50
  }
51
 
52
+ if (actualPath.length > 0) {
53
+ ctx.strokeStyle = 'red';
54
+ ctx.lineWidth = 2;
55
+ ctx.beginPath();
56
+ const actualScaled = actualPath.map(scalePoint);
57
+ ctx.moveTo(actualScaled[0].x, actualScaled[0].y);
58
+ for (let i = 1; i < actualScaled.length; i++) {
59
+ ctx.lineTo(actualScaled[i].x, actualScaled[i].y);
60
+ }
61
+ ctx.stroke();
62
  }
 
63
 
64
+ if (projectedPath.length > 0) {
65
+ ctx.strokeStyle = 'blue';
66
+ ctx.lineWidth = 2;
67
+ ctx.beginPath();
68
+ const projectedScaled = projectedPath.map(scalePoint);
69
+ ctx.moveTo(projectedScaled[0].x, projectedScaled[0].y);
70
+ ctx.lineTo(projectedScaled[1].x, projectedScaled[1].y);
71
+ ctx.stroke();
72
+ }
73
 
 
74
  const pitchPt = scalePoint(pitching);
75
  ctx.fillStyle = 'black';
76
  ctx.beginPath();
77
  ctx.arc(pitchPt.x, pitchPt.y, 5, 0, 2 * Math.PI);
78
  ctx.fill();
79
 
 
80
  const impactPt = scalePoint(impact);
81
  ctx.fillStyle = 'orange';
82
  ctx.beginPath();