Skip to content

Commit

Permalink
patch process_transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Dec 4, 2024
1 parent c9c131b commit 51d64f5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/analytics/enrich_account_funding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@ impl BalanceTracker {
pub fn process_transaction(&mut self, order: &ExchangeOrder) {
let date = order.created_at;
let (buyer_id, seller_id, amount) = match order.order_type.as_str() {
"BUY" => (order.user, order.accepter, order.amount * order.price),
"SELL" => (order.accepter, order.user, order.amount * order.price),
_ => return,
"Buy" => (order.user, order.accepter, order.amount * order.price),
"Sell" => (order.accepter, order.user, order.amount * order.price),
_ => {
println!("ERROR: not a valid Buy/Sell order, {:?}", &order);
return
},
};

self.update_balance_and_flows(seller_id, date, -amount, false);
Expand Down Expand Up @@ -170,6 +173,7 @@ pub fn replay_transactions(orders: &mut [ExchangeOrder]) -> BalanceTracker {
let mut tracker = BalanceTracker::new();
let sorted_orders = orders;
sorted_orders.sort_by_key(|order| order.created_at);
dbg!(&sorted_orders.len());
for order in sorted_orders {
tracker.process_transaction(order);
}
Expand All @@ -180,6 +184,7 @@ pub fn replay_transactions(orders: &mut [ExchangeOrder]) -> BalanceTracker {
pub async fn submit_ledger(balances: &BalanceTracker, pool: &Graph) -> Result<()> {
let query_literal = balances.generate_cypher_query();
println!("Cypher Query:\n{}", &query_literal);
dbg!(&balances.accounts.len());

for (id, acc) in balances.accounts.iter() {
let data = acc.to_cypher_map(*id);
Expand Down
13 changes: 12 additions & 1 deletion tests/test_enrich_exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::path::PathBuf;

use anyhow::Result;
use libra_forensic_db::{
analytics::enrich_rms,
analytics::{enrich_account_funding, enrich_rms},
extract_exchange_orders, load_exchange_orders,
neo4j_init::{get_neo4j_localhost_pool, maybe_create_indexes},
schema_exchange_orders::ExchangeOrder,
Expand Down Expand Up @@ -66,6 +66,17 @@ fn test_sell_order_shill() {
assert!(orders.len() == 25450);
}

#[test]
fn test_enrich_account_funding() {
let path = env!("CARGO_MANIFEST_DIR");
let buf = PathBuf::from(path).join("tests/fixtures/savedOlOrders2.json");
let mut orders = extract_exchange_orders::read_orders_from_file(buf).unwrap();

let balance = enrich_account_funding::replay_transactions(&mut orders);

dbg!(balance.accounts.len());
}

#[test]
fn test_enrich_buy_shill() {
let path = env!("CARGO_MANIFEST_DIR");
Expand Down

0 comments on commit 51d64f5

Please sign in to comment.