cleanup
This commit is contained in:
parent
7a4691e3e4
commit
d07f3485fc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -11,7 +11,6 @@ use std::time::SystemTime;
|
||||||
use actix_web::{App, HttpServer};
|
use actix_web::{App, HttpServer};
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use crate::grib2::{LookupTable2D};
|
use crate::grib2::{LookupTable2D};
|
||||||
use crate::sources::noaa::mrms_cref;
|
|
||||||
|
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
|
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
|
||||||
|
@ -39,7 +38,7 @@ async fn main() -> std::io::Result<()> {
|
||||||
});
|
});
|
||||||
HttpServer::new(move || {
|
HttpServer::new(move || {
|
||||||
App::new()
|
App::new()
|
||||||
.service(mrms_cref)
|
.service(sources::noaa::noaa_mrms_merged_composite_reflectivity_qc)
|
||||||
.app_data(data.clone())
|
.app_data(data.clone())
|
||||||
})
|
})
|
||||||
.bind(("::", 8080))?
|
.bind(("::", 8080))?
|
||||||
|
|
|
@ -166,3 +166,27 @@ pub fn render(xtile: f64, ytile: f64, z: i32, tilesize: usize, pal: Palette, map
|
||||||
|
|
||||||
buf
|
buf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! grib2_handler {
|
||||||
|
(mount $f:ident, at: $path:expr, from: $from:expr, needs_gzip: $needs_gzip:expr, valid_for: $valid_for:expr, lut_with: $lut_key:expr, palette: $pal:expr) => {
|
||||||
|
#[::actix_web::get($path)]
|
||||||
|
async fn $f(path: ::actix_web::web::Path<(i32,u32,u32)>, data: ::actix_web::web::Data<crate::AppState>) -> ::actix_web::HttpResponse {
|
||||||
|
crate::sources::grib2::reload_if_required(
|
||||||
|
$from,
|
||||||
|
$needs_gzip,
|
||||||
|
$valid_for,
|
||||||
|
$lut_key,
|
||||||
|
&data.lut_cache_timestamps,
|
||||||
|
&data.lut_cache
|
||||||
|
).await;
|
||||||
|
if let Some(map) = data.lut_cache.read().await.get(&$lut_key) {
|
||||||
|
::actix_web::HttpResponse::Ok()
|
||||||
|
.insert_header(::actix_web::http::header::ContentType(::mime::IMAGE_PNG))
|
||||||
|
.body(crate::sources::grib2::render(path.1 as f64, path.2 as f64, path.0, 256, $pal, map))
|
||||||
|
} else {
|
||||||
|
::actix_web::HttpResponse::new(::actix_web::http::StatusCode::NOT_FOUND)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,2 +1,3 @@
|
||||||
pub mod noaa;
|
pub mod noaa;
|
||||||
mod grib2;
|
#[macro_use]
|
||||||
|
pub mod grib2;
|
|
@ -1,40 +1,12 @@
|
||||||
use std::collections::BTreeMap;
|
use wxbox_pal::create_test_palette;
|
||||||
use std::f64::consts::PI;
|
use crate::{grib2_handler, LutKey};
|
||||||
use std::io::{BufWriter, Cursor, Read};
|
|
||||||
use std::time::{SystemTime};
|
|
||||||
use actix_web::{get, HttpResponse, web};
|
|
||||||
use actix_web::http::{header, StatusCode};
|
|
||||||
use actix_web::web::Data;
|
|
||||||
use eccodes::{CodesHandle, FallibleStreamingIterator, ProductKind};
|
|
||||||
use flate2::read::GzDecoder;
|
|
||||||
use ndarray::{Zip};
|
|
||||||
use ordered_float::{FloatCore, OrderedFloat};
|
|
||||||
use png::{BitDepth, ColorType, Encoder};
|
|
||||||
use wxbox_pal::{Color, ColorPalette, create_test_palette};
|
|
||||||
use crate::{AppState, LutKey};
|
|
||||||
use crate::grib2::{closest_key, LookupTable2D};
|
|
||||||
use crate::pixmap::Pixmap;
|
|
||||||
use crate::sources::grib2::{eccodes_remap, load, needs_reload, reload_if_required, render};
|
|
||||||
|
|
||||||
#[get("/noaa_mrms_merged_composite_reflectivity_qc/{z}/{x}/{y}.png")]
|
grib2_handler! {
|
||||||
async fn mrms_cref(path: web::Path<(i32, u32, u32)>, data: Data<AppState>) -> HttpResponse {
|
mount noaa_mrms_merged_composite_reflectivity_qc,
|
||||||
let pal = create_test_palette();
|
at: "/noaa_mrms_merged_composite_reflectivity_qc/{z}/{x}/{y}.png",
|
||||||
|
from: "https://mrms.ncep.noaa.gov/data/2D/MergedReflectivityQCComposite/MRMS_MergedReflectivityQCComposite.latest.grib2.gz",
|
||||||
reload_if_required(
|
needs_gzip: true,
|
||||||
"https://mrms.ncep.noaa.gov/data/2D/MergedReflectivityQCComposite/MRMS_MergedReflectivityQCComposite.latest.grib2.gz",
|
valid_for: 120,
|
||||||
true,
|
lut_with: LutKey::NoaaMrmsMergedCompositeReflectivityQc,
|
||||||
120,
|
palette: create_test_palette()
|
||||||
LutKey::NoaaMrmsMergedCompositeReflectivityQc,
|
|
||||||
&data.lut_cache_timestamps,
|
|
||||||
&data.lut_cache
|
|
||||||
).await;
|
|
||||||
|
|
||||||
if let Some(map) = data.lut_cache.read().await.get(&LutKey::NoaaMrmsMergedCompositeReflectivityQc) {
|
|
||||||
HttpResponse::Ok()
|
|
||||||
.insert_header(header::ContentType(mime::IMAGE_PNG))
|
|
||||||
.body(render(path.1 as f64, path.2 as f64, path.0, 256, pal, map))
|
|
||||||
} else {
|
|
||||||
HttpResponse::new(StatusCode::NOT_FOUND)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
"host": "vite dev --host",
|
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||||
|
|
Loading…
Reference in New Issue