ed_journals/modules/logs/content/log_event_content/community_goal_event.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
//! Fired when accessing information about currently active community goals.
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
/// Fired when accessing information about currently active community goals.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct CommunityGoalEvent {
/// List of currently active community goals.
pub current_goals: Vec<CommunityGoalEventGoal>,
}
/// An entry for a currently active community goal.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct CommunityGoalEventGoal {
/// The id of the community goal.
#[serde(rename = "CGID")]
pub cgid: u64,
/// The name of the community goal.
pub title: String,
/// The name of the system the community goal is located in.
pub system_name: String,
/// The market or station name the community goal is located at.
pub market_name: String,
/// When the community goal is planned to end.
pub expiry: DateTime<Utc>,
/// Whether the community goal has been completed.
pub is_complete: bool,
/// The current total contributions made by all players for this community goal.
pub current_total: u64,
/// How much the current player has contributed to the community goal.
pub player_contribution: u64,
/// Thw number of players that have contributed to the community goal.
#[serde(rename = "NumContributors")]
pub number_of_contributors: u64,
/// The percentage of top players that are considered part of the top rank.
pub top_rank_size: u8,
/// Whether the current player is currently in the top rank.
pub player_in_top_rank: bool,
/// The highest rank the current player has reached.
pub tier_reached: Option<String>,
pub player_percentile_band: u8,
pub bonus: Option<u64>,
}
#[cfg(test)]
mod tests {
use crate::logs::content::log_event_content::community_goal_event::{
CommunityGoalEvent, CommunityGoalEventGoal,
};
#[test]
fn community_goal_event_is_parsed_correctly() {
let goal: CommunityGoalEvent = serde_json::from_str(
r#"
{
"timestamp": "2024-04-02T16:09:59Z",
"event": "CommunityGoal",
"CurrentGoals": [
{
"CGID": 804,
"Title": "Aid Achilles Aerospace in Researching Titan Travel Technology",
"SystemName": "Ethgreze",
"MarketName": "Bloch Station",
"Expiry": "2024-04-04T07:00:00Z",
"IsComplete": false,
"CurrentTotal": 15321,
"PlayerContribution": 0,
"NumContributors": 5410,
"TopTier": {
"Name": "Tier 2",
"Bonus": ""
},
"TopRankSize": 10,
"PlayerInTopRank": false,
"TierReached": "Tier 1",
"PlayerPercentileBand": 100,
"Bonus": 500000
}
]
}
"#,
)
.unwrap();
}
#[test]
fn community_goal_is_parsed_correctly() {
let goal: CommunityGoalEventGoal = serde_json::from_str(
r#"
{
"CGID": 804,
"Title": "Aid Achilles Aerospace in Researching Titan Travel Technology",
"SystemName": "Ethgreze",
"MarketName": "Bloch Station",
"Expiry": "2024-04-04T07:00:00Z",
"IsComplete": false,
"CurrentTotal": 15321,
"PlayerContribution": 0,
"NumContributors": 5410,
"TopTier": {
"Name": "Tier 2",
"Bonus": ""
},
"TopRankSize": 10,
"PlayerInTopRank": false,
"TierReached": "Tier 1",
"PlayerPercentileBand": 100,
"Bonus": 500000
}
"#,
)
.unwrap();
}
}