Skip to content

Commit

Permalink
Add cup icons for best track sections
Browse files Browse the repository at this point in the history
  • Loading branch information
RCgmbh committed Jan 8, 2025
1 parent c4a1626 commit c34f429
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 23 deletions.
4 changes: 3 additions & 1 deletion PiLotDataPostgres/Nav/TrackDataConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,9 @@ private TrackSegment ReadTrackSegment(NpgsqlDataReader pReader) {
EndBoatTime = pReader.GetInt64("end_boattime"),
Distance_mm = pReader.GetInt32("distance_mm"),
Speed = pReader.GetDouble("speed"),
Boat = pReader.GetString("boat")
Boat = pReader.GetString("boat"),
YearRank = pReader.GetInt32("year_rank"),
OverallRank = pReader.GetInt32("overall_rank")
};
return result;
}
Expand Down
13 changes: 13 additions & 0 deletions PiLotModel/Nav/TrackSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ public Double Speed {
/// <summary>
/// The boat name
/// </summary>
[JsonPropertyName("boat")]
public String Boat { get; set; }

/// <summary>
/// The rank of this section per section type, boat and year
/// </summary>
[JsonPropertyName("yearRank")]
public Int32 YearRank {get;set;}

/// <summary>
/// The rank of this section per section type and boat
/// </summary>
[JsonPropertyName("overallRank")]
public Int32 OverallRank {get;set;}
}
}
2 changes: 2 additions & 0 deletions PiLotWeb/css/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ body.night .white, body.night a.white, body.night a.white:hover, body.night a.wh
body.night .grey, body.night a.grey, body.night a.grey:hover, body.night a.grey:visited {color: #444;}
.darkGrey, a.darkGrey, a.darkGrey:hover, a.darkGrey:visited {color: #666;}
body.night .darkGrey, body.night a.darkGrey, body.night a.darkGrey:hover, body.night a.darkGrey:visited {color: #999;}
.gold {color: #ffc400;}
.silver {color: #d3d3d3;}

/* LINKS, BUTTONS */
a, a:visited, a:active { color: #3265AD; }
Expand Down
18 changes: 15 additions & 3 deletions PiLotWeb/js/Model/Nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -1931,7 +1931,7 @@ PiLot.Model.Nav = (function () {
* @param {DateTime} pEndBoatTime - the end of the segment in BoatTime
* @param {Number} pDistance - the distance covered in meters
*/
var TrackSegment = function (pTrackId, pType, pStartUtc, pEndUtc, pStartBoatTime, pEndBoatTime, pDistance, pSpeed, pBoat) {
var TrackSegment = function (pTrackId, pType, pStartUtc, pEndUtc, pStartBoatTime, pEndBoatTime, pDistance, pSpeed, pBoat, pYearRank, pOverallRank) {
this.trackId = pTrackId;
this.type = pType;
this.startUtc = pStartUtc;
Expand All @@ -1941,6 +1941,8 @@ PiLot.Model.Nav = (function () {
this.distance = pDistance;
this.speed = pSpeed;
this.boat = pBoat;
this.yearRank = pYearRank;
this.overallRank = pOverallRank;
this.initialize();
};

Expand Down Expand Up @@ -1987,14 +1989,24 @@ PiLot.Model.Nav = (function () {
return this.distance;
},

/** @returns the average speed for the segment in m/s */
/** @returns {Number} the average speed for the segment in m/s */
getSpeed: function () {
return this.speed;
},

/** @returns the name of the boat */
/** @returns {String} the name of the boat */
getBoat: function () {
return this.boat;
},

/** @returns {Number} the rank of this section per type, boat and year */
getYearRank: function(){
return this.yearRank;
},

/** @returns {Number} the rank of this section per type and boat */
getOverallRank: function(){
return this.overallRank;
}
};

Expand Down
6 changes: 4 additions & 2 deletions PiLotWeb/js/Service/Nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ PiLot.Service.Nav = (function () {
* @param {Number} pTrackId
* @returns {PiLot.Model.Nav.TrackSegment[]}
* */
getTrackSegmentsByTrackIdAsync: async function(pTrackId){
loadTrackSegmentsByTrackIdAsync: async function(pTrackId){
let result = null;
await this.ensureTrackSegmentTypesLoadedAsync();
const json = await PiLot.Utils.Common.getFromServerAsync(`/Tracks/${pTrackId}/Segments`);
Expand Down Expand Up @@ -505,7 +505,9 @@ PiLot.Service.Nav = (function () {
RC.Date.DateHelper.millisToLuxon(pData.endBoatTime, pLanguage),
pData.distance,
pData.speed,
pData.boat
pData.boat,
pData.yearRank,
pData.overallRank
);
},

Expand Down
6 changes: 5 additions & 1 deletion PiLotWeb/js/Templates/Nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,5 +390,9 @@ PiLot.Templates.Nav = {
<div><span class="lblLabel"></span>:&nbsp;</div>
<div class="semiBold"><span class="lblSpeed"></span> <span data-text="kn"></span></div>&nbsp;
<div><span class="lblStartTime"></span>-<span class="lblEndTime"></span></div>
</div>`
</div>`,

topSegmentOverall: '<i class="icon-trophy gold marginRightSmall" data-title="topSegmentOverall"></i>',

topSegmentYear: '<i class="icon-trophy silver marginRightSmall" data-title="topSegmentYear"></i>'
};
Binary file modified PiLotWeb/js/Texts/de.js
Binary file not shown.
Binary file modified PiLotWeb/js/Texts/en.js
Binary file not shown.
7 changes: 6 additions & 1 deletion PiLotWeb/js/View/Nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,7 @@ PiLot.View.Nav = (function () {

loadAndShowDataAsync: async function (pTrackId) {
this.container.hidden = false;
const trackSegments = await this.trackService.getTrackSegmentsByTrackIdAsync(pTrackId);
const trackSegments = await this.trackService.loadTrackSegmentsByTrackIdAsync(pTrackId);
trackSegments.sort((a, b) => a.getType().compareTo(b.getType()));
const currentLanguage = PiLot.Utils.Language.getLanguage();
this.plhDistanceSegments.hidden = true;
Expand All @@ -1456,6 +1456,11 @@ PiLot.View.Nav = (function () {
const segmentType = pSegment.getType();
const label = segmentType.getLabel(pLanguage);
control.querySelector('.lblLabel').innerHTML = label;
if(pSegment.getOverallRank() == 1){
control.querySelector('.lblLabel').insertAdjacentElement('afterbegin', PiLot.Utils.Common.createNode(PiLot.Templates.Nav.topSegmentOverall));
} else if (pSegment.getYearRank() == 1){
control.querySelector('.lblLabel').insertAdjacentElement('afterbegin', PiLot.Utils.Common.createNode(PiLot.Templates.Nav.topSegmentYear));
}
const speed = pSegment.getSpeed(); // speed in m/s
if (isDistance) {
let duration = luxon.Duration.fromObject({ seconds: segmentType.getDistance() / speed });
Expand Down
44 changes: 29 additions & 15 deletions installScripts/sql/tracks.sql
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ CREATE VIEW public.all_track_segments AS (
ts.end_boattime,
ts.distance_mm,
ts.distance_mm::DOUBLE PRECISION/(ts.end_utc - ts.start_utc) as speed,
tr.boat
tr.boat,
EXTRACT(YEAR FROM to_timestamp(ts.start_boattime / 1000)) AS year
FROM
track_segments ts INNER JOIN tracks tr ON ts.track_id = tr.id
);
Expand Down Expand Up @@ -350,22 +351,32 @@ RETURNS TABLE (
end_boattime bigint,
distance_mm integer,
speed double precision,
boat text
boat text,
year_rank bigint,
overall_rank bigint
)
LANGUAGE 'sql'
AS $BODY$
SELECT
type_id,
track_id,
start_utc,
end_utc,
start_boattime,
end_boattime,
distance_mm,
speed,
boat
FROM
all_track_segments
*
FROM (
SELECT
type_id,
track_id,
start_utc,
end_utc,
start_boattime,
end_boattime,
distance_mm,
speed,
boat,
row_number() over (PARTITION BY type_id, year ORDER BY speed DESC) as year_rank,
row_number() over (PARTITION BY type_id ORDER BY speed DESC) as overall_rank
FROM
all_track_segments
WHERE
boat IN (SELECT boat FROM tracks WHERE id = p_track_id)
)
WHERE
track_id = p_track_id
$BODY$;
Expand Down Expand Up @@ -393,7 +404,9 @@ RETURNS TABLE (
end_boattime bigint,
distance_mm integer,
speed double precision,
boat text
boat text,
year_rank bigint,
overall_rank bigint
)
LANGUAGE 'sql'
AS $BODY$
Expand All @@ -406,7 +419,8 @@ AS $BODY$
end_boattime,
distance_mm,
speed,
boat
boat,
0, 0
FROM
all_track_segments
WHERE
Expand Down

0 comments on commit c34f429

Please sign in to comment.