Add util extension for calculating hot rank of comments

This commit is contained in:
krawieck 2020-09-02 13:47:45 +02:00
parent 82f2084b60
commit 9e85fd5a2d
1 changed files with 15 additions and 0 deletions

15
lib/util/hot_rank.dart Normal file
View File

@ -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);
}