-
Notifications
You must be signed in to change notification settings - Fork 178
/
db_extensions.rs
41 lines (38 loc) · 1.45 KB
/
db_extensions.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use crate::history::history::Features;
use crate::network::Network;
use rusqlite::functions::FunctionFlags;
use rusqlite::Connection;
pub fn add_db_functions(db: &Connection) {
let network = Network::default();
db.create_scalar_function(
"nn_rank",
10,
FunctionFlags::SQLITE_UTF8 | FunctionFlags::SQLITE_DETERMINISTIC,
move |ctx| {
let age_factor = ctx.get::<f64>(0)?;
let length_factor = ctx.get::<f64>(1)?;
let exit_factor = ctx.get::<f64>(2)?;
let recent_failure_factor = ctx.get::<f64>(3)?;
let selected_dir_factor = ctx.get::<f64>(4)?;
let dir_factor = ctx.get::<f64>(5)?;
let overlap_factor = ctx.get::<f64>(6)?;
let immediate_overlap_factor = ctx.get::<f64>(7)?;
let selected_occurrences_factor = ctx.get::<f64>(8)?;
let occurrences_factor = ctx.get::<f64>(9)?;
let features = Features {
age_factor,
length_factor,
exit_factor,
recent_failure_factor,
selected_dir_factor,
dir_factor,
overlap_factor,
immediate_overlap_factor,
selected_occurrences_factor,
occurrences_factor,
};
Ok(network.output(&features))
},
)
.unwrap_or_else(|err| panic!("McFly error: Successful create_scalar_function ({err})"));
}