Add vscode workspace settings, add graph data structure to rust

This commit is contained in:
Michael Pivato
2024-05-10 17:20:51 +09:30
parent e31499a7e4
commit bd24b0b9be
3 changed files with 146 additions and 0 deletions

142
src/graph.rs Normal file
View 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>,
}