Sahil Tailor commited on
Commit
6dbfea6
Β·
1 Parent(s): 115a8e9

Final Commit - HP

Browse files
Files changed (3) hide show
  1. factory.py +2 -0
  2. frontend/src/App.jsx +55 -9
  3. inference.py +2 -2
factory.py CHANGED
@@ -135,6 +135,8 @@ class ManufacturingFactoryEnv:
135
 
136
  if self.step_count >= self.max_steps:
137
  self.done = True
 
 
138
 
139
  reward_obj = ManufacturingReward(value=step_reward, components=components)
140
  obs = self._build_observation(reward=step_reward)
 
135
 
136
  if self.step_count >= self.max_steps:
137
  self.done = True
138
+ elif not self.pending_orders:
139
+ self.done = True # all orders delivered β€” stop early
140
 
141
  reward_obj = ManufacturingReward(value=step_reward, components=components)
142
  obs = self._build_observation(reward=step_reward)
frontend/src/App.jsx CHANGED
@@ -152,21 +152,67 @@ function RewardSparkline({ history }) {
152
 
153
  // ─── Globe view ───────────────────────────────────────────────────────────────
154
  function GlobeView({ snapshot, globeSize }) {
155
- const globeRef = useRef(null);
156
  const pathStoreRef = useRef([]);
 
157
  const [pathData, setPathData] = useState([]);
158
 
159
- // Lock camera controls
160
  useEffect(() => {
161
  if (!globeRef.current) return;
162
  const controls = globeRef.current.controls();
163
- controls.autoRotate = false;
164
- controls.enablePan = false;
165
- controls.enableZoom = false;
166
- controls.minDistance = 210;
167
- controls.maxDistance = 310;
168
- controls.minPolarAngle = Math.PI * 0.4;
169
- controls.maxPolarAngle = Math.PI * 0.6;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  }, []);
171
 
172
  // Build/update path data from snapshot
 
152
 
153
  // ─── Globe view ───────────────────────────────────────────────────────────────
154
  function GlobeView({ snapshot, globeSize }) {
155
+ const globeRef = useRef(null);
156
  const pathStoreRef = useRef([]);
157
+ const snapAnimRef = useRef(null);
158
  const [pathData, setPathData] = useState([]);
159
 
160
+ // Lock camera controls + snap back to equator after user interaction
161
  useEffect(() => {
162
  if (!globeRef.current) return;
163
  const controls = globeRef.current.controls();
164
+ controls.autoRotate = true;
165
+ controls.autoRotateSpeed = 0.6;
166
+ controls.enablePan = false;
167
+ controls.enableZoom = false;
168
+ controls.minDistance = 210;
169
+ controls.maxDistance = 310;
170
+ controls.minPolarAngle = Math.PI * 0.25;
171
+ controls.maxPolarAngle = Math.PI * 0.75;
172
+
173
+ const snapToEquator = () => {
174
+ if (snapAnimRef.current) cancelAnimationFrame(snapAnimRef.current);
175
+ const camera = globeRef.current.camera();
176
+
177
+ const tick = () => {
178
+ const tx = controls.target.x, ty = controls.target.y, tz = controls.target.z;
179
+ const dx = camera.position.x - tx;
180
+ const dy = camera.position.y - ty;
181
+ const dz = camera.position.z - tz;
182
+ const r = Math.sqrt(dx * dx + dy * dy + dz * dz);
183
+ const phi = Math.atan2(Math.sqrt(dx * dx + dz * dz), dy); // current polar angle
184
+ const diff = Math.PI / 2 - phi; // distance from equator
185
+
186
+ if (Math.abs(diff) < 0.002) { controls.update(); return; }
187
+
188
+ const newPhi = phi + diff * 0.08; // ease toward equator
189
+ const theta = Math.atan2(dz, dx);
190
+ const sinPhi = Math.sin(newPhi);
191
+ const cosPhi = Math.cos(newPhi);
192
+ camera.position.set(
193
+ tx + r * sinPhi * Math.cos(theta),
194
+ ty + r * cosPhi,
195
+ tz + r * sinPhi * Math.sin(theta),
196
+ );
197
+ controls.update();
198
+ snapAnimRef.current = requestAnimationFrame(tick);
199
+ };
200
+
201
+ snapAnimRef.current = requestAnimationFrame(tick);
202
+ };
203
+
204
+ // Cancel snap if user grabs the globe again
205
+ const cancelSnap = () => {
206
+ if (snapAnimRef.current) cancelAnimationFrame(snapAnimRef.current);
207
+ };
208
+
209
+ controls.addEventListener('end', snapToEquator);
210
+ controls.addEventListener('start', cancelSnap);
211
+ return () => {
212
+ controls.removeEventListener('end', snapToEquator);
213
+ controls.removeEventListener('start', cancelSnap);
214
+ if (snapAnimRef.current) cancelAnimationFrame(snapAnimRef.current);
215
+ };
216
  }, []);
217
 
218
  // Build/update path data from snapshot
inference.py CHANGED
@@ -100,8 +100,8 @@ def read_int_env(name: str, default: int) -> int:
100
 
101
 
102
  # ── configuration ──────────────────────────────────────────────────────────────
103
- API_BASE_URL = os.environ["API_BASE_URL"] or os.getenv("API_BASE_URL","https://router.huggingface.co/v1")
104
- API_KEY = os.environ["API_KEY"] or os.getenv("API_KEY")
105
  MODEL_NAME = os.getenv("MODEL_NAME","meta-llama/Llama-3.1-8B-Instruct:novita")
106
  BASELINE_POLICY = os.getenv("BASELINE_POLICY", "openai").lower()
107
  TEMPERATURE = read_float_env("TEMPERATURE", 0.0)
 
100
 
101
 
102
  # ── configuration ──────────────────────────────────────────────────────────────
103
+ API_BASE_URL = os.getenv("API_BASE_URL","https://router.huggingface.co/v1")
104
+ API_KEY = os.getenv("API_KEY")
105
  MODEL_NAME = os.getenv("MODEL_NAME","meta-llama/Llama-3.1-8B-Instruct:novita")
106
  BASELINE_POLICY = os.getenv("BASELINE_POLICY", "openai").lower()
107
  TEMPERATURE = read_float_env("TEMPERATURE", 0.0)