decharge-scout 4.5.0 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/oracle.js +20 -1
- package/src/weather-data.js +28 -0
package/package.json
CHANGED
package/src/oracle.js
CHANGED
|
@@ -123,7 +123,26 @@ export async function submitToOracle(wallet, submissionData) {
|
|
|
123
123
|
* Anonymize submission data
|
|
124
124
|
*/
|
|
125
125
|
function anonymizeData(data) {
|
|
126
|
-
//
|
|
126
|
+
// Check if this is a fleet submission or regular submission
|
|
127
|
+
if (data.type === 'fleet') {
|
|
128
|
+
// Fleet submission - different structure
|
|
129
|
+
return {
|
|
130
|
+
agent_id: hashString(data.agent_name),
|
|
131
|
+
location_region: generalizeLocation(data.location),
|
|
132
|
+
timestamp: data.timestamp,
|
|
133
|
+
type: 'fleet',
|
|
134
|
+
fleet_size: data.fleet_size,
|
|
135
|
+
summary: {
|
|
136
|
+
...data.summary,
|
|
137
|
+
// Round values to reduce precision
|
|
138
|
+
total_cost_usd: parseFloat(data.summary.total_cost_usd.toFixed(2)),
|
|
139
|
+
savings_percent: Math.round(data.summary.savings_percent)
|
|
140
|
+
},
|
|
141
|
+
stops_count: data.stops?.length || 0
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Regular scout submission
|
|
127
146
|
const anonymized = {
|
|
128
147
|
agent_id: hashString(data.agent_name), // Hash the agent name
|
|
129
148
|
location_region: generalizeLocation(data.location), // Generalize location
|
package/src/weather-data.js
CHANGED
|
@@ -136,11 +136,39 @@ const KNOWN_CITIES = {
|
|
|
136
136
|
'dallas': { latitude: 32.776, longitude: -96.797, name: 'Dallas', country: 'United States', timezone: 'America/Chicago' },
|
|
137
137
|
};
|
|
138
138
|
|
|
139
|
+
/**
|
|
140
|
+
* Get weather data for coordinates directly
|
|
141
|
+
* Used by fleet module for intermediate route points
|
|
142
|
+
*/
|
|
143
|
+
export async function getWeatherForCoordinates(latitude, longitude) {
|
|
144
|
+
// Get weather forecast directly without geocoding
|
|
145
|
+
const forecast = await fetchWeatherForecast(latitude, longitude, 'auto');
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
location: {
|
|
149
|
+
latitude,
|
|
150
|
+
longitude,
|
|
151
|
+
name: `${latitude.toFixed(2)},${longitude.toFixed(2)}`,
|
|
152
|
+
country: 'ROUTE',
|
|
153
|
+
timezone: 'auto'
|
|
154
|
+
},
|
|
155
|
+
forecast
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
139
159
|
/**
|
|
140
160
|
* Get weather data for a location
|
|
141
161
|
* Throws error if geocoding fails - caller should handle user interaction
|
|
142
162
|
*/
|
|
143
163
|
export async function getWeatherForLocation(location) {
|
|
164
|
+
// Check if location is already in coordinate format (lat,lon)
|
|
165
|
+
const coordMatch = location.match(/^(-?\d+\.?\d*),\s*(-?\d+\.?\d*)$/);
|
|
166
|
+
if (coordMatch) {
|
|
167
|
+
const lat = parseFloat(coordMatch[1]);
|
|
168
|
+
const lon = parseFloat(coordMatch[2]);
|
|
169
|
+
return getWeatherForCoordinates(lat, lon);
|
|
170
|
+
}
|
|
171
|
+
|
|
144
172
|
// Try geocoding - throw error if fails
|
|
145
173
|
const coords = await getCoordinatesFromLocation(location);
|
|
146
174
|
console.log(`📍 Location: ${coords.name}, ${coords.country} (${coords.latitude}, ${coords.longitude})`);
|