Skip to content

Commit 4c3ae1e

Browse files
committed
update data; add new updates chart
1 parent 12f0cc9 commit 4c3ae1e

File tree

155 files changed

+363
-200
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+363
-200
lines changed

data-lib/src/date.rs

Lines changed: 71 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
11
use chrono::Datelike;
22
use serde::{Deserialize, Serialize};
33

4+
pub fn is_leap_year(year: u32) -> bool {
5+
(year.is_multiple_of(4) && !year.is_multiple_of(100)) || year.is_multiple_of(400)
6+
}
7+
8+
pub fn get_days_in_month(month: u32, year: u32) -> u32 {
9+
match month {
10+
1 | 3 | 5 | 7 | 8 | 10 | 12 => 31,
11+
4 | 6 | 9 | 11 => 30,
12+
2 => {
13+
if is_leap_year(year) {
14+
29
15+
} else {
16+
28
17+
}
18+
}
19+
_ => panic!("Invalid month"),
20+
}
21+
}
22+
423
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)]
524
pub struct Date {
625
pub year: u32,
26+
/// the month, starting with 1 for january
727
pub month: u32,
28+
// the day, starting at 1 each month
829
pub day: u32,
930
}
1031

@@ -52,38 +73,31 @@ impl Date {
5273
}
5374

5475
pub fn get_month_length(&self) -> u32 {
55-
match self.month {
56-
1 | 3 | 5 | 7 | 8 | 10 | 12 => 31,
57-
4 | 6 | 9 | 11 => 30,
58-
2 => {
59-
if self.is_leap_year() {
60-
29
61-
} else {
62-
28
63-
}
64-
}
65-
_ => panic!("Invalid month"),
66-
}
76+
get_days_in_month(self.month, self.year)
6777
}
6878

6979
pub fn is_leap_year(&self) -> bool {
70-
(self.year.is_multiple_of(4) && !self.year.is_multiple_of(100))
71-
|| self.year.is_multiple_of(400)
80+
is_leap_year(self.year)
7281
}
7382

7483
pub fn days_since_epoch(&self) -> u32 {
7584
let mut days = 0;
7685
for y in 1970..self.year {
77-
days += if Date::new(y, 1, 1).is_leap_year() {
78-
366
79-
} else {
80-
365
81-
};
86+
days += if is_leap_year(y) { 366 } else { 365 };
8287
}
88+
days + self.day_in_year() - 1 // Subtract one because we start counting from day 1
89+
}
90+
91+
pub fn day_in_year(&self) -> u32 {
92+
let mut days = 0;
8393
for m in 1..self.month {
84-
days += Date::new(self.year, m, 1).get_month_length();
94+
days += get_days_in_month(m, self.year);
8595
}
86-
days + self.day - 1 // Subtract one because we start counting from day 1
96+
days + self.day
97+
}
98+
99+
pub fn week_number(&self) -> u32 {
100+
(self.day_in_year() + 1) / 7 + 1
87101
}
88102

89103
pub fn week_day(&self) -> u32 {
@@ -161,6 +175,12 @@ impl Date {
161175
}
162176
}
163177

178+
pub fn week_start(&self) -> Date {
179+
let mut date = self.clone();
180+
date.reverse_days(self.week_day());
181+
date
182+
}
183+
164184
pub fn diff_in_days(&self, other: &Date) -> i32 {
165185
let self_days = self.days_since_epoch();
166186
let other_days = other.days_since_epoch();
@@ -299,3 +319,33 @@ fn date_advance() {
299319
date5.advance_month();
300320
assert_eq!(date5.to_fancy_string(), "2024-01-01");
301321
}
322+
323+
#[test]
324+
fn week_number() {
325+
let date1 = Date::new(2025, 1, 1);
326+
assert_eq!(date1.week_number(), 1);
327+
328+
let date2 = Date::new(2025, 11, 23);
329+
assert_eq!(date2.week_number(), 47);
330+
331+
let date3 = Date::new(2025, 11, 24);
332+
assert_eq!(date3.week_number(), 48);
333+
}
334+
335+
#[test]
336+
fn week_day() {
337+
let date2 = Date::new(2025, 11, 23);
338+
assert_eq!(date2.week_day(), 6);
339+
340+
let date3 = Date::new(2025, 11, 24);
341+
assert_eq!(date3.week_day(), 0);
342+
}
343+
344+
#[test]
345+
fn week_start() {
346+
let date2 = Date::new(2025, 11, 23);
347+
assert_eq!(date2.week_start(), Date::new(2025, 11, 17));
348+
349+
let date3 = Date::new(2025, 11, 24);
350+
assert_eq!(date3.week_start(), date3);
351+
}

data-lib/src/plugin/data_array.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::ops::Index;
22

3+
use hashbrown::HashMap;
34
use wasm_bindgen::prelude::wasm_bindgen;
45

56
use crate::{
@@ -414,6 +415,24 @@ impl PluginDataArrayView {
414415
tmp
415416
}
416417

418+
pub fn updates_weekly(&self, data: &PluginDataArray) -> Vec<NamedDataPoint> {
419+
let mut points = vec![];
420+
421+
self.iter_data(data).for_each(|item| {
422+
item.data.version_history.iter().for_each(|version| {
423+
increment_named_data_points(
424+
&mut points,
425+
&version.initial_release_date.week_start().to_fancy_string(),
426+
1.0,
427+
);
428+
});
429+
});
430+
431+
points.sort_by(|a, b| a.name.cmp(&b.name));
432+
433+
points
434+
}
435+
417436
pub fn repo_data_points(&self, data: &PluginDataArray) -> PluginRepoDataPoints {
418437
let mut points = PluginRepoDataPoints::default();
419438

data/out/licenses.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -986,26 +986,26 @@
986986
],
987987
"permissions": [
988988
"patent-use",
989+
"commercial-use",
989990
"distribution",
990991
"private-use",
991-
"modifications",
992-
"commercial-use"
992+
"modifications"
993993
],
994994
"conditions": [
995-
"include-copyright",
996-
"same-license",
997995
"document-changes",
996+
"include-copyright",
998997
"network-use-disclose",
998+
"same-license--library",
999999
"include-copyright--source",
1000-
"same-license--file",
10011000
"disclose-source",
1002-
"same-license--library"
1001+
"same-license--file",
1002+
"same-license"
10031003
],
10041004
"limitations": [
1005-
"trademark-use",
1006-
"warranty",
10071005
"liability",
1008-
"patent-use"
1006+
"trademark-use",
1007+
"patent-use",
1008+
"warranty"
10091009
],
10101010
"descriptions": {
10111011
"permissions": [

data/out/plugin-data/chunk_0.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

data/out/plugin-data/chunk_1.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

data/out/plugin-data/chunk_10.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

data/out/plugin-data/chunk_11.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

data/out/plugin-data/chunk_12.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

data/out/plugin-data/chunk_13.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

data/out/plugin-data/chunk_14.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)