forked from gsn/predictor
updated downloader
This commit is contained in:
parent
ca95e06ab7
commit
8e9f117799
30 changed files with 1209 additions and 698 deletions
87
scripts/test_prediction.go
Normal file
87
scripts/test_prediction.go
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"git.intra.yksa.space/gsn/predictor/internal/pkg/grib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
|
||||
// Инициализируем GRIB сервис
|
||||
cfg := &grib.Config{
|
||||
Dir: "C:/tmp/grib",
|
||||
TTL: 48 * time.Hour,
|
||||
CacheTTL: 1 * time.Hour,
|
||||
Parallel: 8,
|
||||
}
|
||||
|
||||
svc, err := grib.New(cfg)
|
||||
if err != nil {
|
||||
fmt.Printf("Error creating service: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Обновляем данные (создаёт куб)
|
||||
fmt.Println("Updating GRIB data (building cube)...")
|
||||
start := time.Now()
|
||||
if err := svc.Update(ctx); err != nil {
|
||||
fmt.Printf("Update error: %v\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("Cube built in %v\n", time.Since(start))
|
||||
|
||||
// Тестируем извлечение ветра
|
||||
fmt.Println("\nTesting wind extraction...")
|
||||
lat, lon, alt := 52.2, 0.1, 10000.0
|
||||
ts := time.Date(2026, 2, 11, 12, 0, 0, 0, time.UTC)
|
||||
|
||||
wind, err := svc.Extract(ctx, lat, lon, alt, ts)
|
||||
if err != nil {
|
||||
fmt.Printf("Extract error: %v\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("Wind at (%.2f, %.2f, %.0fm) at %v:\n", lat, lon, alt, ts)
|
||||
fmt.Printf(" U (east): %.2f m/s\n", wind[0])
|
||||
fmt.Printf(" V (north): %.2f m/s\n", wind[1])
|
||||
|
||||
// Сравниваем с Tawhiri
|
||||
fmt.Println("\nComparing with Tawhiri API...")
|
||||
tawhiriURL := fmt.Sprintf(
|
||||
"https://api.v2.sondehub.org/tawhiri?launch_latitude=%.2f&launch_longitude=%.2f&launch_altitude=0&launch_datetime=%s&ascent_rate=5&burst_altitude=30000&descent_rate=5",
|
||||
lat, lon, ts.Format(time.RFC3339),
|
||||
)
|
||||
|
||||
resp, err := http.Get(tawhiriURL)
|
||||
if err != nil {
|
||||
fmt.Printf("Tawhiri request error: %v\n", err)
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
var tawhiriResp map[string]interface{}
|
||||
json.Unmarshal(body, &tawhiriResp)
|
||||
|
||||
// Выводим финальную точку приземления
|
||||
if prediction, ok := tawhiriResp["prediction"].([]interface{}); ok {
|
||||
for _, stage := range prediction {
|
||||
stageMap := stage.(map[string]interface{})
|
||||
if stageMap["stage"] == "descent" {
|
||||
trajectory := stageMap["trajectory"].([]interface{})
|
||||
if len(trajectory) > 0 {
|
||||
last := trajectory[len(trajectory)-1].(map[string]interface{})
|
||||
fmt.Printf("\nTawhiri landing point:\n")
|
||||
fmt.Printf(" Lat: %.4f\n", last["latitude"])
|
||||
fmt.Printf(" Lon: %.4f\n", last["longitude"])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue