Skip to content

Commit 5d623f1

Browse files
FreddyFunkjacobgkau
authored andcommitted
Update Flathub stats to January 2026
Disclosure: I developed this code utilizing LSPs and LLMs. All changes have been manually reviewed by me.
1 parent 8f1609f commit 5d623f1

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

flathub-stats/src/main.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ mod app_id;
66

77
#[derive(serde::Deserialize)]
88
pub struct Stats {
9+
/// New format (2026+): { "app.id": { "CC": (downloads, updates) } }
10+
#[serde(default)]
11+
ref_by_country: HashMap<String, HashMap<String, (u64, u64)>>,
12+
/// Old format (pre-2026): { "app.id/arch": { "channel": (downloads, updates) } }
13+
#[serde(default)]
914
refs: HashMap<String, HashMap<String, (u64, u64)>>,
1015
}
1116

@@ -23,8 +28,8 @@ fn leap_year(year: u16) -> bool {
2328

2429
#[tokio::main]
2530
async fn main() -> Result<(), Box<dyn Error>> {
26-
let year = 2025;
27-
let month = 9;
31+
let year = 2026;
32+
let month = 1;
2833
let days = match month {
2934
1 | 3 | 5 | 7 | 8 | 10 | 12 => 31,
3035
4 | 6 | 9 | 11 => 30,
@@ -41,16 +46,27 @@ async fn main() -> Result<(), Box<dyn Error>> {
4146
let mut ref_downloads = HashMap::<AppId, u64>::new();
4247
for day in 1..=days {
4348
let stats = stats(year, month, day).await?;
44-
for (r, archs) in stats.refs {
45-
for (_arch, (downloads, _updates)) in archs {
46-
let id = r.split('/').next().unwrap();
47-
*ref_downloads.entry(AppId::new(&id)).or_insert(0) += downloads;
49+
if !stats.ref_by_country.is_empty() {
50+
for (app_id, countries) in stats.ref_by_country {
51+
let total: u64 = countries.values().map(|(dl, _)| *dl).sum();
52+
if total > 0 {
53+
*ref_downloads.entry(AppId::new(&app_id)).or_insert(0) += total;
54+
}
55+
}
56+
} else {
57+
for (r, archs) in stats.refs {
58+
for (_arch, (downloads, _updates)) in archs {
59+
let id = r.split('/').next().unwrap();
60+
*ref_downloads.entry(AppId::new(&id)).or_insert(0) += downloads;
61+
}
4862
}
4963
}
5064
}
5165

5266
let bitcode = bitcode::encode(&ref_downloads);
5367
fs::write(format!("res/flathub-stats.bitcode-v0-6"), &bitcode)?;
5468

69+
println!("Wrote stats for {} apps", ref_downloads.len());
70+
5571
Ok(())
5672
}

res/flathub-stats.bitcode-v0-6

56.5 KB
Binary file not shown.

src/appstream_cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl AppstreamCache {
196196

197197
/// Versioned filename of cache
198198
fn cache_filename() -> &'static str {
199-
"appstream_cache-v2.bitcode-v0-6"
199+
"appstream_cache-v3.bitcode-v0-6"
200200
}
201201

202202
/// Remove all files from cache not matching filename

0 commit comments

Comments
 (0)