Skip to content

Bachelorarbeit 2024 #990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions datatypes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ postgres-types = { version = "0.2", features = [
] }
proj = "0.22" # needs to stay fixed to use fixed proj version
rayon = "1.8"
schemars = "0.8.16"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_with = "3.6"
Expand Down
44 changes: 43 additions & 1 deletion datatypes/src/dataset.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::identifier;
use std::borrow::Cow;

use crate::{identifier, util::helpers::json_schema_help_link};
use schemars::{gen::SchemaGenerator, schema::Schema, JsonSchema};
use serde::{de::Visitor, Deserialize, Serialize};

identifier!(DataProviderId);
Expand Down Expand Up @@ -86,6 +89,45 @@ pub struct NamedData {
pub name: String,
}

impl JsonSchema for NamedData {
fn schema_name() -> String {
"NamedData".to_owned()
}

fn schema_id() -> Cow<'static, str> {
Cow::Borrowed(concat!(module_path!(), "::NamedData"))
}

fn is_referenceable() -> bool {
false
}

fn json_schema(_gen: &mut SchemaGenerator) -> Schema {
use schemars::schema::*;
Schema::Object(SchemaObject {
metadata: Some(Box::new(Metadata {
description: Some("The user-facing identifier for loadable data.
It can be resolved into a [`DataId`].

It is a triple of namespace, provider and name.
The namespace and provider are optional and default to the system namespace and provider.

# Examples

* `dataset` -> `NamedData { namespace: None, provider: None, name: \"dataset\" }`
* `namespace:dataset` -> `NamedData { namespace: Some(\"namespace\"), provider: None, name: \"dataset\" }`
* `namespace:provider:dataset` -> `NamedData { namespace: Some(\"namespace\"), provider: Some(\"provider\"), name: \"dataset\" }`".to_owned()),
..Default::default()
})),
instance_type: Some(SingleOrVec::Single(Box::new(InstanceType::String))),
extensions: schemars::Map::from([
json_schema_help_link("https://docs.geoengine.io/geoengine/datasets.html")
]),
..Default::default()
})
}
}

impl NamedData {
/// Canonicalize a name that reflects the system namespace and provider.
fn canonicalize<S: Into<String> + PartialEq<&'static str>>(
Expand Down
13 changes: 12 additions & 1 deletion datatypes/src/primitives/coordinate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use float_cmp::ApproxEq;

use postgres_types::{FromSql, ToSql};
use proj::Coord;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use std::{
Expand All @@ -15,7 +16,17 @@ use std::{
};

#[derive(
Clone, Copy, Debug, Deserialize, PartialEq, PartialOrd, Serialize, Default, ToSql, FromSql,
Clone,
Copy,
Debug,
Deserialize,
PartialEq,
PartialOrd,
Serialize,
Default,
ToSql,
FromSql,
JsonSchema,
)]
#[repr(C)]
pub struct Coordinate2D {
Expand Down
15 changes: 10 additions & 5 deletions datatypes/src/primitives/measurement.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use postgres_types::{FromSql, ToSql};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, HashMap};
use std::fmt;
use std::str::FromStr;

#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase", tag = "type")]
pub enum Measurement {
Unitless,
Continuous(ContinuousMeasurement),
#[schemars(with = "SerializableClassificationMeasurement")]
Classification(ClassificationMeasurement),
}

Expand All @@ -31,7 +33,7 @@ impl Default for Measurement {
}
}

