forked from TabbyML/tabby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(webserver): Add more languages to analytics (TabbyML#1790)
* chore(webserver): Add more languages to analytics * [autofix.ci] apply automated fixes * Fix languages, implement Other query, and fix analytics bug * [autofix.ci] apply automated fixes * [autofix.ci] apply automated fixes (attempt 2/3) * [autofix.ci] apply automated fixes (attempt 3/3) * Fix query * [autofix.ci] apply automated fixes * [autofix.ci] apply automated fixes (attempt 2/3) * [autofix.ci] apply automated fixes (attempt 3/3) * update * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Meng Zhang <[email protected]>
- Loading branch information
1 parent
f38192f
commit 7ff97a5
Showing
8 changed files
with
136 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,13 +39,29 @@ impl AnalyticService for AnalyticServiceImpl { | |
start: DateTime<Utc>, | ||
end: DateTime<Utc>, | ||
users: Vec<ID>, | ||
languages: Vec<Language>, | ||
mut languages: Vec<Language>, | ||
) -> Result<Vec<CompletionStats>> { | ||
let users = convert_ids(users); | ||
let languages = languages.into_iter().map(|l| l.to_string()).collect(); | ||
|
||
let include_other_languages = languages.iter().any(|l| l == &Language::Other); | ||
let not_languages = if include_other_languages { | ||
Some(Language::all_known().flat_map(|l| l.to_strings()).collect()) | ||
} else { | ||
None | ||
}; | ||
|
||
languages.retain(|l| l != &Language::Other); | ||
|
||
let languages = languages.into_iter().flat_map(|l| l.to_strings()).collect(); | ||
let stats = self | ||
.db | ||
.compute_daily_stats(start, end, users, languages) | ||
.compute_daily_stats( | ||
start, | ||
end, | ||
users, | ||
languages, | ||
not_languages.unwrap_or_default(), | ||
) | ||
.await?; | ||
let stats = stats | ||
.into_iter() | ||
|
@@ -154,4 +170,39 @@ mod tests { | |
assert_eq!(1, stats[0].completions); | ||
assert_eq!(1, stats[0].selects); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_other_langs() { | ||
let db = DbConn::new_in_memory().await.unwrap(); | ||
|
||
let user_id = db | ||
.create_user("[email protected]".into(), Some("pass".into()), true) | ||
.await | ||
.unwrap(); | ||
|
||
db.create_user_completion( | ||
timestamp(), | ||
user_id, | ||
"completion_id".into(), | ||
"testlang".into(), | ||
) | ||
.await | ||
.unwrap(); | ||
|
||
db.create_user_completion(timestamp(), user_id, "completion_id2".into(), "rust".into()) | ||
.await | ||
.unwrap(); | ||
|
||
let service = new_analytic_service(db); | ||
let end = Utc::now(); | ||
let start = end.checked_sub_days(Days::new(100)).unwrap(); | ||
|
||
let stats = service | ||
.daily_stats(start, end, vec![], vec![Language::Other]) | ||
.await | ||
.unwrap(); | ||
|
||
assert_eq!(1, stats.len()); | ||
assert_eq!(1, stats[0].completions); | ||
} | ||
} |