Skip to content

Commit 5f21b97

Browse files
committed
Create team ranking algorithm
1 parent ab576d6 commit 5f21b97

File tree

7 files changed

+194
-24
lines changed

7 files changed

+194
-24
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import 'package:sj_manager/models/simulation/flow/jumper_dynamic_params.dart';
2+
import 'package:sj_manager/models/user_db/jumper/jumper.dart';
3+
4+
class CountryTeamRankingCreator {
5+
const CountryTeamRankingCreator({
6+
required this.jumpers,
7+
required this.dynamicParams,
8+
});
9+
10+
final List<Jumper> jumpers;
11+
final Map<Jumper, JumperDynamicParams> dynamicParams;
12+
13+
List<Jumper> create() {
14+
final ratings = {
15+
for (final jumper in jumpers) jumper: _calculateRating(jumper),
16+
};
17+
final sorted = List.of(jumpers)
18+
..sort((first, second) {
19+
return ratings[second]!.compareTo(ratings[first]!);
20+
});
21+
return sorted;
22+
}
23+
24+
double _calculateRating(Jumper jumper) {
25+
return (jumper.skills.takeoffQuality / 1) +
26+
(jumper.skills.flightQuality / 1) +
27+
(jumper.skills.landingQuality / 10) +
28+
(dynamicParams[jumper]!.jumpsConsistency / 1.5) +
29+
(dynamicParams[jumper]!.form * 2);
30+
}
31+
}
32+
33+
/*
34+
takeoff quality: 15
35+
flight quality: 15
36+
landing quality: 15 / 10
37+
jumps consistency: 14 / 1.5
38+
form: 10 * 2
39+
*/
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:sj_manager/models/user_db/jumper/jumper.dart';
3+
import 'package:sj_manager/ui/screens/simulation/large/widgets/simulation_jumper_image.dart';
4+
5+
class JumperInRankingTile extends StatelessWidget {
6+
const JumperInRankingTile({
7+
super.key,
8+
required this.jumper,
9+
required this.position,
10+
this.onTap,
11+
});
12+
13+
final Jumper jumper;
14+
final int position;
15+
final VoidCallback? onTap;
16+
17+
@override
18+
Widget build(BuildContext context) {
19+
return ListTile(
20+
leading: Text(
21+
position.toString(),
22+
style: Theme.of(context).textTheme.bodyLarge,
23+
),
24+
trailing: SimulationJumperImage(
25+
jumper: jumper,
26+
width: 25,
27+
),
28+
title: Text(jumper.nameAndSurname()),
29+
onTap: onTap,
30+
);
31+
}
32+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:sj_manager/models/user_db/jumper/jumper.dart';
3+
import 'package:sj_manager/ui/reusable_widgets/jumpers_ranking/jumper_in_ranking_tile.dart';
4+
5+
class TeamJumpersRankingList extends StatelessWidget {
6+
const TeamJumpersRankingList({
7+
super.key,
8+
required this.jumpers,
9+
});
10+
11+
final List<Jumper> jumpers;
12+
13+
@override
14+
Widget build(BuildContext context) {
15+
return ListView(
16+
children: [
17+
for (var i = 0; i < jumpers.length; i++)
18+
JumperInRankingTile(
19+
jumper: jumpers[i],
20+
position: i + 1,
21+
),
22+
],
23+
);
24+
}
25+
}

lib/ui/screens/simulation/large/subscreens/__teams_screen.dart

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -157,23 +157,26 @@ class _ListView extends StatelessWidget {
157157
await showDialog(
158158
context: context,
159159
builder: (context) {
160-
return MultiProvider(
161-
providers: [
162-
Provider.value(value: flagsRepo),
163-
],
164-
child: Center(
165-
child: ClipRRect(
166-
borderRadius: BorderRadius.circular(15),
167-
child: Container(
168-
width: MediaQuery.of(context).size.width * 0.7,
169-
height: MediaQuery.of(context).size.height * 0.8,
170-
padding: const EdgeInsets.all(6),
171-
decoration: BoxDecoration(
172-
color: Theme.of(context).colorScheme.surfaceContainerHigh,
173-
borderRadius: BorderRadius.circular(15),
174-
),
175-
child: CountryTeamProfileWidget(
176-
team: team,
160+
return BlocProvider.value(
161+
value: context.read<SimulationDatabaseCubit>(),
162+
child: MultiProvider(
163+
providers: [
164+
Provider.value(value: flagsRepo),
165+
],
166+
child: Center(
167+
child: ClipRRect(
168+
borderRadius: BorderRadius.circular(15),
169+
child: Container(
170+
width: MediaQuery.of(context).size.width * 0.7,
171+
height: MediaQuery.of(context).size.height * 0.8,
172+
padding: const EdgeInsets.all(6),
173+
decoration: BoxDecoration(
174+
color: Theme.of(context).colorScheme.surfaceContainerHigh,
175+
borderRadius: BorderRadius.circular(15),
176+
),
177+
child: CountryTeamProfileWidget(
178+
team: team,
179+
),
177180
),
178181
),
179182
),
@@ -187,7 +190,3 @@ class _ListView extends StatelessWidget {
187190
);
188191
}
189192
}
190-
191-
// francja
192-
// musi zawierac f i r
193-
// fr

lib/ui/screens/simulation/large/widgets/teams/country_team_profile_widget.dart renamed to lib/ui/screens/simulation/large/widgets/teams/country_team_profile/country_team_profile_widget.dart

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:gap/gap.dart';
33
import 'package:material_symbols_icons/material_symbols_icons.dart';
44
import 'package:sj_manager/models/user_db/team/country_team/country_team.dart';
55
import 'package:sj_manager/ui/reusable_widgets/countries/country_flag.dart';
6+
import 'package:sj_manager/ui/screens/simulation/large/widgets/teams/country_team_profile/overview/country_team_profile_overview.dart';
67
import 'package:sj_manager/utils/icons.dart';
78

89
class CountryTeamProfileWidget extends StatefulWidget {
@@ -42,7 +43,7 @@ class _CountryTeamProfileWidgetState extends State<CountryTeamProfileWidget> {
4243
length: 3,
4344
child: Column(
4445
children: [
45-
TabBar(
46+
const TabBar(
4647
tabs: [
4748
Tab(
4849
text: 'Przegląd',
@@ -57,7 +58,22 @@ class _CountryTeamProfileWidgetState extends State<CountryTeamProfileWidget> {
5758
icon: Icon(Symbols.analytics),
5859
),
5960
],
60-
)
61+
),
62+
const Gap(10),
63+
Expanded(
64+
child: Padding(
65+
padding: const EdgeInsets.only(left: 5),
66+
child: TabBarView(
67+
children: [
68+
CountryTeamProfileOverview(
69+
countryTeam: widget.team,
70+
),
71+
const Placeholder(),
72+
const Placeholder(),
73+
],
74+
),
75+
),
76+
),
6177
],
6278
),
6379
),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_bloc/flutter_bloc.dart';
3+
import 'package:sj_manager/algorithms/jumpers_ranking/country_team_ranking_creator.dart';
4+
import 'package:sj_manager/bloc/simulation/simulation_database_cubit.dart';
5+
import 'package:sj_manager/models/user_db/jumper/jumper.dart';
6+
import 'package:sj_manager/models/user_db/team/country_team/country_team.dart';
7+
import 'package:sj_manager/ui/reusable_widgets/card_with_title.dart';
8+
import 'package:sj_manager/ui/reusable_widgets/jumpers_ranking/team_jumpers_ranking_list.dart';
9+
10+
class CountryTeamProfileOverview extends StatelessWidget {
11+
const CountryTeamProfileOverview({
12+
super.key,
13+
required this.countryTeam,
14+
});
15+
16+
final CountryTeam countryTeam;
17+
18+
@override
19+
Widget build(BuildContext context) {
20+
final database = context.watch<SimulationDatabaseCubit>().state;
21+
final subteams = database.subteamJumpers.keys.where(
22+
(subteam) => subteam.parentTeam == countryTeam,
23+
);
24+
final unorderedJumpers = <Jumper>[];
25+
for (var subteam in subteams) {
26+
final jumperIds = database.subteamJumpers[subteam]!;
27+
unorderedJumpers.addAll(
28+
jumperIds.map((id) => database.idsRepo.get(id) as Jumper),
29+
);
30+
}
31+
final ranking = CountryTeamRankingCreator(
32+
jumpers: unorderedJumpers, dynamicParams: database.jumperDynamicParams)
33+
.create();
34+
35+
return Row(
36+
children: [
37+
SizedBox(
38+
width: 250,
39+
child: CardWithTitle(
40+
title: Text(
41+
'Ranking',
42+
style: Theme.of(context).textTheme.headlineSmall,
43+
),
44+
child: TeamJumpersRankingList(
45+
jumpers: ranking,
46+
),
47+
),
48+
)
49+
],
50+
);
51+
}
52+
}
53+
54+
// ranking skoczków
55+
// perspektywa
56+
// podstawowe rekordy (wygranych konkursow druż pś, wygranych konkursów ind pś)
57+
// gwiazdki
58+
// płeć na fladze
59+
//

lib/ui/screens/simulation/simulation_route.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import 'package:sj_manager/ui/screens/simulation/large/widgets/team/team_screen/
4040
import 'package:sj_manager/ui/screens/simulation/large/widgets/team/team_screen/team_screen_personal_coach_bottom_bar.dart';
4141
import 'package:sj_manager/ui/screens/simulation/large/widgets/team/team_screen/team_summary_card.dart';
4242
import 'package:sj_manager/ui/screens/simulation/large/widgets/teams/country_team_overview_list_tile.dart';
43-
import 'package:sj_manager/ui/screens/simulation/large/widgets/teams/country_team_profile_widget.dart';
43+
import 'package:sj_manager/ui/screens/simulation/large/widgets/teams/country_team_profile/country_team_profile_widget.dart';
4444
import 'package:sj_manager/utils/filtering.dart';
4545
import 'package:sj_manager/utils/show_dialog.dart';
4646
import 'package:sj_manager/utils/translating.dart';

0 commit comments

Comments
 (0)