Skip to content

Commit

Permalink
Add segment ride stats
Browse files Browse the repository at this point in the history
  • Loading branch information
oldnapalm committed Dec 7, 2023
1 parent 4515679 commit 3bb728b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
10 changes: 10 additions & 0 deletions protobuf/segment-result.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,13 @@ message SegmentResults {
optional uint64 event_subgroup_id = 3;
repeated SegmentResult segment_results = 4;
}

message SegmentRideStats {
required int64 segment_id = 1;
optional uint32 f2 = 2;
optional uint32 number_of_results = 3;
optional uint64 latest_time = 4;
optional float latest_percentile = 5;
optional uint64 best_time = 6;
optional float best_percentile = 7;
}
4 changes: 3 additions & 1 deletion protobuf/segment_result_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion variants.txt
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@
"boolValue": false
},
"EnableHeroicDifficulty": {
"boolValue": false
"boolValue": true
},
"MustHaveDefaultRoad": {
"boolValue": false
Expand Down
16 changes: 14 additions & 2 deletions zwift_offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3221,8 +3221,20 @@ def api_personal_records_my_records():
@jwt_to_session_cookie
@login_required
def api_personal_records_my_segment_ride_stats(sport):
# TODO
return '', 200
if not request.args.get('segmentId'):
return '', 422
stats = segment_result_pb2.SegmentRideStats()
stats.segment_id = int(request.args.get('segmentId'))
where_stmt = "WHERE segment_id = :s AND player_id = :p AND sport = :sp"
args = {"s": stats.segment_id, "p": current_user.player_id, "sp": profile_pb2.Sport.Value(sport)}
row = db.session.execute(sqlalchemy.text("SELECT * FROM segment_result %s ORDER BY elapsed_ms LIMIT 1" % where_stmt), args).first()
if row:
stats.number_of_results = db.session.execute(sqlalchemy.text("SELECT COUNT(*) FROM segment_result %s" % where_stmt), args).scalar()
stats.latest_time = row.elapsed_ms # Zwift sends only best
stats.latest_percentile = 100
stats.best_time = row.elapsed_ms
stats.best_percentile = 100
return stats.SerializeToString(), 200


@app.route('/api/personal-records/results/summary/profiles/me/<sport>', methods=['GET'])
Expand Down

0 comments on commit 3bb728b

Please sign in to comment.