22Data structures and convenience methods for creating and interacting with rating data 
33*/ 
44
5- use  crate :: glicko2:: constants; 
5+ use  crate :: glicko2:: { constants,  tuning :: Tuning } ; 
66
77/// Represents a team's Glicko2 rating (mu), distribution (phi), and volatility (sigma). 
88#[ derive( Debug ,  Copy ,  Clone ) ]  
9- pub  struct  Rating  { 
9+ pub  struct  Rating < ' a >  { 
1010 pub  mu :  f64 , 
1111 pub  phi :  f64 , 
1212 pub  sigma :  f64 , 
1313 pub  is_scaled :  bool , 
14+  pub ( crate )  tuning :  & ' a  Tuning , 
1415} 
1516
16- impl  Rating  { 
17+ impl < ' a >  Rating < ' a >  { 
1718 /// Create a new instance of a Rating with default constants. 
1819 /// 
1920 /// # Example 
2021 /// ``` 
21-  /// use glicko2::Rating; 
22+  /// use glicko2::{ Rating, Tuning} ; 
2223 /// 
23-  /// let team_1 = Rating::new(); 
24+  /// let tuning = Tuning::default(); 
25+  /// let team_1 = Rating::new(&tuning); 
2426 /// ``` 
25-  pub  fn  new ( )  -> Rating  { 
27+  pub  fn  new ( tuning : & Tuning )  -> Rating  { 
2628 Rating  { 
27-  mu :  constants :: MU , 
28-  phi :  constants :: PHI , 
29-  sigma :  constants :: SIGMA , 
29+  mu :  tuning . mu , 
30+  phi :  tuning . phi , 
31+  sigma :  tuning . sigma , 
3032 is_scaled :  false , 
33+  tuning, 
3134 } 
3235 } 
3336
3437 /// Scales a rating down to the Glicko2 scale 
3538 pub ( crate )  fn  scale_down ( & mut  self )  { 
3639 if  !self . is_scaled  { 
37-  let  mu = ( self . mu  - constants :: MU )  / constants:: RATIO ; 
40+  let  mu = ( self . mu  - self . tuning . mu )  / constants:: RATIO ; 
3841 let  phi = self . phi  / constants:: RATIO ; 
3942 self . mu  = mu; 
4043 self . phi  = phi; 
@@ -45,7 +48,7 @@ impl Rating {
4548 /// Scales a rating up to the nominal scale 
4649 pub ( crate )  fn  scale_up ( & mut  self )  { 
4750 if  self . is_scaled  { 
48-  let  mu = ( self . mu  *  constants:: RATIO )  + constants :: MU ; 
51+  let  mu = ( self . mu  *  constants:: RATIO )  + self . tuning . mu ; 
4952 let  phi = self . phi  *  constants:: RATIO ; 
5053 self . mu  = mu; 
5154 self . phi  = phi; 
@@ -56,9 +59,11 @@ impl Rating {
5659 /// Decay a rating for a team that has not played during a period 
5760 /// # Example 
5861 /// ``` 
59-  /// use glicko2::Rating; 
60-  /// 
61-  /// let mut new_rating = Rating::new(); 
62+  /// use glicko2::{Rating, Tuning}; 
63+  ///  
64+  /// let tuning = Tuning::default(); 
65+  /// let mut new_rating = Rating::new(&tuning); 
66+  ///  
6267 /// new_rating.decay(); 
6368 /// ``` 
6469 pub  fn  decay ( & mut  self )  { 
@@ -70,9 +75,3 @@ impl Rating {
7075 self . scale_up ( ) ; 
7176 } 
7277} 
73- 74- impl  Default  for  Rating  { 
75-  fn  default ( )  -> Self  { 
76-  Self :: new ( ) 
77-  } 
78- } 
0 commit comments