@@ -6,6 +6,11 @@ mod app_id;
66
77#[ derive( serde:: Deserialize ) ]
88pub 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]
2530async 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}
0 commit comments