mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-24 15:02:59 +03:00
Consistently count hours for a time. There was some disagreement between
recorded analytics and code that later summed things up, making the relative throughput layer more confusing than it is already. #85
This commit is contained in:
parent
957d08e8b9
commit
bf8f51ae05
@ -869,7 +869,7 @@ fn mouseover_unzoomed_agent_circle(ctx: &mut EventCtx, app: &mut App) {
|
||||
}
|
||||
|
||||
fn is_daytime(app: &App) -> bool {
|
||||
let hours = app.primary.sim.time().get_parts().0 % 24;
|
||||
let hours = app.primary.sim.time().get_hours() % 24;
|
||||
hours >= 6 && hours < 18
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ impl Time {
|
||||
}
|
||||
|
||||
/// (hours, minutes, seconds, centiseconds)
|
||||
pub fn get_parts(self) -> (usize, usize, usize, usize) {
|
||||
fn get_parts(self) -> (usize, usize, usize, usize) {
|
||||
let mut remainder = self.0;
|
||||
let hours = (remainder / 3600.0).floor();
|
||||
remainder -= hours * 3600.0;
|
||||
@ -54,14 +54,9 @@ impl Time {
|
||||
centis as usize,
|
||||
)
|
||||
}
|
||||
/// Rounded up
|
||||
/// Rounded down. 6:59:00 is hour 6.
|
||||
pub fn get_hours(self) -> usize {
|
||||
let (hr, min, sec, cs) = self.get_parts();
|
||||
if min > 0 || sec > 0 || cs > 0 {
|
||||
hr + 1
|
||||
} else {
|
||||
hr
|
||||
}
|
||||
self.get_parts().0
|
||||
}
|
||||
|
||||
pub fn ampm_tostring(self) -> String {
|
||||
@ -210,4 +205,17 @@ mod tests {
|
||||
Time::parse("07:30:05").unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_hours() {
|
||||
assert_eq!((Time::START_OF_DAY + Duration::hours(6)).get_hours(), 6);
|
||||
assert_eq!(
|
||||
(Time::START_OF_DAY + Duration::hours(6) + Duration::seconds(1.0)).get_hours(),
|
||||
6
|
||||
);
|
||||
assert_eq!(
|
||||
(Time::START_OF_DAY + Duration::hours(6) + Duration::minutes(59)).get_hours(),
|
||||
6
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -535,8 +535,10 @@ impl<X: Ord + Clone> TimeSeriesCount<X> {
|
||||
}
|
||||
}
|
||||
|
||||
let hour = time.get_parts().0;
|
||||
*self.counts.entry((id, agent_type, hour)).or_insert(0) += count;
|
||||
*self
|
||||
.counts
|
||||
.entry((id, agent_type, time.get_hours()))
|
||||
.or_insert(0) += count;
|
||||
}
|
||||
|
||||
pub fn total_for(&self, id: X) -> usize {
|
||||
@ -561,8 +563,7 @@ impl<X: Ord + Clone> TimeSeriesCount<X> {
|
||||
pub fn total_for_by_time(&self, id: X, now: Time) -> usize {
|
||||
let mut cnt = 0;
|
||||
for agent_type in AgentType::all() {
|
||||
// TODO Off-by-one?
|
||||
for hour in 0..now.get_hours() {
|
||||
for hour in 0..=now.get_hours() {
|
||||
cnt += self
|
||||
.counts
|
||||
.get(&(id.clone(), agent_type, hour))
|
||||
|
@ -146,7 +146,7 @@ impl CapSimState {
|
||||
let zone = &mut self.zones[*idx];
|
||||
|
||||
if now - zone.hour_started >= Duration::hours(1) {
|
||||
zone.hour_started = Time::START_OF_DAY + Duration::hours(now.get_parts().0);
|
||||
zone.hour_started = Time::START_OF_DAY + Duration::hours(now.get_hours());
|
||||
zone.entered_in_last_hour.clear();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user