• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

geo-engine / geoengine / 12466344113

23 Dec 2024 11:27AM UTC coverage: 90.695% (+0.2%) from 90.509%
12466344113

push

github

web-flow
Merge pull request #1002 from geo-engine/update-deps-2024-12-06

update deps 2024-12-06

38 of 75 new or added lines in 14 files covered. (50.67%)

24 existing lines in 15 files now uncovered.

133182 of 146846 relevant lines covered (90.7%)

54823.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

4.65
/services/src/machine_learning/mod.rs
1
use std::borrow::Cow;
2

3
use async_trait::async_trait;
4
use error::{error::CouldNotFindMlModelFileMachineLearningError, MachineLearningError};
5
use name::MlModelName;
6
use postgres_types::{FromSql, ToSql};
7
use serde::{Deserialize, Serialize};
8
use snafu::ResultExt;
9
use tokio_postgres::{
10
    tls::{MakeTlsConnect, TlsConnect},
11
    Socket,
12
};
13
use utoipa::{IntoParams, ToSchema};
14
use validator::{Validate, ValidationError};
15

16
use crate::{
17
    api::model::datatypes::RasterDataType,
18
    contexts::PostgresDb,
19
    datasets::upload::{UploadId, UploadRootPath},
20
    identifier,
21
    util::{
22
        config::{get_config_element, MachineLearning},
23
        path_with_base_path,
24
    },
25
};
26

27
pub mod error;
28
pub mod name;
29

30
identifier!(MlModelId);
31

32
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, ToSchema, FromSql, ToSql)]
2✔
33
#[serde(rename_all = "camelCase")]
34
pub struct MlModel {
35
    pub name: MlModelName,
36
    pub display_name: String,
37
    pub description: String,
38
    pub upload: UploadId,
39
    pub metadata: MlModelMetadata,
40
}
41

42
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, ToSchema, FromSql, ToSql)]
12✔
43
#[serde(rename_all = "camelCase")]
44
pub struct MlModelMetadata {
45
    pub file_name: String,
46
    pub input_type: RasterDataType,
47
    pub num_input_bands: u32, // number of features per sample (bands per pixel)
48
    pub output_type: RasterDataType, // TODO: support multiple outputs, e.g. one band for the probability of prediction
49
                                     // TODO: output measurement, e.g. classification or regression, label names for classification. This would have to be provided by the model creator along the model file as it cannot be extracted from the model file(?)
50
}
51

52
impl MlModel {
53
    pub fn metadata_for_operator(
×
54
        &self,
×
55
    ) -> Result<geoengine_datatypes::machine_learning::MlModelMetadata, MachineLearningError> {
×
56
        Ok(geoengine_datatypes::machine_learning::MlModelMetadata {
×
57
            file_path: path_with_base_path(
×
58
                &self
×
59
                    .upload
×
60
                    .root_path()
×
61
                    .context(CouldNotFindMlModelFileMachineLearningError)?,
×
62
                self.metadata.file_name.as_ref(),
×
63
            )
×
64
            .context(CouldNotFindMlModelFileMachineLearningError)?,
×
65
            input_type: self.metadata.input_type.into(),
×
66
            num_input_bands: self.metadata.num_input_bands,
×
67
            output_type: self.metadata.output_type.into(),
×
68
        })
69
    }
×
70
}
71

UNCOV
72
#[derive(Debug, Deserialize, Serialize, Clone, IntoParams, Validate)]
×
73
#[into_params(parameter_in = Query)]
74
pub struct MlModelListOptions {
75
    #[param(example = 0)]
76
    pub offset: u32,
77
    #[param(example = 2)]
78
    #[validate(custom(function = "validate_list_limit"))]
79
    pub limit: u32,
80
}
81

82
fn validate_list_limit(value: u32) -> Result<(), ValidationError> {
×
83
    let limit = get_config_element::<MachineLearning>()
×
84
        .expect("should exist because it is defined in the default config")
×
85
        .list_limit;
×
86
    if value <= limit {
×
87
        return Ok(());
×
88
    }
×
89

×
90
    let mut err = ValidationError::new("limit (too large)");
×
91
    err.add_param::<u32>(Cow::Borrowed("max limit"), &limit);
×
92
    Err(err)
×
93
}
×
94

95
#[async_trait]
96
pub trait MlModelDb {
97
    async fn list_models(
98
        &self,
99
        options: &MlModelListOptions,
100
    ) -> Result<Vec<MlModel>, MachineLearningError>;
101

102
    async fn load_model(&self, name: &MlModelName) -> Result<MlModel, MachineLearningError>;
103

104
    async fn load_model_metadata(
105
        &self,
106
        name: &MlModelName,
107
    ) -> Result<MlModelMetadata, MachineLearningError>;
108

109
    async fn add_model(&self, model: MlModel) -> Result<(), MachineLearningError>;
110
}
111

112
#[async_trait]
113
impl<Tls> MlModelDb for PostgresDb<Tls>
114
where
115
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static + std::fmt::Debug,
116
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
117
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
118
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send,
119
{
120
    async fn list_models(
121
        &self,
122
        _options: &MlModelListOptions,
123
    ) -> Result<Vec<MlModel>, MachineLearningError> {
×
124
        unimplemented!()
×
125
    }
×
126

127
    async fn load_model(&self, _name: &MlModelName) -> Result<MlModel, MachineLearningError> {
×
128
        unimplemented!()
×
129
    }
×
130

131
    async fn load_model_metadata(
132
        &self,
133
        _name: &MlModelName,
134
    ) -> Result<MlModelMetadata, MachineLearningError> {
×
135
        unimplemented!()
×
136
    }
×
137

138
    async fn add_model(&self, _model: MlModel) -> Result<(), MachineLearningError> {
×
139
        unimplemented!()
×
140
    }
×
141
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc