-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagc1.php
More file actions
658 lines (593 loc) · 24.1 KB
/
agc1.php
File metadata and controls
658 lines (593 loc) · 24.1 KB
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>AI Grow Light Calculator — Professional UI</title>
<!-- Vue 3 CDN -->
<script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
<!-- jsPDF & html2canvas for PDF generation -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
<style>
/* --- Clean modern UI --- */
:root{
--accent:#ef8b25;
--muted:#6b7280;
--bg:#f7f7f8;
--card:#ffffff;
--glass: rgba(255,255,255,0.7);
--radius:14px;
--shadow: 0 6px 18px rgba(18,24,38,0.06);
font-family: Inter, "Segoe UI", Roboto, "Helvetica Neue", Arial;
}
body{
margin:0;
background: linear-gradient(180deg,#fafafa 0%, #f0f4f8 100%);
color:#111827;
-webkit-font-smoothing:antialiased;
-moz-osx-font-smoothing:grayscale;
padding:32px;
}
.container{
max-width:1100px;
margin:0 auto;
}
.hero{
text-align:center;
margin-bottom:22px;
}
.title{
font-family: "Georgia", serif;
font-size:36px;
letter-spacing:0.5px;
margin:0 0 6px;
}
.subtitle{
color:var(--muted);
font-size:15px;
margin-bottom:18px;
}
.grid{
display:grid;
grid-template-columns: 1fr 420px;
gap:20px;
align-items:start;
}
@media (max-width:980px){
.grid{ grid-template-columns:1fr; padding:0 12px; }
}
.card{
background:var(--card);
border-radius:var(--radius);
box-shadow:var(--shadow);
padding:20px;
}
label{
display:block;
font-weight:600;
margin-bottom:6px;
font-size:13px;
}
.field{
margin-bottom:12px;
}
input[type="number"], input[type="text"], select{
width:100%;
padding:10px 12px;
border-radius:10px;
border:1px solid #e6e7ea;
font-size:14px;
background:linear-gradient(180deg,#fff,#fbfbfb);
box-sizing:border-box;
}
.row{
display:flex;
gap:10px;
}
.row > div{ flex:1; }
.btn{
display:inline-block;
background:var(--accent);
color:white;
border:none;
padding:10px 16px;
border-radius:999px;
font-weight:700;
cursor:pointer;
box-shadow: 0 6px 18px rgba(239,139,37,0.18);
}
.btn.secondary{
background:#111827;
box-shadow:none;
border-radius:10px;
}
.report{
margin-top:14px;
padding:14px;
border-radius:12px;
background:linear-gradient(180deg,rgba(239,139,37,0.06), rgba(239,139,37,0.02));
border:1px solid rgba(239,139,37,0.07);
}
.kpi{
display:flex;
gap:12px;
flex-wrap:wrap;
}
.kpi .item{
background:var(--card);
border-radius:10px;
padding:10px;
flex:1 1 160px;
box-shadow:0 6px 18px rgba(2,6,23,0.03);
}
.small{ font-size:12px; color:var(--muted); margin-bottom:6px;}
.big{ font-size:18px; font-weight:800; color:#111827; }
.muted{ color:var(--muted); }
.footer-actions{
display:flex;
gap:10px;
margin-top:12px;
flex-wrap:wrap;
}
/* nice image card for presets */
.preset{
border-radius:10px;
overflow:hidden;
display:flex;
align-items:center;
justify-content:space-between;
padding:12px;
gap:10px;
}
.preset .left{flex:1}
.preset h4{ margin:0 0 6px; font-size:16px}
.preset p{ margin:0; font-size:13px; color:var(--muted) }
/* report table */
table{ width:100%; border-collapse:collapse; margin-top:8px }
th,td{ padding:8px 10px; text-align:left; border-bottom:1px dashed #eef2f6; font-size:13px }
th{ color:var(--muted); font-weight:700; }
/* small helpers */
.note{ font-size:12px; color:var(--muted); margin-top:8px;}
.chip{ display:inline-block; background:#fff; border-radius:999px; padding:4px 10px; border:1px solid #eee; font-weight:600; font-size:13px; }
</style>
</head>
<body>
<div id="app" class="container">
<div class="hero">
<div class="title">AI Grow Light Calculator</div>
<div class="subtitle">Data-driven lighting advice for greenhouse & indoor farming — reduce energy costs and maximize yield</div>
</div>
<div class="grid">
<!-- Left: main controls -->
<div>
<div class="card">
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:12px;">
<div>
<div style="font-weight:800; font-size:18px">Your Application</div>
<div class="note">Enter crop, area and lighting preferences — results update live.</div>
</div>
<div class="chip">Client-side • No backend required</div>
</div>
<!-- form -->
<div class="field">
<label>Crop</label>
<select v-model="form.crop">
<option v-for="(c,i) in crops" :key="i" :value="c.key">{{c.name}}</option>
</select>
</div>
<div class="row">
<div class="field">
<label>Growth stage</label>
<select v-model="form.stage">
<option v-for="s in stages" :value="s.key">{{s.label}}</option>
</select>
</div>
<div class="field">
<label>Desired DLI (mol·m⁻²·day⁻¹)</label>
<input type="number" v-model.number="form.desiredDLI" min="0" step="0.1"/>
</div>
</div>
<div class="row">
<div class="field">
<label>Area Width (m)</label>
<input type="number" v-model.number="form.width" min="0.1" step="0.1"/>
</div>
<div class="field">
<label>Area Length (m)</label>
<input type="number" v-model.number="form.length" min="0.1" step="0.1"/>
</div>
</div>
<div class="row">
<div class="field">
<label>Fixture Wattage (W)</label>
<input type="number" v-model.number="form.fixtureWatt" min="1" step="1"/>
</div>
<div class="field">
<label>Fixture Efficacy (µmol/J)</label>
<input type="number" v-model.number="form.efficacy" min="0.1" step="0.1"/>
</div>
</div>
<div class="row">
<div class="field">
<label>Natural light available (hours/day)</label>
<input type="number" v-model.number="form.naturalHours" min="0" step="0.1"/>
</div>
<div class="field">
<label>Electricity cost ($/kWh)</label>
<input type="number" v-model.number="form.kwhCost" min="0" step="0.001"/>
</div>
</div>
<div style="display:flex; gap:10px; align-items:center; margin-top:8px;">
<button class="btn" @click="computeAll">Calculate</button>
<button class="btn secondary" @click="resetForm">Reset</button>
<div class="note" style="margin-left:auto">Estimates only. Use as design starting point.</div>
</div>
</div>
<!-- presets & notes -->
<div style="height:14px"></div>
<div class="card">
<div style="display:flex; justify-content:space-between; align-items:center;">
<div>
<div style="font-weight:800">Presets</div>
<div class="note">Click to apply a crop preset</div>
</div>
<div class="muted">Recommended PPFD shown below</div>
</div>
<div style="margin-top:12px; display:grid; gap:10px;">
<div class="preset" v-for="p in presetList" :key="p.key" style="border:1px solid #f1f1f3">
<div class="left">
<h4>{{p.name}}</h4>
<p>{{p.description}}</p>
</div>
<div style="text-align:right">
<div style="font-weight:800; font-size:18px">{{p.ppfd}} µmol·m⁻²·s⁻¹</div>
<button class="btn" style="margin-top:8px" @click="applyPreset(p)">Use</button>
</div>
</div>
</div>
</div>
</div>
<!-- Right: report -->
<div>
<div class="card" id="report-card">
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:6px;">
<div style="font-weight:800; font-size:18px">Calculated Recommendation</div>
<div class="muted">Live results</div>
</div>
<div class="report">
<div style="display:flex; justify-content:space-between; align-items:center;">
<div>
<div style="font-weight:800; font-size:16px">{{cropName}} — {{stageLabel}}</div>
<div class="note">Target DLI: <strong>{{computed.targetDLI.toFixed(2)}}</strong> mol·m⁻²·day⁻¹</div>
</div>
<div style="text-align:right">
<div class="small">Area</div>
<div class="big">{{area}} m²</div>
</div>
</div>
<div style="height:10px"></div>
<div class="kpi">
<div class="item">
<div class="small">Target PPFD</div>
<div class="big">{{computed.targetPPFD.toFixed(0)}} µmol·m⁻²·s⁻¹</div>
<div class="muted small">based on crop & stage</div>
</div>
<div class="item">
<div class="small">Hours required (lighting)</div>
<div class="big">{{computed.hours.toFixed(2)}} h/day</div>
<div class="muted small">after natural light (if any)</div>
</div>
<div class="item">
<div class="small">Fixtures required</div>
<div class="big">{{computed.fixtures}}</div>
<div class="muted small">using your wattage & efficacy</div>
</div>
<div class="item">
<div class="small">Estimated daily energy</div>
<div class="big">{{computed.kwhPerDay.toFixed(3)}} kWh/day</div>
<div class="muted small">cost: ${{computed.costPerDay.toFixed(2)}}/day</div>
</div>
</div>
<div style="height:10px"></div>
<table>
<thead>
<tr><th>Metric</th><th>Value</th></tr>
</thead>
<tbody>
<tr><td>Total area</td><td>{{area}} m²</td></tr>
<tr><td>Target PPFD</td><td>{{computed.targetPPFD.toFixed(0)}} µmol·m⁻²·s⁻¹</td></tr>
<tr><td>Desired DLI</td><td>{{computed.targetDLI.toFixed(2)}} mol·m⁻²·day⁻¹</td></tr>
<tr><td>Hours lighting</td><td>{{computed.hours.toFixed(2)}} h/day</td></tr>
<tr><td>Fixture wattage</td><td>{{form.fixtureWatt}} W</td></tr>
<tr><td>Fixture efficacy</td><td>{{form.efficacy}} µmol/J</td></tr>
<tr><td>Fixtures required</td><td>{{computed.fixtures}}</td></tr>
<tr><td>Energy / day</td><td>{{computed.kwhPerDay.toFixed(3)}} kWh</td></tr>
<tr><td>Cost / day</td><td>${{computed.costPerDay.toFixed(2)}}</td></tr>
</tbody>
</table>
<div class="footer-actions">
<button class="btn" @click="downloadPDF">Download PDF Report</button>
<button class="btn secondary" @click="exportCSV">Export CSV</button>
<button class="btn" @click="copySummary">Copy Summary</button>
<div style="margin-left:auto" class="note">Report generated on client — private.</div>
</div>
</div>
<div class="note" style="margin-top:10px">
If you want server-side logging or advanced AI suggestions (cloud model), we can output this form as JSON to your PHP / Node endpoint. See commented placeholders in the code.
</div>
</div>
</div>
</div>
</div>
<!-- Main script -->
<script>
const { createApp, ref, reactive, computed } = Vue;
createApp({
setup(){
// Crop presets with recommended PPFD for stages (µmol/m2/s)
const crops = [
{ key:'tomato', name:'Tomato', basePPFD: 400 },
{ key:'lettuce', name:'Lettuce', basePPFD: 150 },
{ key:'herbs', name:'Herbs (basil)', basePPFD: 200 },
{ key:'leafy', name:'Leafy Greens', basePPFD: 180 },
{ key:'flower', name:'Flowering crops', basePPFD: 500 },
{ key:'cucumber', name:'Cucumber', basePPFD: 350 }
];
const stages = [
{ key:'veg', label:'Vegetative / Young' },
{ key:'flower', label:'Flowering / Fruit' },
{ key:'seedling', label:'Seedling' }
];
// presets for UI quick use
const presetList = [
{ key:'p1', name:'Fruits & Vegetables', description:'Tomato, cucumber typical full growth', ppfd:380 },
{ key:'p2', name:'Leafy Greens', description:'Lettuce, baby leaf', ppfd:160 },
{ key:'p3', name:'Herbs', description:'Basil, mint', ppfd:220 }
];
// reactive form
const form = reactive({
crop: 'tomato',
stage: 'flower',
desiredDLI: 20.0, // mol/m2/day (default)
width: 4.0,
length: 6.0,
fixtureWatt: 300,
efficacy: 2.6, // µmol/J
naturalHours: 3.0,
kwhCost: 0.15
});
// computed helpers
const area = computed(()=> {
const w = Number(form.width) || 0;
const l = Number(form.length) || 0;
return Math.max(0, (w*l));
});
// derive selected crop name
const cropName = computed(()=>{
const find = crops.find(c=>c.key===form.crop);
return find? find.name : form.crop;
});
const stageLabel = computed(()=>{
const s = stages.find(x=>x.key===form.stage);
return s? s.label : form.stage;
});
// core calculation function
function compute() {
// target PPFD baseline by crop
const found = crops.find(c=>c.key===form.crop);
let basePPFD = found ? found.basePPFD : 200;
// adjust baseline for stage
let stageFactor = 1.0;
if (form.stage === 'seedling') stageFactor = 0.4;
else if (form.stage === 'veg') stageFactor = 0.8;
else if (form.stage === 'flower') stageFactor = 1.0;
let targetPPFD = basePPFD * stageFactor;
// If user provided desired DLI, we can compute required hours:
// DLI (mol/m2/day) = PPFD (µmol/m2/s) * 3600 * hours / 1e6
// => hours = DLI / (PPFD * 0.0036)
let desiredDLI = Number(form.desiredDLI) || 0;
// If user left desiredDLI = 0 or blank, derive DLI from PPFD with 16 hours default:
if (!desiredDLI || desiredDLI <= 0) {
// common conversion: DLI ≈ PPFD * 0.0036 * 16
desiredDLI = targetPPFD * 0.0036 * 16;
}
// compute hours needed to reach desiredDLI using targetPPFD
let hoursTotal = desiredDLI / (targetPPFD * 0.0036); // hours/day of PPFD
// subtract natural light (but natural light may be of different spectrum/PPFD; we assume user input is equivalent)
let supplementalHours = Math.max(0, hoursTotal - (Number(form.naturalHours) || 0));
// compute fixture PPF from wattage & efficacy
// efficacy (µmol/J) * wattage (W) => µmol/s (PPF) for fixture
const ppfPerFixture = (Number(form.fixtureWatt) || 0) * (Number(form.efficacy) || 0);
// coverage area per fixture = PPF / targetPPFD (m2)
const areaPerFixture = ppfPerFixture > 0 ? (ppfPerFixture / targetPPFD) : 0;
// number of fixtures needed (ceiling)
const totalArea = area.value || 0;
let fixtures = 0;
if (areaPerFixture <= 0) fixtures = 0;
else fixtures = Math.max(0, Math.ceil(totalArea / areaPerFixture));
// energy and cost estimates
const totalWatts = fixtures * (Number(form.fixtureWatt) || 0);
const kwhPerDay = (totalWatts * supplementalHours) / 1000.0;
const costPerDay = kwhPerDay * (Number(form.kwhCost) || 0);
return {
targetPPFD,
targetDLI: desiredDLI,
hours: Math.max(0, supplementalHours),
fixtures,
ppfPerFixture,
areaPerFixture,
totalWatts,
kwhPerDay,
costPerDay
};
}
// reactive computed to update UI as form changes
const computedState = ref(compute());
function computeAll(){
computedState.value = compute();
// small UI flourish: scroll report into view
setTimeout(()=> {
const card = document.getElementById('report-card');
if(card) card.scrollIntoView({behavior:'smooth', block:'center'});
}, 80);
}
// auto compute initially and when fields change (debounced)
let debounceTimer = null;
function scheduleCompute(){
clearTimeout(debounceTimer);
debounceTimer = setTimeout(()=> {
computedState.value = compute();
}, 180);
}
// watch for changes
// minimal watcher using proxies: setInterval to check form changes is easier here:
let lastSnapshot = JSON.stringify(form);
setInterval(()=>{
const snap = JSON.stringify(form);
if (snap !== lastSnapshot){
lastSnapshot = snap;
scheduleCompute();
}
}, 300);
// exports
function exportCSV(){
const s = computedState.value;
const rows = [
['Field','Value'],
['Crop', cropName.value],
['Stage', stageLabel.value],
['Area (m2)', area.value],
['Target PPFD (µmol/m2/s)', s.targetPPFD.toFixed(1)],
['Desired DLI (mol/m2/day)', s.targetDLI.toFixed(2)],
['Lighting hours required (h/day)', s.hours.toFixed(2)],
['Fixture wattage (W)', form.fixtureWatt],
['Efficacy (µmol/J)', form.efficacy],
['PPF per fixture (µmol/s)', s.ppfPerFixture.toFixed(1)],
['Fixtures required', s.fixtures],
['Total wattage (W)', s.totalWatts],
['Energy per day (kWh)', s.kwhPerDay.toFixed(3)],
['Cost per day ($)', s.costPerDay.toFixed(2)],
['Generated at', new Date().toLocaleString()]
];
const csv = rows.map(r=> r.map(cell => `"${String(cell).replace(/"/g,'""')}"`).join(',')).join('\n');
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `growlight-report-${(new Date()).toISOString().slice(0,19).replace(/[:T]/g,'-')}.csv`;
document.body.appendChild(a);
a.click();
a.remove();
URL.revokeObjectURL(url);
}
async function downloadPDF(){
// create snapshot of the report element
const el = document.getElementById('report-card');
if(!el) return alert('Report not found');
// Expand to full width for better capture (temporary)
const originalWidth = el.style.width;
el.style.width = '900px';
// Use html2canvas
try {
const canvas = await html2canvas(el, { scale: 2, useCORS:true, backgroundColor: null });
const imgData = canvas.toDataURL('image/jpeg', 0.92);
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({
orientation: (canvas.width > canvas.height) ? 'landscape' : 'portrait',
unit: 'px',
format: [canvas.width, canvas.height]
});
pdf.addImage(imgData, 'JPEG', 0, 0, canvas.width, canvas.height, undefined, 'FAST');
const filename = `growlight-report-${(new Date()).toISOString().slice(0,19).replace(/[:T]/g,'-')}.pdf`;
pdf.save(filename);
} catch (err){
console.error(err);
alert('PDF generation failed. Try again.');
} finally {
el.style.width = originalWidth;
}
}
function copySummary(){
const s = computedState.value;
const text = [
`AI Grow Light Calculator — Summary`,
`Crop: ${cropName.value} (${stageLabel.value})`,
`Area: ${area.value} m²`,
`Target PPFD: ${s.targetPPFD.toFixed(0)} µmol·m⁻²·s⁻¹`,
`Desired DLI: ${s.targetDLI.toFixed(2)} mol·m⁻²·day⁻¹`,
`Lighting hours required: ${s.hours.toFixed(2)} h/day`,
`Fixtures required: ${s.fixtures}`,
`Estimated energy: ${s.kwhPerDay.toFixed(3)} kWh/day — Cost: $${s.costPerDay.toFixed(2)} / day`,
`Generated: ${new Date().toLocaleString()}`
].join('\\n');
navigator.clipboard?.writeText(text).then(()=> {
alert('Summary copied to clipboard');
}).catch(()=> {
prompt('Copy this text manually:', text);
});
}
function resetForm(){
form.crop = 'tomato';
form.stage = 'flower';
form.desiredDLI = 20.0;
form.width = 4;
form.length = 6;
form.fixtureWatt = 300;
form.efficacy = 2.6;
form.naturalHours = 3;
form.kwhCost = 0.15;
computeAll();
}
function applyPreset(p){
// set PPFD-based DLI: derive DLI assuming 16 hours at that PPFD
const newPPFD = p.ppfd;
// DLI = PPFD * 0.0036 * hours (assume 16h)
const derivedDLI = newPPFD * 0.0036 * 16;
form.desiredDLI = Number(derivedDLI.toFixed(1));
// set crop maybe
form.crop = (p.name.toLowerCase().includes('leaf')) ? 'lettuce' : 'tomato';
// set some defaults
form.fixtureWatt = 300;
form.efficacy = 2.6;
computeAll();
}
// small API placeholders: if later you want to POST results to your WordPress backend,
// replace the below commented block with a call to your PHP endpoint (AJAX / fetch).
//
// Example (uncomment & update endpoint in real deploy):
// async function postToServer(payload) {
// return fetch('/wp-json/myplugin/v1/log', {
// method:'POST',
// headers:{ 'Content-Type':'application/json' },
// body: JSON.stringify(payload)
// });
// }
// initial compute
computedState.value = compute();
return {
crops, stages,
presetList,
form,
area,
cropName,
stageLabel,
computed: computedState.value,
computedState,
computeAll,
resetForm,
exportCSV,
downloadPDF,
copySummary,
applyPreset
};
},
// keep computed binding reactive to UI - update computed when underlying reactive changes
updated(){
// sync computed pointer (so UI uses latest)
if (this.computedState) this.computed = this.computedState.value;
}
}).mount('#app');
</script>
</body>
</html>