File size: 11,795 Bytes
759768a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
import React, { useState } from 'react';
import { testStripGenerator } from '../../utils/testStripGenerator';

const TestStripTester = ({ onTestResult }) => {
  const [selectedScenario, setSelectedScenario] = useState('excellent_water');
  const [testOptions, setTestOptions] = useState({
    lighting: 'normal',
    background: 'white',
    addImperfections: true,
    imperfectionLevel: 'medium',
    addLabels: false
  });
  const [generatedTest, setGeneratedTest] = useState(null);
  const [testResults, setTestResults] = useState([]);

  // Safely get scenarios with fallback
  const scenarios = testStripGenerator?.getAvailableScenarios?.() || [
    { name: 'excellent_water', description: 'Excellent quality drinking water' },
    { name: 'good_water', description: 'Good quality water with minor issues' },
    { name: 'poor_water', description: 'Poor quality water needing treatment' },
    { name: 'contaminated_water', description: 'Contaminated water - unsafe for consumption' }
  ];

  const generateTestImage = () => {
    try {
      if (!testStripGenerator?.generateFromScenario) {
        console.error('Test strip generator not available');
        return;
      }
      
      const testStrip = testStripGenerator.generateFromScenario(selectedScenario, testOptions);
      setGeneratedTest(testStrip);
      
      if (onTestResult) {
        onTestResult(testStrip);
      }
    } catch (error) {
      console.error('Failed to generate test strip:', error);
      alert('Failed to generate test strip. Please try again.');
    }
  };

  const generateFullTestSuite = () => {
    try {
      if (!testStripGenerator?.generateTestSuite) {
        console.error('Test suite generator not available');
        return;
      }
      
      const testSuite = testStripGenerator.generateTestSuite({
        scenarios: ['excellent_water', 'good_water', 'poor_water', 'contaminated_water'],
        lightingConditions: ['dim', 'normal', 'bright'],
        backgrounds: ['white', 'colored']
      });
      
      setTestResults(testSuite);
      console.log('Generated test suite with', testSuite.length, 'test images');
    } catch (error) {
      console.error('Failed to generate test suite:', error);
      alert('Failed to generate test suite. Please try again.');
    }
  };

  const downloadTestSuite = () => {
    try {
      if (testResults.length === 0) {
        generateFullTestSuite();
        return;
      }

      if (!testStripGenerator?.exportTestSuite) {
        console.error('Export function not available');
        return;
      }

      const exportData = testStripGenerator.exportTestSuite(testResults);
      const blob = new Blob([exportData], { type: 'application/json' });
      const url = URL.createObjectURL(blob);
      
      const a = document.createElement('a');
      a.href = url;
      a.download = `aqua-lens-test-suite-${new Date().toISOString().split('T')[0]}.json`;
      document.body.appendChild(a);
      a.click();
      document.body.removeChild(a);
      URL.revokeObjectURL(url);
    } catch (error) {
      console.error('Failed to download test suite:', error);
      alert('Failed to download test suite. Please try again.');
    }
  };

  return (
    <div style={{ 

      background: 'linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%)',

      padding: '20px',

      borderRadius: '12px',

      border: '2px solid #2196F3',

      marginBottom: '20px'

    }}>

      <h3 style={{ color: '#1976D2', marginBottom: '20px' }}>

        🧪 AquaLens Accuracy Tester

      </h3>

      

      <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '20px', marginBottom: '20px' }}>

        {/* Scenario Selection */}

        <div>

          <label style={{ display: 'block', marginBottom: '10px', fontWeight: 'bold' }}>

            Test Scenario:

          </label>

          <select

            value={selectedScenario}

            onChange={(e) => setSelectedScenario(e.target.value)}

            style={{

              width: '100%',

              padding: '8px',

              borderRadius: '6px',

              border: '1px solid #ccc'

            }}

          >

            {scenarios.map(scenario => (

              <option key={scenario.name} value={scenario.name}>

                {scenario.description}

              </option>

            ))}

          </select>

        </div>



        {/* Test Options */}

        <div>

          <label style={{ display: 'block', marginBottom: '10px', fontWeight: 'bold' }}>

            Test Conditions:

          </label>

          <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '10px' }}>

            <select

              value={testOptions.lighting}

              onChange={(e) => setTestOptions({...testOptions, lighting: e.target.value})}

              style={{ padding: '6px', borderRadius: '4px', border: '1px solid #ccc' }}

            >

              <option value="dim">Dim Light</option>

              <option value="normal">Normal Light</option>

              <option value="bright">Bright Light</option>

            </select>

            

            <select

              value={testOptions.background}

              onChange={(e) => setTestOptions({...testOptions, background: e.target.value})}

              style={{ padding: '6px', borderRadius: '4px', border: '1px solid #ccc' }}

            >

              <option value="white">White Background</option>

              <option value="colored">Colored Background</option>

              <option value="textured">Textured Background</option>

            </select>

          </div>

        </div>

      </div>



      {/* Options Checkboxes */}

      <div style={{ marginBottom: '20px' }}>

        <label style={{ display: 'flex', alignItems: 'center', marginBottom: '8px' }}>

          <input

            type="checkbox"

            checked={testOptions.addImperfections}

            onChange={(e) => setTestOptions({...testOptions, addImperfections: e.target.checked})}

            style={{ marginRight: '8px' }}

          />

          Add realistic imperfections

        </label>

        

        <label style={{ display: 'flex', alignItems: 'center' }}>

          <input

            type="checkbox"

            checked={testOptions.addLabels}

            onChange={(e) => setTestOptions({...testOptions, addLabels: e.target.checked})}

            style={{ marginRight: '8px' }}

          />

          Add parameter labels

        </label>

      </div>



      {/* Action Buttons */}

      <div style={{ display: 'flex', gap: '10px', marginBottom: '20px' }}>

        <button

          onClick={generateTestImage}

          style={{

            padding: '10px 20px',

            background: '#2196F3',

            color: 'white',

            border: 'none',

            borderRadius: '6px',

            cursor: 'pointer',

            fontWeight: 'bold'

          }}

        >

          🎯 Generate Test Strip

        </button>

        

        <button

          onClick={generateFullTestSuite}

          style={{

            padding: '10px 20px',

            background: '#4CAF50',

            color: 'white',

            border: 'none',

            borderRadius: '6px',

            cursor: 'pointer',

            fontWeight: 'bold'

          }}

        >

          📊 Generate Test Suite ({testResults.length} tests)

        </button>

        

        <button

          onClick={downloadTestSuite}

          style={{

            padding: '10px 20px',

            background: '#FF9800',

            color: 'white',

            border: 'none',

            borderRadius: '6px',

            cursor: 'pointer',

            fontWeight: 'bold'

          }}

        >

          💾 Download Test Data

        </button>

      </div>



      {/* Generated Test Display */}

      {generatedTest && (

        <div style={{

          background: 'white',

          padding: '15px',

          borderRadius: '8px',

          border: '1px solid #ddd'

        }}>

          <h4 style={{ marginBottom: '15px', color: '#1976D2' }}>Generated Test Strip</h4>

          

          <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '20px' }}>

            <div>

              <img

                src={generatedTest.dataURL}

                alt="Generated test strip"

                style={{

                  width: '100%',

                  maxWidth: '400px',

                  border: '2px solid #ddd',

                  borderRadius: '8px'

                }}

              />

            </div>

            

            <div>

              <h5 style={{ marginBottom: '10px' }}>Expected Results:</h5>

              <div style={{ fontSize: '0.9rem', lineHeight: '1.6' }}>

                <div><strong>pH:</strong> {generatedTest.expectedResults.ph}</div>

                <div><strong>Chlorine:</strong> {generatedTest.expectedResults.chlorine} ppm</div>

                <div><strong>Nitrates:</strong> {generatedTest.expectedResults.nitrates} ppm</div>

                <div><strong>Hardness:</strong> {generatedTest.expectedResults.hardness} ppm</div>

                <div><strong>Alkalinity:</strong> {generatedTest.expectedResults.alkalinity} ppm</div>

                <div><strong>Bacteria:</strong> {generatedTest.expectedResults.bacteria ? 'Present' : 'Safe'}</div>

                <div style={{ marginTop: '10px' }}>

                  <strong>Overall Quality:</strong> 

                  <span style={{ 

                    color: generatedTest.expectedResults.overallQuality === 'Excellent' ? '#4CAF50' : 

                           generatedTest.expectedResults.overallQuality === 'Good' ? '#8BC34A' :

                           generatedTest.expectedResults.overallQuality === 'Fair' ? '#FF9800' : '#f44336',

                    fontWeight: 'bold',

                    marginLeft: '5px'

                  }}>

                    {generatedTest.expectedResults.overallQuality}

                  </span>

                </div>

                <div>

                  <strong>Safety Level:</strong>

                  <span style={{ 

                    color: generatedTest.expectedResults.safetyLevel === 'Safe' ? '#4CAF50' : 

                           generatedTest.expectedResults.safetyLevel === 'Caution' ? '#FF9800' : '#f44336',

                    fontWeight: 'bold',

                    marginLeft: '5px'

                  }}>

                    {generatedTest.expectedResults.safetyLevel}

                  </span>

                </div>

              </div>

            </div>

          </div>

        </div>

      )}



      {/* Test Suite Summary */}

      {testResults.length > 0 && (

        <div style={{

          background: 'white',

          padding: '15px',

          borderRadius: '8px',

          border: '1px solid #ddd',

          marginTop: '15px'

        }}>

          <h4 style={{ marginBottom: '10px', color: '#1976D2' }}>Test Suite Generated</h4>

          <p style={{ marginBottom: '10px' }}>

            Generated {testResults.length} test images covering various scenarios and conditions.

          </p>

          <div style={{ fontSize: '0.9rem', color: '#666' }}>

            <div>• Multiple lighting conditions (dim, normal, bright)</div>

            <div>• Different backgrounds (white, colored, textured)</div>

            <div>• Various water quality scenarios</div>

            <div>• Realistic imperfections and variations</div>

          </div>

        </div>

      )}

    </div>
  );
};

export default TestStripTester;