Rehost company recent-share cache band
This commit is contained in:
parent
6112141bb8
commit
40ae41a270
4 changed files with 50 additions and 5 deletions
|
|
@ -5187,6 +5187,8 @@ mod tests {
|
|||
mutable_support_scalar_raw_u32: 0x3f99999a,
|
||||
young_company_support_scalar_raw_u32: 0x42700000,
|
||||
support_progress_word: 12,
|
||||
recent_per_share_cache_absolute_counter: 0,
|
||||
recent_per_share_cached_value_bits: 0,
|
||||
recent_per_share_subscore_raw_u32: 0x420c0000,
|
||||
cached_share_price_raw_u32: 0x42200000,
|
||||
chairman_salary_baseline: 24,
|
||||
|
|
@ -5244,6 +5246,8 @@ mod tests {
|
|||
mutable_support_scalar_raw_u32: 0x3f4ccccd,
|
||||
young_company_support_scalar_raw_u32: 0x42580000,
|
||||
support_progress_word: 9,
|
||||
recent_per_share_cache_absolute_counter: 0,
|
||||
recent_per_share_cached_value_bits: 0,
|
||||
recent_per_share_subscore_raw_u32: 0x41f00000,
|
||||
cached_share_price_raw_u32: 0x41f80000,
|
||||
chairman_salary_baseline: 20,
|
||||
|
|
@ -6631,6 +6635,8 @@ mod tests {
|
|||
mutable_support_scalar_raw_u32: 0x3f19999a,
|
||||
young_company_support_scalar_raw_u32: 0x42580000,
|
||||
support_progress_word: 8,
|
||||
recent_per_share_cache_absolute_counter: 0,
|
||||
recent_per_share_cached_value_bits: 0,
|
||||
recent_per_share_subscore_raw_u32: 0x42000000,
|
||||
cached_share_price_raw_u32: 0x42180000,
|
||||
chairman_salary_baseline: 21,
|
||||
|
|
|
|||
|
|
@ -65,6 +65,10 @@ pub struct RuntimeCompanyMarketState {
|
|||
#[serde(default)]
|
||||
pub support_progress_word: u32,
|
||||
#[serde(default)]
|
||||
pub recent_per_share_cache_absolute_counter: u32,
|
||||
#[serde(default)]
|
||||
pub recent_per_share_cached_value_bits: u64,
|
||||
#[serde(default)]
|
||||
pub recent_per_share_subscore_raw_u32: u32,
|
||||
#[serde(default)]
|
||||
pub cached_share_price_raw_u32: u32,
|
||||
|
|
@ -2060,6 +2064,15 @@ pub fn runtime_company_recent_per_share_subscore(
|
|||
company_id: u32,
|
||||
) -> Option<f64> {
|
||||
let market_state = state.service_state.company_market_state.get(&company_id)?;
|
||||
if runtime_world_absolute_counter(state)
|
||||
.is_some_and(|counter| counter == market_state.recent_per_share_cache_absolute_counter)
|
||||
{
|
||||
if let Some(cached_value) =
|
||||
runtime_decode_saved_f64_bits(market_state.recent_per_share_cached_value_bits)
|
||||
{
|
||||
return Some(cached_value);
|
||||
}
|
||||
}
|
||||
runtime_decode_saved_f32_value_f64(market_state.recent_per_share_subscore_raw_u32)
|
||||
}
|
||||
|
||||
|
|
@ -3374,7 +3387,10 @@ mod tests {
|
|||
},
|
||||
world_flags: BTreeMap::new(),
|
||||
save_profile: RuntimeSaveProfileState::default(),
|
||||
world_restore: RuntimeWorldRestoreState::default(),
|
||||
world_restore: RuntimeWorldRestoreState {
|
||||
absolute_counter_raw_u32: Some(5),
|
||||
..RuntimeWorldRestoreState::default()
|
||||
},
|
||||
metadata: BTreeMap::new(),
|
||||
companies: vec![
|
||||
RuntimeCompany {
|
||||
|
|
@ -3549,7 +3565,10 @@ mod tests {
|
|||
},
|
||||
world_flags: BTreeMap::new(),
|
||||
save_profile: RuntimeSaveProfileState::default(),
|
||||
world_restore: RuntimeWorldRestoreState::default(),
|
||||
world_restore: RuntimeWorldRestoreState {
|
||||
absolute_counter_raw_u32: Some(5),
|
||||
..RuntimeWorldRestoreState::default()
|
||||
},
|
||||
metadata: BTreeMap::new(),
|
||||
companies: vec![RuntimeCompany {
|
||||
company_id: 1,
|
||||
|
|
@ -3627,7 +3646,10 @@ mod tests {
|
|||
},
|
||||
world_flags: BTreeMap::new(),
|
||||
save_profile: RuntimeSaveProfileState::default(),
|
||||
world_restore: RuntimeWorldRestoreState::default(),
|
||||
world_restore: RuntimeWorldRestoreState {
|
||||
absolute_counter_raw_u32: Some(5),
|
||||
..RuntimeWorldRestoreState::default()
|
||||
},
|
||||
metadata: BTreeMap::new(),
|
||||
companies: vec![RuntimeCompany {
|
||||
company_id: 1,
|
||||
|
|
@ -5051,7 +5073,10 @@ mod tests {
|
|||
},
|
||||
world_flags: BTreeMap::new(),
|
||||
save_profile: RuntimeSaveProfileState::default(),
|
||||
world_restore: RuntimeWorldRestoreState::default(),
|
||||
world_restore: RuntimeWorldRestoreState {
|
||||
absolute_counter_raw_u32: Some(5),
|
||||
..RuntimeWorldRestoreState::default()
|
||||
},
|
||||
metadata: BTreeMap::new(),
|
||||
companies: vec![RuntimeCompany {
|
||||
company_id: 7,
|
||||
|
|
@ -5103,6 +5128,8 @@ mod tests {
|
|||
company_market_state: BTreeMap::from([(
|
||||
7,
|
||||
RuntimeCompanyMarketState {
|
||||
recent_per_share_cache_absolute_counter: 5,
|
||||
recent_per_share_cached_value_bits: 14.5f64.to_bits(),
|
||||
recent_per_share_subscore_raw_u32: 12.0f32.to_bits(),
|
||||
cached_share_price_raw_u32: 37.0f32.to_bits(),
|
||||
..RuntimeCompanyMarketState::default()
|
||||
|
|
@ -5114,7 +5141,7 @@ mod tests {
|
|||
|
||||
assert_eq!(
|
||||
runtime_company_recent_per_share_subscore(&state, 7),
|
||||
Some(12.0)
|
||||
Some(14.5)
|
||||
);
|
||||
assert_eq!(runtime_company_investor_confidence(&state, 7), Some(37));
|
||||
assert_eq!(
|
||||
|
|
|
|||
|
|
@ -3725,6 +3725,14 @@ fn parse_save_company_roster_probe(
|
|||
bytes,
|
||||
record_offset + SAVE_COMPANY_RECORD_SUPPORT_PROGRESS_OFFSET,
|
||||
)?;
|
||||
let recent_per_share_cache_absolute_counter = read_u32_at(
|
||||
bytes,
|
||||
record_offset + SAVE_COMPANY_RECORD_STAT_BAND_ROOT_0CFB_OFFSET,
|
||||
)?;
|
||||
let recent_per_share_cached_value_bits = read_u64_at(
|
||||
bytes,
|
||||
record_offset + SAVE_COMPANY_RECORD_STAT_BAND_ROOT_0CFB_OFFSET + 4,
|
||||
)?;
|
||||
let recent_per_share_subscore_raw_u32 = read_u32_at(
|
||||
bytes,
|
||||
record_offset + SAVE_COMPANY_RECORD_RECENT_PER_SHARE_SUBSCORE_OFFSET,
|
||||
|
|
@ -3873,6 +3881,8 @@ fn parse_save_company_roster_probe(
|
|||
mutable_support_scalar_raw_u32,
|
||||
young_company_support_scalar_raw_u32,
|
||||
support_progress_word,
|
||||
recent_per_share_cache_absolute_counter,
|
||||
recent_per_share_cached_value_bits,
|
||||
recent_per_share_subscore_raw_u32,
|
||||
cached_share_price_raw_u32,
|
||||
chairman_salary_baseline,
|
||||
|
|
|
|||
|
|
@ -2045,6 +2045,8 @@ mod tests {
|
|||
mutable_support_scalar_raw_u32: 0x3f800000,
|
||||
young_company_support_scalar_raw_u32: 0x42340000,
|
||||
support_progress_word: 12,
|
||||
recent_per_share_cache_absolute_counter: 0,
|
||||
recent_per_share_cached_value_bits: 0,
|
||||
recent_per_share_subscore_raw_u32: 0x420c0000,
|
||||
cached_share_price_raw_u32: 0x42200000,
|
||||
chairman_salary_baseline: 24,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue