Skip to content

Commit

Permalink
Use only orgs in data file when processing stats (#589)
Browse files Browse the repository at this point in the history
Signed-off-by: Sergio Castaño Arteaga <tegioz@icloud.com>
  • Loading branch information
tegioz authored Apr 29, 2024
1 parent a3f5046 commit 5565ca0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion crates/core/src/datasets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Datasets {
base: Base::new(i.landscape_data, i.settings, i.guide, i.qr_code),
embed: Embed::new(i.landscape_data),
full: Full::new(i.landscape_data, i.crunchbase_data, i.github_data),
stats: Stats::new(i.landscape_data, i.settings, i.crunchbase_data),
stats: Stats::new(i.landscape_data, i.settings),
}
}
}
Expand Down
29 changes: 18 additions & 11 deletions crates/core/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::{
data::{CategoryName, SubCategoryName},
settings::{LandscapeSettings, TagName},
};
use crate::data::{CrunchbaseData, LandscapeData};
use crate::data::LandscapeData;
use chrono::{Datelike, Utc};
use itertools::Itertools;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -44,14 +44,10 @@ impl Stats {
/// Create a new Stats instance from the information available in the
/// landscape.
#[must_use]
pub fn new(
landscape_data: &LandscapeData,
settings: &LandscapeSettings,
crunchbase_data: &CrunchbaseData,
) -> Self {
pub fn new(landscape_data: &LandscapeData, settings: &LandscapeSettings) -> Self {
Self {
members: MembersStats::new(landscape_data, settings),
organizations: OrganizationsStats::new(crunchbase_data),
organizations: OrganizationsStats::new(landscape_data),
projects: ProjectsStats::new(landscape_data),
repositories: RepositoriesStats::new(landscape_data),
}
Expand Down Expand Up @@ -134,13 +130,22 @@ pub struct OrganizationsStats {
impl OrganizationsStats {
/// Create a new OrganizationsStats instance from the information available
/// in the landscape.
fn new(crunchbase_data: &CrunchbaseData) -> Option<Self> {
fn new(landscape_data: &LandscapeData) -> Option<Self> {
let mut stats = OrganizationsStats::default();
let mut crunchbase_data_processed = HashSet::new();

// Collect stats from landscape items
for org in crunchbase_data.values() {
for item in &landscape_data.items {
// Check if this crunchbase data has already been processed
if let Some(url) = item.crunchbase_url.as_ref() {
if crunchbase_data_processed.contains(url) {
continue;
}
crunchbase_data_processed.insert(url);
}

// Acquisitions
if let Some(acquisitions) = org.acquisitions.as_ref() {
if let Some(acquisitions) = item.crunchbase_data.as_ref().and_then(|d| d.acquisitions.as_ref()) {
for acq in acquisitions {
if let Some(announced_on) = acq.announced_on {
let year = announced_on.format("%Y").to_string();
Expand All @@ -155,7 +160,9 @@ impl OrganizationsStats {
}

// Funding rounds
if let Some(funding_rounds) = org.funding_rounds.as_ref() {
if let Some(funding_rounds) =
item.crunchbase_data.as_ref().and_then(|d| d.funding_rounds.as_ref())
{
for fr in funding_rounds {
if let Some(announced_on) = fr.announced_on {
// Only funding rounds in the last 5 years
Expand Down
2 changes: 1 addition & 1 deletion crates/wasm/overlay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub async fn get_overlay_data(input: JsValue) -> Result<String, String> {
let datasets = Datasets {
base: Base::new(&landscape_data, &settings, &guide, &qr_code),
full: Full::new(&landscape_data, &crunchbase_data, &github_data),
stats: Stats::new(&landscape_data, &settings, &crunchbase_data),
stats: Stats::new(&landscape_data, &settings),
};

// Prepare overlay data and return it
Expand Down

0 comments on commit 5565ca0

Please sign in to comment.