forked from withchristopher/goatfarmer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
281 lines (238 loc) · 5.95 KB
/
index.html
File metadata and controls
281 lines (238 loc) · 5.95 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>GOATFarmer</title>
<style>
body {
margin: 0;
height: 100vh;
background: #111;
display: flex;
align-items: center;
justify-content: center;
font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}
.phone {
width: 360px;
height: 640px;
background: #000;
border-radius: 26px;
overflow: hidden;
box-shadow: 0 0 35px rgba(0,0,0,.9);
display: flex;
flex-direction: column;
border: 4px solid #222;
}
.header {
background: #075E54;
color: #fff;
padding: 12px;
font-weight: 600;
font-size: 16px;
display: flex;
justify-content: space-between;
align-items: center;
}
.header button {
background: none;
border: none;
color: #fff;
font-size: 14px;
cursor: pointer;
}
.screen {
flex: 1;
display: none;
flex-direction: column;
height: 100%;
}
.screen.active {
display: flex;
}
.chat {
flex: 1;
background: #ece5dd;
padding: 10px;
overflow-y: auto;
display: flex;
flex-direction: column;
gap: 8px;
}
.msg {
max-width: 78%;
padding: 8px 10px;
border-radius: 8px;
font-size: 14px;
line-height: 1.35;
white-space: pre-line;
}
.worker {
background: #fff;
align-self: flex-end;
border-top-right-radius: 0;
}
.farmer {
background: #dcf8c6;
align-self: flex-start;
border-top-left-radius: 0;
}
.footer {
background: #f0f0f0;
padding: 8px;
border-top: 1px solid #ccc;
}
.question {
background: #fff;
border: 1px solid #ccc;
border-radius: 6px;
padding: 8px;
margin-bottom: 6px;
font-size: 13px;
cursor: pointer;
}
.question:active {
background: #ddd;
}
.about {
flex: 1;
background: #fff;
padding: 14px;
font-size: 14px;
line-height: 1.4;
overflow-y: auto;
}
</style>
</head>
<body>
<div class="phone">
<div class="header">
<span>🐐 GOATFarmer</span>
<button onclick="showAbout()">About</button>
</div>
<!-- CHAT SCREEN -->
<div class="screen active" id="chatScreen">
<div class="chat" id="chat"></div>
<div class="footer" id="questions"></div>
</div>
<!-- ABOUT SCREEN -->
<div class="screen" id="aboutScreen">
<div class="about">
<h2>About GOATFarmer</h2>
<p>
<strong>GOATFarmer</strong> helps people who keep goats make better
day-to-day decisions.
</p>
<p>
It works like advice from an experienced farmer.
You can use it when goats are sick, not eating,
giving less milk, or when you want to make cheese.
</p>
<h3>Why this helps</h3>
<ul>
<li>Works on simple phones</li>
<li>Does not need internet all the time</li>
<li>Gives clear steps, not long explanations</li>
<li>Helps you act early before problems get worse</li>
</ul>
<h3>How to use it</h3>
<ul>
<li>Tap a question below</li>
<li>Read the causes</li>
<li>Follow the steps</li>
</ul>
<p>
The advice is based on real goat farming knowledge
about feeding, clean water, shelter, health,
milk and cheese making.
</p>
<button onclick="showChat()">⬅ Back to Chat</button>
</div>
</div>
</div>
<script>
function showAbout() {
document.getElementById("chatScreen").classList.remove("active");
document.getElementById("aboutScreen").classList.add("active");
}
function showChat() {
document.getElementById("aboutScreen").classList.remove("active");
document.getElementById("chatScreen").classList.add("active");
}
const chat = document.getElementById("chat");
const questionsDiv = document.getElementById("questions");
function addMessage(text, sender) {
const msg = document.createElement("div");
msg.className = "msg " + sender;
msg.innerText = text;
chat.appendChild(msg);
chat.scrollTop = chat.scrollHeight;
}
fetch("data.json")
.then(res => {
if (!res.ok) throw new Error("data.json not found");
return res.json();
})
.then(graph => {
let user = JSON.parse(localStorage.getItem("goatfarmer_user"))
|| graph.userMemory;
function saveUser() {
localStorage.setItem("goatfarmer_user", JSON.stringify(user));
}
function symptomResponse(key) {
const s = graph.symptoms[key];
let r = "Possible causes:\n";
s.possibleCauses.forEach(c => r += "• " + c.replace(/_/g," ") + "\n");
r += "\nWhat to do:\n";
s.advice.forEach(a => r += "• " + a + "\n");
return r;
}
function cheeseResponse(goal) {
const milk = user.average_milk_liters;
let matches = [];
Object.entries(graph.cheeses).forEach(([name, c]) => {
if (milk >= c.milk_min && milk <= c.milk_max) {
if (goal === "fast" && c.time_hours <= 24) matches.push(name);
if (goal === "storage" && c.storage_days >= 10) matches.push(name);
}
});
if (!matches.length) {
return "With the milk you have today, fresh cheese is the best choice.";
}
let r = "Based on your milk today (" + milk + " liters):\n";
matches.forEach(m => r += "• " + m.replace(/_/g," ") + "\n");
return r;
}
graph.questions.slice(0, 4).forEach(q => {
const btn = document.createElement("div");
btn.className = "question";
btn.innerText = q.ask;
btn.onclick = () => {
addMessage(q.ask, "worker");
setTimeout(() => {
const reply =
q.type === "symptom"
? symptomResponse(q.key)
: cheeseResponse(q.goal);
addMessage(reply, "farmer");
saveUser();
}, 300);
};
questionsDiv.appendChild(btn);
});
addMessage(
"I can help with goats, milk, and simple cheese making.\nTap a question below.",
"farmer"
);
})
.catch(err => {
console.error(err);
addMessage(
"Error loading farm knowledge.\nMake sure data.json is in the same folder.",
"farmer"
);
});
</script>
</body>
</html>