Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Dec 12, 2024
1 parent b559be8 commit 90502b3
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 35 deletions.
32 changes: 13 additions & 19 deletions src/analytics/offline_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ pub async fn get_exchange_users_only_outflows(pool: &Graph) -> Result<Vec<MinFun
r#"
MATCH (e:SwapAccount)-[]-(u:UserLedger)
WHERE u.`total_inflows` = 0
AND u.total_outflows = u.total_funded // total outflows are only what was funded
AND u.current_balance = 0 // after account is plausibly depleted
WITH distinct(e.swap_id) AS user_id, max(u.`total_funded`) AS funded
RETURN user_id, funded
ORDER BY funded DESC
Expand Down Expand Up @@ -330,10 +332,11 @@ impl Matching {
pool: &Graph,
start: DateTime<Utc>,
end: DateTime<Utc>,
mut top_n: u64,
save_dir: Option<PathBuf>,
) -> Result<()> {
let mut top_n = 5;
while top_n < 25 {
let top_n_limit = 101;
while top_n < top_n_limit {
let _ = self
.breadth_search_by_dates(pool, top_n, start, end, &save_dir)
.await; // don't error
Expand All @@ -358,27 +361,13 @@ impl Matching {
// this may retry a number of users, but with more users discovered
// the search space gets smaller
for d in days_in_range(start, end) {
println!("day: {}", d);
info!("day: {}", d);
let next_list = get_exchange_users(pool, top_n, start, d).await?;

// // TODO: pick top of deposits
// let deposits = get_date_range_deposits(pool, 1000, start, d).await.unwrap_or_default();

// if next_list.len() > 5 {
// // dbg!("next_list");
// dbg!(&next_list[..5]);
// }
// dbg!(&next_list);

let deposits = get_date_range_deposits_alt(pool, 1000, start, d)
.await
.unwrap_or_default();

// if deposits.len() > 5 {
// dbg!("alt");
// dbg!(&deposits[..5]);
// }

for u in next_list {
let _r = self.search(&u, &deposits).await;

Expand Down Expand Up @@ -438,13 +427,18 @@ impl Matching {
.collect();

pending.maybe = candidates;
});

// after all users processed, try to find matches
user_list.iter().for_each(|user| {
let pending = self.pending.entry(user.user_id).or_default();

if pending.maybe.len() == 1 {
// we found a definite match, update it so the next loop doesn't include it
self.definite
.insert(user.user_id, *pending.maybe.first().unwrap());
}
})
});
}

pub fn eliminate_candidates(&mut self, user: &MinFunding, deposits: &[Deposit]) {
Expand All @@ -453,7 +447,7 @@ impl Matching {

let mut eval: Vec<AccountAddress> = vec![];
deposits.iter().for_each(|el| {
dbg!(&el);
// dbg!(&el);
if el.deposited >= user.funded &&
// must not already have been tagged impossible
!pending.impossible.contains(&el.account) &&
Expand Down
64 changes: 48 additions & 16 deletions tests/test_analytics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,6 @@ async fn test_offline_analytics() -> Result<()> {
let start_time = parse_date("2024-01-01");
let end_time = parse_date("2024-07-10");

let _r = offline_matching::get_date_range_deposits(&pool, 20, start_time, end_time).await?;
// dbg!(&r);

let _r = offline_matching::get_exchange_users(&pool, 20, start_time, end_time).await?;

Ok(())
Expand All @@ -268,6 +265,7 @@ async fn test_offline_analytics_matching() -> Result<()> {
&pool,
parse_date("2024-01-07"),
parse_date("2024-07-22"),
75,
Some(dir),
)
.await;
Expand All @@ -284,6 +282,52 @@ async fn test_easy_sellers() -> Result<()> {
let (uri, user, pass) = neo4j_init::get_credentials_from_env()?;
let pool = neo4j_init::get_neo4j_remote_pool(&uri, &user, &pass).await?;

let mut user_list = offline_matching::get_exchange_users_only_outflows(&pool).await?;
user_list
.sort_by(|a, b: &offline_matching::MinFunding| b.funded.partial_cmp(&a.funded).unwrap());
dbg!(&user_list.len());

let deposits = offline_matching::get_date_range_deposits_alt(
&pool,
1000,
parse_date("2024-01-07"),
parse_date("2024-07-22"),
)
.await
.unwrap_or_default();

let dir: PathBuf = PathBuf::from(env!("CARGO_MANIFEST_DIR"));

let mut m = Matching::read_cache_from_file(&dir).unwrap_or_default();

m.match_exact_sellers(&user_list, &deposits, 1.05);

dbg!(&m.definite.len());

dbg!(&m.definite);
m.write_cache_to_file(&dir)?;

// let _ = m
// .depth_search_by_top_n_accounts(
// &pool,
// parse_date("2024-01-07"),
// parse_date("2024-03-15"),
// 101,
// Some(dir),
// )
// .await;
// dbg!(&m.definite.len());

Ok(())
}

#[tokio::test]
async fn test_easy_sellers_combined() -> Result<()> {
libra_forensic_db::log_setup();

let (uri, user, pass) = neo4j_init::get_credentials_from_env()?;
let pool = neo4j_init::get_neo4j_remote_pool(&uri, &user, &pass).await?;

let mut user_list = offline_matching::get_exchange_users_only_outflows(&pool).await?;
user_list
.sort_by(|a, b: &offline_matching::MinFunding| b.funded.partial_cmp(&a.funded).unwrap());
Expand Down Expand Up @@ -311,23 +355,11 @@ async fn test_easy_sellers() -> Result<()> {
&pool,
parse_date("2024-01-07"),
parse_date("2024-07-22"),
10,
Some(dir),
)
.await;
dbg!(&m.definite.len());

// let _ = m
// .depth_search_by_top_n_accounts(
// &pool,
// parse_date("2024-01-07"),
// parse_date("2024-07-22"),
// Some(dir),
// )
// .await;

// dbg!(&m.definite);

Ok(())
}

//

0 comments on commit 90502b3

Please sign in to comment.