Add vscode workspace settings, add graph data structure to rust
This commit is contained in:
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"editor.formatOnSave": true
|
||||
}
|
||||
142
src/graph.rs
Normal file
142
src/graph.rs
Normal file
@@ -0,0 +1,142 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum NodeConfiguration {
|
||||
FileNode,
|
||||
MoveMoneyNode(MoveMoneyNode),
|
||||
MergeNode(MergeNode),
|
||||
DeriveNode(DeriveNode),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct NodeInfo {
|
||||
pub name: String,
|
||||
pub output_files: Vec<String>,
|
||||
pub configuration: NodeConfiguration,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum MoveMoneyAmountType {
|
||||
Percent,
|
||||
Amount,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct MoveMoneyRule {
|
||||
pub from_account: String,
|
||||
pub from_cc: String,
|
||||
pub to_account: String,
|
||||
pub to_cc: String,
|
||||
pub value: f64,
|
||||
pub amount_type: MoveMoneyAmountType,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct MoveMoneyNode {
|
||||
pub departments_path: String,
|
||||
pub accounts_path: String,
|
||||
pub gl_path: String,
|
||||
pub rules: Vec<MoveMoneyRule>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum JoinType {
|
||||
Left,
|
||||
Inner,
|
||||
Right,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct MergeJoin {
|
||||
pub join_type: JoinType,
|
||||
pub left_column_name: String,
|
||||
pub right_column_name: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct MergeNode {
|
||||
pub input_files: Vec<String>,
|
||||
pub joins: Vec<MergeJoin>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum DeriveColumnType {
|
||||
Column(String),
|
||||
Constant(String),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct MapOperation {
|
||||
pub mapped_value: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum DatePart {
|
||||
Year,
|
||||
Month,
|
||||
Week,
|
||||
Day,
|
||||
Hour,
|
||||
Minute,
|
||||
Second,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum SplitType {
|
||||
DateTime(String, DatePart),
|
||||
Numeric(String, isize),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum MatchComparisonType {
|
||||
Equal,
|
||||
GreaterThan,
|
||||
LessThan,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum DeriveOperation {
|
||||
Concat(Vec<DeriveColumnType>),
|
||||
Add(Vec<DeriveColumnType>),
|
||||
Multiply(Vec<DeriveColumnType>),
|
||||
Subtract(DeriveColumnType, DeriveColumnType),
|
||||
Divide(DeriveColumnType, DeriveColumnType),
|
||||
Map(String, Vec<MapOperation>),
|
||||
Split(String, SplitType),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct DeriveFilter {
|
||||
pub column_name: String,
|
||||
pub comparator: MatchComparisonType,
|
||||
pub match_value: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct DeriveRule {
|
||||
pub operations: Vec<DeriveOperation>,
|
||||
pub filters: Vec<DeriveFilter>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct DeriveNode {
|
||||
pub rules: Vec<DeriveRule>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Node {
|
||||
pub id: i64,
|
||||
pub info: NodeInfo,
|
||||
pub dependent_node_ids: Vec<i64>,
|
||||
}
|
||||
|
||||
impl Node {
|
||||
pub fn has_dependent_nodes(&self) -> bool {
|
||||
!self.dependent_node_ids.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Graph {
|
||||
pub name: String,
|
||||
pub nodes: Vec<Node>,
|
||||
}
|
||||
@@ -22,6 +22,7 @@ pub mod filter;
|
||||
pub mod upload_to_db;
|
||||
|
||||
mod io;
|
||||
mod graph;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn move_money_from_text(
|
||||
|
||||
Reference in New Issue
Block a user