Add util extension for calculating hot rank of comments
This commit is contained in:
parent
82f2084b60
commit
9e85fd5a2d
|
@ -0,0 +1,15 @@
|
|||
// import 'dart:core' show ab;
|
||||
import 'dart:math' show log, max, pow;
|
||||
|
||||
import 'package:lemmy_api_client/lemmy_api_client.dart';
|
||||
|
||||
double _calculateHotRank(int score, DateTime time) {
|
||||
final elapsed = (time.difference(DateTime.now()).inMilliseconds).abs() / 36e5;
|
||||
|
||||
// log instead of log10 in web version. does log == log10?
|
||||
return (10000 * log(max(1, 3 + score))) / pow(elapsed + 2, 1.8);
|
||||
}
|
||||
|
||||
extension CommentHotRank on CommentView {
|
||||
double get computedHotRank => _calculateHotRank(score, published);
|
||||
}
|
Loading…
Reference in New Issue