Skip to content

Commit

Permalink
Update the actual start and end for DPS tally
Browse files Browse the repository at this point in the history
  • Loading branch information
Barugon committed Dec 2, 2023
1 parent 692a9c8 commit 7b49203
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/dps_dlg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,15 @@ impl DPSDlg {
self.log_path = path_buf.to_owned();
self.avatar = avatar.to_owned();
self.state.set_disabled(true);
self.tally = None;
self.visible = true;
}
}

pub fn show(&mut self, ctx: &Context) {
while let Ok(Some(tally)) = self.channel.rx.try_next() {
// Update the date/time span and store the tally.
self.span = tally.span.clone();
self.tally = Some(tally);
self.state.set_busy(false);
}
Expand Down Expand Up @@ -197,12 +200,11 @@ impl DPSDlg {
fn close(&mut self) {
if self.visible {
if let Some(mut cancel) = self.channel.cancel.take() {
// Cancel the search if it's still outstanding.
// Cancel the tally request if it's still outstanding.
cancel.cancel();
}

self.state.set_disabled(false);
self.tally = None;
self.visible = false;
}
}
Expand Down
26 changes: 23 additions & 3 deletions src/log_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,24 @@ pub struct Span {
pub end: NaiveDateTime,
}

#[derive(Default)]
pub struct DPSTally {
pub span: Span,
pub avatar: u64,
pub pet: u64,
pub secs: u64,
}

impl DPSTally {
fn new(span: Span) -> Self {
Self {
span,
avatar: 0,
pet: 0,
secs: 0,
}
}
}

pub async fn tally_dps(log_path: PathBuf, avatar: String, span: Span, cancel: Cancel) -> DPSTally {
let filenames = {
let begin = span.begin.date();
Expand All @@ -385,7 +396,7 @@ pub async fn tally_dps(log_path: PathBuf, avatar: String, span: Span, cancel: Ca
filenames
};

let mut dps_tally = DPSTally::default();
let mut dps_tally = DPSTally::new(span.clone());
if cancel.is_canceled() {
return dps_tally;
}
Expand All @@ -411,7 +422,7 @@ pub async fn tally_dps(log_path: PathBuf, avatar: String, span: Span, cancel: Ca

for filename in filenames {
if cancel.is_canceled() {
return DPSTally::default();
return DPSTally::new(span.clone());
}

// Read the log file.
Expand All @@ -423,6 +434,7 @@ pub async fn tally_dps(log_path: PathBuf, avatar: String, span: Span, cancel: Ca
let Some(ts) = get_log_timestamp(line, file_date) else {
continue;
};

if !range.contains(&ts) {
continue;
}
Expand Down Expand Up @@ -455,7 +467,15 @@ pub async fn tally_dps(log_path: PathBuf, avatar: String, span: Span, cancel: Ca
}

if let Some(start_ts) = dmg_start_ts {
if let Some(begin) = NaiveDateTime::from_timestamp_opt(start_ts, 0) {
// Update the begin data/time.
dps_tally.span.begin = begin;
}
if let Some(end_ts) = dmg_end_ts {
if let Some(end) = NaiveDateTime::from_timestamp_opt(end_ts, 0) {
// Update the end data/time.
dps_tally.span.end = end;
}
dps_tally.secs = 0.max(end_ts - start_ts) as u64;
}
}
Expand Down

0 comments on commit 7b49203

Please sign in to comment.