Skip to content

Commit

Permalink
Starting feature extraction fmwrk
Browse files Browse the repository at this point in the history
  • Loading branch information
maxfierrog committed Dec 4, 2024
1 parent d83d8b5 commit dd6716a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/database/engine/sled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::database::Schema;
/* CONSTANTS */

/// A common name for all instances a [`sled`] database directory.
pub const DIRECTORY_NAME: &str = "sled_db";
pub const DIRECTORY_NAME: &str = "./sled_db/";

/* DEFINITIONS */

Expand Down
4 changes: 2 additions & 2 deletions src/database/record/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub const BUFFER_SIZE: usize = PAGE_OFFSET_BITS

/// Return the database table schema associated with a record instance.
pub fn schema() -> Result<Schema> {
let mut schema = SchemaBuilder::new()
let mut schema = SchemaBuilder::default()
.add(Attribute::new(
"attr_count",
Datatype::UINT,
Expand Down Expand Up @@ -127,7 +127,7 @@ impl TryFrom<Schema> for RecordBuffer {
impl TryFrom<RecordBuffer> for Schema {
type Error = anyhow::Error;
fn try_from(buf: RecordBuffer) -> Result<Schema> {
let mut schema = SchemaBuilder::new();
let mut schema = SchemaBuilder::default();
for index in 0..buf.get_attribute_count() {
let attribute = buf.get_attribute(index)?;
schema = schema.add(attribute)?;
Expand Down
2 changes: 1 addition & 1 deletion src/database/record/mur.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub fn schema(
UtilityType::Real => (Datatype::SPFP, FLOAT_UTILITTY_SIZE),
};

let mut schema = SchemaBuilder::new();
let mut schema = SchemaBuilder::default();
for i in 0..players {
let name = &format!("p{i}_utility");
schema = schema
Expand Down
9 changes: 5 additions & 4 deletions src/database/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::database::Schema;
/// Builder pattern intermediary for constructing a schema declaratively out of
/// provided attributes. This is here to help ensure schemas are not changed
/// accidentally after being instantiated.
#[derive(Default)]
pub struct SchemaBuilder {
attribute_count: usize,
attributes: Vec<Attribute>,
Expand All @@ -45,11 +46,11 @@ pub struct KeySequencer {
impl SchemaBuilder {
/// Returns a new instance of a `SchemaBuilder`, which can be used to
/// declaratively construct a new record `Schema`.
pub fn new() -> Self {
pub fn new(schema: Schema) -> Self {
SchemaBuilder {
attribute_count: 0,
attributes: Vec::new(),
size: 0,
attribute_count: schema.attribute_count(),
attributes: Vec::from(schema.attributes()),
size: schema.size(),
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
//! relationship, greater weight is placed on making things fit into this
//! module as a centralized point.
use std::path::PathBuf;
use std::{env, process};

use anyhow::{Context, Result};
use clap::Parser;

use crate::database::engine::sled::SledDatabase;
use crate::database::engine::sled::DIRECTORY_NAME;
use crate::database::Persistent;
use crate::game::model::GameModule;
use crate::game::{Forward, Information};
Expand All @@ -37,7 +39,7 @@ fn main() -> Result<()> {
let cli = Cli::parse();
let res = match cli.command {
Commands::Info(args) => info(args),
Commands::Solve(args) => solve(args),
Commands::Solve(args) => extract(args),
Commands::Query(args) => query(args),
};
if res.is_err() && cli.quiet {
Expand All @@ -52,9 +54,9 @@ fn query(args: QueryArgs) -> Result<()> {
todo!()
}

fn solve(args: SolveArgs) -> Result<()> {
fn extract(args: SolveArgs) -> Result<()> {
interface::standard::confirm_potential_overwrite(args.yes, args.mode);
let db_path = env::current_dir()?;
let db_path = env::current_dir()?.join(&PathBuf::from(DIRECTORY_NAME));
let mut db = SledDatabase::new(&db_path)?;
match args.target {
GameModule::ZeroBy => {
Expand Down

0 comments on commit dd6716a

Please sign in to comment.