#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, FromSql, ToSql)]
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, FromSql, ToSql, JsonSchema)]
pub struct ContinuousMeasurement {
pub measurement: String,
pub unit: Option<String>,
Expand All @@ -47,9 +49,12 @@ pub struct ClassificationMeasurement {
pub classes: HashMap<u8, String>,
}

/// A type that is solely for serde's serializability.
/// You cannot serialize floats as JSON map keys.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
// A type that is solely for serde's serializability.
// You cannot serialize floats as JSON map keys.
//
// Note: Do not use a doc comment here, because otherwise
// internal details would be shown in workflow editor.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct SerializableClassificationMeasurement {
pub measurement: String,
// use a BTreeMap to preserve the order of the keys
Expand Down
3 changes: 2 additions & 1 deletion datatypes/src/primitives/spatial_resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ use std::{convert::TryFrom, ops::Add, ops::Div, ops::Mul, ops::Sub};
use crate::primitives::error;
use crate::util::Result;
use postgres_types::{FromSql, ToSql};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use snafu::ensure;

/// The spatial resolution in SRS units
#[derive(Copy, Clone, Debug, PartialEq, Deserialize, Serialize, ToSql, FromSql)]
#[derive(Copy, Clone, Debug, PartialEq, Deserialize, Serialize, ToSql, FromSql, JsonSchema)]
pub struct SpatialResolution {
pub x: f64,
pub y: f64,
Expand Down
55 changes: 55 additions & 0 deletions datatypes/src/primitives/time_instance.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
use super::datetime::DateTimeError;
use super::{DateTime, Duration};
use crate::primitives::error;
use crate::util::helpers::json_schema_help_link;
use crate::util::Result;
use postgres_types::{FromSql, ToSql};
use schemars::gen::SchemaGenerator;
use schemars::schema::Schema;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use snafu::ensure;
use std::borrow::Cow;
use std::ops::AddAssign;
use std::{
convert::TryFrom,
Expand All @@ -18,6 +23,56 @@ use std::{
#[postgres(transparent)]
pub struct TimeInstance(i64);

impl JsonSchema for TimeInstance {
fn schema_name() -> String {
"TimeInstance".to_owned()
}

fn schema_id() -> Cow<'static, str> {
Cow::Borrowed(concat!(module_path!(), "::TimeInstance"))
}

fn is_referenceable() -> bool {
true
}

fn json_schema(_gen: &mut SchemaGenerator) -> Schema {
use schemars::schema::*;
Schema::Object(SchemaObject {
subschemas: Some(Box::new(SubschemaValidation {
one_of: Some(vec![
Schema::Object(SchemaObject {
metadata: Some(Box::new(Metadata {
title: Some("Unix Timestamp".to_owned()),
description: Some("Unix timestamp in milliseconds".to_owned()),
..Default::default()
})),
instance_type: Some(SingleOrVec::Single(Box::new(InstanceType::Integer))),
..Default::default()
}),
Schema::Object(SchemaObject {
metadata: Some(Box::new(Metadata {
title: Some("Datetime String".to_owned()),
description: Some(
"Date and time as defined in RFC 3339, section 5.6".to_owned(),
),
..Default::default()
})),
instance_type: Some(SingleOrVec::Single(Box::new(InstanceType::String))),
format: Some("date-time".to_owned()),
extensions: schemars::Map::from([json_schema_help_link(
"http://tools.ietf.org/html/rfc3339",
)]),
..Default::default()
}),
]),
..Default::default()
})),
..Default::default()
})
}
}

impl TimeInstance {
pub fn from_millis(millis: i64) -> Result<Self> {
ensure!(
Expand Down
3 changes: 2 additions & 1 deletion datatypes/src/primitives/time_interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ use arrow::datatypes::{DataType, Field};
use arrow::error::ArrowError;

use postgres_types::{FromSql, ToSql};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use snafu::ensure;
use std::fmt::{Debug, Display};
use std::sync::Arc;
use std::{cmp::Ordering, convert::TryInto};

/// Stores time intervals in ms in close-open semantic [start, end)
#[derive(Clone, Copy, Deserialize, Serialize, PartialEq, Eq, ToSql, FromSql)]
#[derive(Clone, Copy, Deserialize, Serialize, PartialEq, Eq, ToSql, FromSql, JsonSchema)]
#[repr(C)]
pub struct TimeInterval {
start: TimeInstance,
Expand Down
5 changes: 3 additions & 2 deletions datatypes/src/primitives/time_step.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::ops::{Mul, Sub};
use std::{cmp::max, convert::TryInto, ops::Add};

use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use postgres_types::{FromSql, ToSql};
Expand All @@ -13,7 +14,7 @@ use crate::util::Result;
use super::{DateTime, Duration, TimeInterval};

/// A time granularity.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, ToSql, FromSql)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, ToSql, FromSql, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub enum TimeGranularity {
Millis,
Expand All @@ -26,7 +27,7 @@ pub enum TimeGranularity {
}

/// A step in time.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, ToSql, FromSql)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, ToSql, FromSql, JsonSchema)]
pub struct TimeStep {
pub granularity: TimeGranularity,
pub step: u32, // TODO: ensure on deserialization it is > 0
Expand Down
12 changes: 8 additions & 4 deletions datatypes/src/raster/band_names.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use snafu::ensure;

Expand All @@ -7,12 +8,15 @@ use crate::error::{
};
use crate::util::Result;

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase", tag = "type", content = "values")]
pub enum RenameBands {
Default, // append " (n)" to the band name for the `n`-th conflict,
Suffix(Vec<String>), // A suffix for every input, to be appended to the original band names
Rename(Vec<String>), // A new name for each band, to be used instead of the original band names
/// Append " (n)" to the band name for the `n`-th conflict
Default,
/// A suffix for every input, to be appended to the original band names
Suffix(Vec<String>),
/// A new name for each band, to be used instead of the original band names
Rename(Vec<String>),
}

impl RenameBands {
Expand Down
Loading