-
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.
#22 Add relative plot functionality for artists
- Loading branch information
Showing
6 changed files
with
83 additions
and
6 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use super::{create_plot, find_dates}; | ||
use crate::display::date; | ||
use crate::types::{Artist, SongEntries}; | ||
|
||
/// Creates a plot of the amount of plays of an [`Artist`] relative to all plays | ||
/// | ||
/// Opens the plot in the browser | ||
pub fn artist(entries: &SongEntries, art: &Artist) { | ||
let mut times = Vec::<i64>::new(); | ||
// percentages relative to the sum of all plays | ||
let mut plays = Vec::<f64>::new(); | ||
|
||
let dates = find_dates(entries, art, true); | ||
|
||
let start = dates.first().unwrap(); | ||
let sum_start = &entries.first_date(); | ||
|
||
for date in &dates { | ||
times.push(date.timestamp()); | ||
let sum_of_plays = date::gather_artist(entries, art, start, date) as f64; | ||
let sum_of_all_plays = date::sum_plays(entries, &sum_start, date) as f64; | ||
plays.push(sum_of_plays / sum_of_all_plays); | ||
} | ||
|
||
create_plot(times, plays, format!("{art} - relative").as_str()); | ||
} |
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