forked from firka/firka
firka: show weighted avg when adding ghost grades
This commit is contained in:
@@ -1051,18 +1051,6 @@ class _GradeCalculatorSheetContentState
|
||||
int weightPercent = 100;
|
||||
final List<(int grade, int weight)> entries = [];
|
||||
|
||||
double get _weightedAverage {
|
||||
if (entries.isEmpty) return 0;
|
||||
double sum = 0;
|
||||
double weightTotal = 0;
|
||||
for (final e in entries) {
|
||||
final w = e.$2 / 100.0;
|
||||
weightTotal += w;
|
||||
sum += e.$1 * w;
|
||||
}
|
||||
return weightTotal > 0 ? sum / weightTotal : 0;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:firka/ui/phone/widgets/grade_summary_bar.dart';
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
import 'package:firka/core/extensions.dart';
|
||||
import 'package:firka/ui/components/common_bottom_sheets.dart';
|
||||
@@ -312,6 +313,12 @@ class _HomeGradesSubjectScreen extends FirkaState<HomeGradesSubjectScreen> {
|
||||
GradeChartWithInteraction(
|
||||
grades: _gradesWithGhosts(aGrade.subject),
|
||||
),
|
||||
SizedBox(height: 2),
|
||||
GradeSummaryBar(
|
||||
grades: _gradesWithGhosts(aGrade.subject),
|
||||
l10n: widget.data.l10n,
|
||||
showAverage: ghostGradeWidgets.isNotEmpty,
|
||||
),
|
||||
SizedBox(height: 12),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 4),
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:firka/core/average_helper.dart';
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
import 'package:firka/ui/components/grade.dart';
|
||||
import 'package:firka/ui/components/grade_helpers.dart';
|
||||
@@ -11,8 +12,14 @@ import 'package:firka/ui/theme/style.dart';
|
||||
class GradeSummaryBar extends StatefulWidget {
|
||||
final List<Grade> grades;
|
||||
final AppLocalizations l10n;
|
||||
final bool showAverage;
|
||||
|
||||
const GradeSummaryBar({super.key, required this.grades, required this.l10n});
|
||||
const GradeSummaryBar({
|
||||
super.key,
|
||||
required this.grades,
|
||||
required this.l10n,
|
||||
this.showAverage = false,
|
||||
});
|
||||
|
||||
@override
|
||||
State<GradeSummaryBar> createState() => _GradeSummaryBarState();
|
||||
@@ -32,6 +39,9 @@ class _GradeSummaryBarState extends State<GradeSummaryBar> {
|
||||
appStyle.colors.grade5,
|
||||
];
|
||||
final totalCounted = countsByGrade.reduce((a, b) => a + b);
|
||||
final averageText = widget.showAverage
|
||||
? calculateAverage(widget.grades).toStringAsFixed(2)
|
||||
: '';
|
||||
|
||||
return Card(
|
||||
shadowColor: Colors.transparent,
|
||||
@@ -49,7 +59,9 @@ class _GradeSummaryBarState extends State<GradeSummaryBar> {
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
widget.l10n.gradesCount(total),
|
||||
widget.showAverage
|
||||
? '${widget.l10n.gradesCount(total)} ($averageText)'
|
||||
: widget.l10n.gradesCount(total),
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user