Skip to content

Commit 86e02e2

Browse files
authored
Merge pull request #25 from Hyper-Dragon/24-display-only-played-time-controls
24 display only played time controls
2 parents 6a30e03 + 5c437f1 commit 86e02e2

3 files changed

Lines changed: 152 additions & 94 deletions

File tree

ChessStats/ChessStats/Helpers/StatsGraph.cs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@ internal class StatsGraph
3737
public double GraphWidth { get; private set; }
3838
public float TextSize { get; private set; }
3939
public float TextSizeMsg { get; private set; }
40+
public double GameTypeDivisor { get; private set; }
4041

41-
internal StatsGraph(double width = 3840, float textSize = 140, float textSizeMsg = 100)
42+
internal StatsGraph(double width = 3840, float textSize = 140, float textSizeMsg = 100, int gameModesPlayed = 0)
4243
{
43-
TextSize = textSize;
44-
TextSizeMsg = textSizeMsg;
44+
GameTypeDivisor = (4 - (gameModesPlayed == 0 ? 3 : gameModesPlayed));
45+
TextSize = textSize/(float)GameTypeDivisor;
46+
TextSizeMsg = textSizeMsg / (float)GameTypeDivisor;
4547
GraphWidth = width;
48+
4649

4750
font = new(FontFamily.ResolveFontFamily(FontFamily.StandardFontFamilies.TimesRoman), TextSize);
4851
fontMessage = new(FontFamily.ResolveFontFamily(FontFamily.StandardFontFamilies.TimesItalic), TextSizeMsg);
@@ -52,7 +55,7 @@ private Document CreateDocument(double height)
5255
{
5356
Document doc = new();
5457
doc.Pages.Add(new(GraphWidth, height));
55-
58+
5659
LinearGradientBrush bkgBrush = new(new Point(0, 0),
5760
new Point(GraphWidth, height),
5861
new GradientStop(COL_BKG_GRAD_START, 0),
@@ -105,6 +108,8 @@ internal async Task<string> RenderCapsGraph(List<CapsRecord> capsScoresWhite, Li
105108
{
106109
return await Task<string>.Run(() =>
107110
{
111+
height /= GameTypeDivisor;
112+
108113
//Make sure the data is sorted correctly
109114
capsScoresWhite = capsScoresWhite.OrderBy(item => item.GameDate).TakeLast((int)maxCapsGames).ToList();
110115
capsScoresBlack = capsScoresBlack.OrderBy(item => item.GameDate).TakeLast((int)maxCapsGames).ToList();
@@ -162,12 +167,12 @@ internal async Task<string> RenderCapsGraph(List<CapsRecord> capsScoresWhite, Li
162167

163168
GraphicsPath gpWhiteSmooth = new();
164169
_ = gpWhiteSmooth.AddSmoothSpline(gpWhitePoints.ToArray());
165-
gpr.StrokePath(IS_SMOOTH_CAPS ? gpWhiteSmooth : gpWhite, COL_CAPS_WHITE, lineWidth: GRAPH_LINE_WIDTH);
170+
gpr.StrokePath(IS_SMOOTH_CAPS ? gpWhiteSmooth : gpWhite, COL_CAPS_WHITE, lineWidth: GRAPH_LINE_WIDTH/GameTypeDivisor);
166171

167172

168173
GraphicsPath gpBlackSmooth = new();
169174
_ = gpBlackSmooth.AddSmoothSpline(gpBlackPoints.ToArray());
170-
gpr.StrokePath(IS_SMOOTH_CAPS ? gpBlackSmooth : gpBlack, COL_CAPS_BLACK, lineWidth: GRAPH_LINE_WIDTH);
175+
gpr.StrokePath(IS_SMOOTH_CAPS ? gpBlackSmooth : gpBlack, COL_CAPS_BLACK, lineWidth: GRAPH_LINE_WIDTH/GameTypeDivisor);
171176

172177
WriteMessage(gpr, height, $"* Based on the last {whiteMovingAv.Length}/{blackMovingAv.Length} games with available CAPs scores");
173178
}
@@ -181,6 +186,7 @@ internal async Task<string> RenderAllCapsGraph(List<CapsRecord> capsScores, doub
181186
{
182187
return await Task<string>.Run(() =>
183188
{
189+
height /= GameTypeDivisor;
184190
Document doc = CreateDocument(height);
185191
VectSharp.Graphics gpr = doc.Pages[0].Graphics;
186192

@@ -229,11 +235,12 @@ internal async Task<string> RenderAllCapsGraph(List<CapsRecord> capsScores, doub
229235
}).ConfigureAwait(false);
230236
}
231237

232-
internal async Task<string> RenderRatingGraph(List<(DateTime gameDate, int rating,
233-
string gameType)> ratingsPostGame, double height = 1920)
238+
internal async Task<string> RenderRatingGraph(List<(DateTime gameDate, int rating, string gameType)> ratingsPostGame,
239+
double height = 1920)
234240
{
235241
return await Task<string>.Run(() =>
236242
{
243+
height /= GameTypeDivisor;
237244
Document doc = CreateDocument(height);
238245
VectSharp.Graphics gpr = doc.Pages[0].Graphics;
239246

@@ -283,8 +290,8 @@ internal async Task<string> RenderRatingGraph(List<(DateTime gameDate, int ratin
283290

284291
WriteRangeMessage(gpr, height, $"{graphMin}", $"{graphMax}");
285292

286-
gpr.FillRectangle(0, ((graphMax - ratingsPostGameOrdered[^1].rating) * RatingStepY) - (CUR_RATING_BAR_HEIGHT / 2),
287-
GraphWidth, CUR_RATING_BAR_HEIGHT,
293+
gpr.FillRectangle(0, ((graphMax - ratingsPostGameOrdered[^1].rating) * RatingStepY) - ((CUR_RATING_BAR_HEIGHT / GameTypeDivisor) / 2),
294+
GraphWidth, CUR_RATING_BAR_HEIGHT / GameTypeDivisor,
288295
COL_RATING);
289296
}
290297

@@ -293,11 +300,13 @@ internal async Task<string> RenderRatingGraph(List<(DateTime gameDate, int ratin
293300
}).ConfigureAwait(false);
294301
}
295302

296-
internal async Task<string> RenderAverageStatsGraph(List<(string TimeControl, int VsMin, int Worst, int LossAv, int DrawAv,
297-
int WinAv, int Best, int VsMax)> graphData, double height = 1280)
303+
internal async Task<string> RenderAverageStatsGraph(List<(string TimeControl, int VsMin, int Worst, int LossAv, int DrawAv, int WinAv, int Best, int VsMax)> graphData,
304+
double height = 1280)
298305
{
299306
return await Task<string>.Run(() =>
300307
{
308+
height /= ((double)GameTypeDivisor);
309+
301310
int graphMinCalc = graphData.Where(x => x.WinAv != 0 && x.LossAv != 0).Select(x => x.WinAv).DefaultIfEmpty(0).Min();
302311
int graphMaxCalc = graphData.Where(x => x.WinAv != 0 && x.LossAv != 0).Select(x => x.LossAv).DefaultIfEmpty(0).Max();
303312

ChessStats/ChessStats/Helpers/StatsHtml.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using System.Text;
34

45
namespace ChessStats.Helpers
@@ -12,7 +13,7 @@ public static string GetHtmlTail(Uri chessdotcomUrl, string versionNumber, strin
1213
: $"<div class='footer'><br/><hr/><i>Generated by ChessStats (for <a href='{chessdotcomUrl.OriginalString}'>Chess.com</a>)&nbsp;ver. {versionNumber}<br/><a href='{projectLink}'>{projectLink}</a></i><br/><br/><br/></div>";
1314
}
1415

15-
public static string GetHtmlTop(string pageTitle, string backgroundImage, string favIconImage, string font700Fragment, string font800Fragment)
16+
public static string GetHtmlTop(string pageTitle, string backgroundImage, string favIconImage, string font700Fragment, string font800Fragment, int controlsPlayed=3)
1617
{
1718
StringBuilder htmlReport = new();
1819
_ = htmlReport.AppendLine("<!DOCTYPE html>")
@@ -53,12 +54,15 @@ public static string GetHtmlTop(string pageTitle, string backgroundImage, string
5354
.AppendLine(" .headRow {display: grid; grid-template-columns: 200px auto; grid-gap: 0px; border:0px; height: auto; padding: 0px; }")
5455
.AppendLine(" .headRow > div {padding: 0px; }")
5556
.AppendLine(" .headBox img {vertical-align: middle}")
56-
.AppendLine(" .ratingRow {display: grid;grid-template-columns: auto auto auto;grid-gap: 20px;padding: 10px;}")
57+
.AppendLine($" .ratingRow {{display: grid;grid-template-columns: {string.Join(" ","auto auto auto".Split(" ").Take(controlsPlayed))} ;grid-gap: 20px;padding: 10px;}}")
5758
.AppendLine(" .ratingRow > div {font-family: Montserrat; font-weight: 700; text-align: center; padding: 0px; color: whitesmoke; font-size: 15px; font-weight: bold;}")
5859
.AppendLine(" .ratingBox {cursor: pointer;}")
59-
.AppendLine(" .graphRow {display: grid;grid-template-columns: auto auto auto;grid-gap: 10px;padding: 5px;}")
60+
.AppendLine($" .graphRow {{display: grid;grid-template-columns: {string.Join(" ", "auto auto auto".Split(" ").Take(controlsPlayed))} ;grid-gap: 10px;padding: 5px;}}")
6061
.AppendLine(" .graphRow > div {font-family: Montserrat; font-weight: 700; text-align: center; padding: 0px; color: whitesmoke; font-size: 15px; font-weight: bold;}")
61-
.AppendLine(" .graphBox img { max-width:100%; height:auto; }")
62+
.AppendLine(" .graphBox img { width:100%; height:auto; object-fit: cover; }")
63+
.AppendLine(" .graphCapsRow {display: grid;grid-template-columns: 60% auto;grid-gap: 10px;padding: 5px;}")
64+
.AppendLine(" .graphCapsRow>div {font-family: Montserrat;font-weight: 700;text-align: center;padding: 0px;color: whitesmoke;font-size: 15px;font-weight: bold;}")
65+
.AppendLine(" .graphCapsBox img {max-width: 100%; width: auto;height: auto;}")
6266
.AppendLine(" .yearSplit {border-top: thin dotted; border-color: #1583b7;}")
6367
.AppendLine(" .higher {background-color: hsla(120, 100%, 50%, 0.25);}")
6468
.AppendLine(" .lower {background-color: hsla(0, 100%, 70%, 0.4);}")
@@ -70,9 +74,6 @@ public static string GetHtmlTop(string pageTitle, string backgroundImage, string
7074
.AppendLine(" .capsRollingTable tbody td:nth-child(1) {font-size: 14px;font-weight: bold;}")
7175
.AppendLine(" .playingStatsTable tbody td:nth-child(1) {font-size: 14px;font-weight: bold;}")
7276
.AppendLine(" .playingStatsMonthTable tbody td:nth-child(1) {font-size: 14px;font-weight: bold;}")
73-
.AppendLine(" .graphCapsRow {display: grid;grid-template-columns: 60% auto;grid-gap: 10px;padding: 5px;}")
74-
.AppendLine(" .graphCapsRow>div {font-family: Montserrat;font-weight: 700;text-align: center;padding: 0px;color: whitesmoke;font-size: 15px;font-weight: bold;}")
75-
.AppendLine(" .graphCapsBox img {max-width: 100%; width: auto;height: auto;}")
7677
.AppendLine(" .playingStatsTable tbody td:nth-child(5) {border-right: thin solid; border-color: #1583b7;}")
7778
.AppendLine(" .playingStatsTable tbody td:nth-child(8) {border-left: thin dotted; border-color: #1583b7;}")
7879
.AppendLine(" .playingStatsTable tbody td:nth-child(11) {border-left: thin dotted; border-color: #1583b7;}")

0 commit comments

Comments
 (0)