changes
This commit is contained in:
10
src/main.rs
10
src/main.rs
@@ -483,12 +483,12 @@ impl Market {
|
||||
for (ap,pq) in &self.orders {
|
||||
println!("Orders selling {} to buy {}:",self.number_to_name(ap.0),self.number_to_name(ap.1));
|
||||
let mut sorted=pq.v.clone();
|
||||
sorted.sort_by(|a,b| { (a.sell_qty/a.buy_qty).cmp(&(b.sell_qty/b.buy_qty)) });
|
||||
sorted.sort_by(|a,b| { (b.sell_qty/b.buy_qty).cmp(&(a.sell_qty/a.buy_qty)) });
|
||||
for off in sorted.iter() {
|
||||
let rt=self.royalties.get_mut(&ap.1).unwrap();
|
||||
let indexr=rt.order_finder.get(&off.order_id).unwrap();
|
||||
let royalty_amt=rt.get_royalty(*indexr);
|
||||
println!(" {} @ {} ({}) OrderID: {} Royalties Accumulated: {} Royalties Offered {} Commissions Offered: {}",
|
||||
println!(" {} @ {} ({}) OrderID: {} Accumulated: {} Royalties {} Commissions: {}",
|
||||
off.sell_remain, // off.buy_qty*off.sell_remain/off.sell_qty,
|
||||
(off.buy_qty/off.sell_qty).fmt_recip(),
|
||||
self.traders[off.owner as usize].name,
|
||||
@@ -532,6 +532,7 @@ impl Market {
|
||||
let reader=io::BufReader::new(f.unwrap());
|
||||
for line in reader.lines() {
|
||||
if let Ok(line) = line {
|
||||
let line=clean_replay(&line);
|
||||
let cmd=Command::deserialize(line);
|
||||
if let Command::NOP(comment)=cmd { println!("{}",comment); }
|
||||
else {
|
||||
@@ -957,6 +958,11 @@ enum Command {
|
||||
|
||||
fn clean(s: &str) -> String { s.to_string() }
|
||||
|
||||
fn clean_replay(input: &str) -> String {
|
||||
let before_semicolon = input.split(';').next().unwrap_or(""); // Split on semicolon; take first chunk (before semicolon), or "" if none
|
||||
before_semicolon.trim_end().to_string() // Trim trailing whitespace, then convert to owned String
|
||||
}
|
||||
|
||||
impl Command {
|
||||
fn serialize(&self) -> String {
|
||||
match self {
|
||||
|
||||
Reference in New Issue
Block a user