post request
This commit is contained in:
parent
dc29454df7
commit
c88469c1d4
2 changed files with 1161 additions and 3 deletions
|
|
@ -26,6 +26,36 @@
|
|||
let inputLat = '56.3576';
|
||||
let inputLng = '39.8666';
|
||||
|
||||
let showBurstCalculator = false;
|
||||
let payloadMass = 1500;
|
||||
let balloonMass = 1000;
|
||||
let desiredBurstAltitude = 33000;
|
||||
let desiredAscentRate = 2.33;
|
||||
|
||||
let burstAltitudeResult = 33000;
|
||||
let timeToBurst = 236;
|
||||
let initialVolume = 2.66;
|
||||
let ascentRateResult = 2.33;
|
||||
let liftForce = 1733;
|
||||
let volumeLiters = 2662;
|
||||
let volumeCubicFeet = 94.0;
|
||||
|
||||
const toggleBurstCalculator = () => {
|
||||
showBurstCalculator = !showBurstCalculator;
|
||||
};
|
||||
|
||||
const calculateBurst = () => {
|
||||
// In a real app, you would implement actual calculations here
|
||||
// These are just placeholder values matching your image
|
||||
burstAltitudeResult = desiredBurstAltitude;
|
||||
timeToBurst = 236;
|
||||
initialVolume = 2.66;
|
||||
ascentRateResult = desiredAscentRate;
|
||||
liftForce = 1733;
|
||||
volumeLiters = 2662;
|
||||
volumeCubicFeet = 94.0;
|
||||
};
|
||||
|
||||
const updateMapPosition = () => {
|
||||
const lat = parseFloat(inputLat);
|
||||
const lng = parseFloat(inputLng);
|
||||
|
|
@ -79,6 +109,59 @@
|
|||
`;
|
||||
});
|
||||
});
|
||||
|
||||
// Forecast request function
|
||||
const getForecast = async () => {
|
||||
// Create request object
|
||||
const request = {
|
||||
ascent_rate: parseFloat(ascentRate),
|
||||
burst_altitude: parseFloat(burstAltitude),
|
||||
dataset: new Date().toISOString(), // Current time as dataset timestamp
|
||||
descent_rate: parseFloat(descentRate),
|
||||
format: "json",
|
||||
launch_altitude: parseFloat(startHeight),
|
||||
launch_datetime: new Date(
|
||||
`${startDate.getFullYear()}-${startDate.getMonth() + 1}-${startDate.getDate()}T${startTime}:00Z`
|
||||
).toISOString(),
|
||||
launch_latitude: parseFloat(inputLat),
|
||||
launch_longitude: parseFloat(inputLng),
|
||||
profile: flightProfile === 'Normal' ? 'standard_profile' : 'custom_profile',
|
||||
version: 2
|
||||
};
|
||||
|
||||
console.log("Sending request:", request);
|
||||
|
||||
try {
|
||||
// Example POST request - replace with your actual API endpoint
|
||||
const response = await fetch('https://api.example.com/forecast', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(request)
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
console.log("Forecast response:", data);
|
||||
alert("Forecast request successful!");
|
||||
// Handle the response data as needed
|
||||
} catch (error) {
|
||||
console.error("Error sending forecast request:", error);
|
||||
alert("Error getting forecast: " + error.message);
|
||||
}
|
||||
};
|
||||
|
||||
// Helper function to format date as YYYY-MM-DD
|
||||
const formatDateForAPI = (date) => {
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
return `${year}-${month}-${day}`;
|
||||
};
|
||||
</script>
|
||||
|
||||
<div class="map-container">
|
||||
|
|
@ -109,7 +192,11 @@
|
|||
</div>
|
||||
|
||||
<div class="control-row">
|
||||
<button class="map-button">Specify on map</button>
|
||||
<button class="map-button" on:click={() => {
|
||||
inputLat = mouseLat;
|
||||
inputLng = mouseLng;
|
||||
updateMapPosition();
|
||||
}}>Specify on map (click location)</button>
|
||||
</div>
|
||||
|
||||
<div class="control-row">
|
||||
|
|
@ -141,12 +228,14 @@
|
|||
<span>Flight Profile:</span>
|
||||
<select bind:value={flightProfile}>
|
||||
<option>Normal</option>
|
||||
<option>Drift</option>
|
||||
<option>Reversible (on the rise)</option>
|
||||
<option>Custom</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="control-row buttons">
|
||||
<button>Open Burst Calculator</button>
|
||||
<button on:click={toggleBurstCalculator}>Open Burst Calculator</button>
|
||||
<button>Set Custom Flight Profile</button>
|
||||
<button>Show Last Altitude Graph</button>
|
||||
</div>
|
||||
|
|
@ -169,12 +258,77 @@
|
|||
</div>
|
||||
|
||||
<div class="control-row">
|
||||
<button class="primary-button">Get Forecast</button>
|
||||
<button class="primary-button" on:click={getForecast}>Get Forecast</button>
|
||||
<button>Save Point</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Burst Calculator Modal -->
|
||||
{#if showBurstCalculator}
|
||||
<div class="modal-overlay" on:click|self={toggleBurstCalculator}>
|
||||
<div class="modal-content">
|
||||
<h2>Balloon Burst Calculation</h2>
|
||||
|
||||
<div class="calculator-grid">
|
||||
<div class="input-group">
|
||||
<label>Payload Mass (g)</label>
|
||||
<input type="number" bind:value={payloadMass}>
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<label>Balloon Mass (g)</label>
|
||||
<input type="number" bind:value={balloonMass}>
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<label>Desired Burst Altitude (m)</label>
|
||||
<input type="number" bind:value={desiredBurstAltitude}>
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<label>Desired Ascent Rate (m/s)</label>
|
||||
<input type="number" bind:value={desiredAscentRate} step="0.01">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="results-section">
|
||||
<h3>Results</h3>
|
||||
<div class="result-row">
|
||||
<span>Burst Altitude:</span>
|
||||
<span>{burstAltitudeResult} m</span>
|
||||
</div>
|
||||
<div class="result-row">
|
||||
<span>Time to Burst:</span>
|
||||
<span>{timeToBurst} min</span>
|
||||
</div>
|
||||
<div class="result-row">
|
||||
<span>Initial Volume:</span>
|
||||
<span>{initialVolume} m³</span>
|
||||
</div>
|
||||
<div class="result-row">
|
||||
<span>Ascent Rate:</span>
|
||||
<span>{ascentRateResult} m/s</span>
|
||||
</div>
|
||||
<div class="result-row">
|
||||
<span>Lift Force at Launch:</span>
|
||||
<span>{liftForce} g</span>
|
||||
</div>
|
||||
<div class="result-row">
|
||||
<span>Volume:</span>
|
||||
<span>{volumeLiters} L ({volumeCubicFeet} ft³)</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-actions">
|
||||
<button class="secondary-button">Additional Settings</button>
|
||||
<button class="primary-button" on:click={calculateBurst}>Use Results</button>
|
||||
<button on:click={toggleBurstCalculator}>Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.map-container {
|
||||
position: relative;
|
||||
|
|
@ -307,4 +461,88 @@
|
|||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.modal-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 2000;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background-color: white;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
width: 500px;
|
||||
max-width: 90%;
|
||||
max-height: 90vh;
|
||||
overflow-y: auto;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.calculator-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 15px;
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
.input-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.input-group label {
|
||||
margin-bottom: 5px;
|
||||
font-weight: bold;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.input-group input {
|
||||
padding: 8px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.results-section {
|
||||
background-color: #f5f5f5;
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
margin: 15px 0;
|
||||
}
|
||||
|
||||
.results-section h3 {
|
||||
margin-top: 0;
|
||||
border-bottom: 1px solid #ddd;
|
||||
padding-bottom: 5px;
|
||||
}
|
||||
|
||||
.result-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin: 8px 0;
|
||||
}
|
||||
|
||||
.result-row span:first-child {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.modal-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.secondary-button {
|
||||
background: #f0f0f0;
|
||||
border: 1px solid #ccc;
|
||||
}
|
||||
|
||||
</style>
|
||||
Loading…
Add table
Add a link
Reference in a new issue