Add percentage of subscribers compared to the highest-subscribed group.
This commit is contained in:
		
							parent
							
								
									f28a0bf505
								
							
						
					
					
						commit
						65eb941eb4
					
				|  | @ -65,3 +65,7 @@ details { | |||
| .underline { | ||||
|   text-decoration: underline; | ||||
| } | ||||
| 
 | ||||
| .small { | ||||
|   font-size: 1rem; | ||||
| } | ||||
|  |  | |||
|  | @ -44,7 +44,11 @@ | |||
|           <td> | ||||
|             <a href="/{{ group.name }}">{{ group.name }}</a> | ||||
|           </td> | ||||
|           <td>{{ group.subscribers }}</td> | ||||
|           <td> | ||||
|             {{ group.subscribers }} <span class="small" | ||||
|               title="Percentage of subscribers compared to the highest-subscribed group." | ||||
|             >({{ group.subscribers|percentage(user_count) }})</span> | ||||
|           </td> | ||||
|           <td> | ||||
|             {% if let Some(description) = group.description %} | ||||
|             {{ description }} | ||||
|  |  | |||
|  | @ -40,7 +40,7 @@ pub struct HomeTemplate { | |||
|   pub today: NaiveDate, | ||||
| 
 | ||||
|   /// The user count from the group with the most subscribers.
 | ||||
|   pub user_count: String, | ||||
|   pub user_count: i64, | ||||
| } | ||||
| 
 | ||||
| impl HomeTemplate { | ||||
|  | @ -59,9 +59,7 @@ impl HomeTemplate { | |||
|       groups, | ||||
|       page_title: "Tildes Statistics".to_string(), | ||||
|       today: today(), | ||||
|       user_count: user_count | ||||
|         .map(|n| n.to_string()) | ||||
|         .unwrap_or_else(|| "unknown".to_string()), | ||||
|       user_count: user_count.unwrap_or(1), | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|  | @ -128,3 +126,10 @@ impl GroupTemplate { | |||
|     Ok(()) | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| mod filters { | ||||
|   pub fn percentage(a: &i64, b: &i64) -> askama::Result<String> { | ||||
|     let percentage = (*a as f64 / *b as f64) * 100_f64; | ||||
|     Ok(format!("{:.2}%", percentage)) | ||||
|   } | ||||
| } | ||||
|  |  | |||
		Reference in New Issue