smoke purpp

This commit is contained in:
ntr committed 2023-08-31 16:55:31 +10:00
1 parent dba4e3fe2b
commit d086069e18
9 files changed
+92 -85

No files matched your search

+9 -3
View File
@@ -23,7 +23,8 @@ public class LapService {
PbDTO _pb; PbDTO _pb;
PbDTO _lr; PbDTO _lr;
public Lap PB; public Lap Pb;
public Lap LapRecord;
public LapService(string mapName) { public LapService(string mapName) {
_mapName = mapName; _mapName = mapName;
@@ -53,15 +54,20 @@ public class LapService {
_pb = dto.Pb; _pb = dto.Pb;
_lr = dto.LapRecord; _lr = dto.LapRecord;
PB = new Lap { Pb = new Lap {
Map = _pb.Map, Map = _pb.Map,
Sectors = _pb.Sectors.Select((d, i) => new SectorTime { Sector = i + 1, Seconds = d }).ToList(), Sectors = _pb.Sectors.Select((d, i) => new SectorTime { Sector = i + 1, Seconds = d }).ToList(),
}; };
LapRecord = new Lap {
Map = _lr.Map,
Sectors = _lr.Sectors.Select((d, i) => new SectorTime { Sector = i + 1, Seconds = d }).ToList(),
};
} catch (Exception e) { } catch (Exception e) {
Debug.LogWarning($"Failed to set lap times {e}"); Debug.LogWarning($"Failed to set lap times {e}");
_pb = null; _pb = null;
_lr = null; _lr = null;
PB = null; Pb = null;
} }
} }
+9 -13
View File
@@ -14,21 +14,17 @@ public enum NoticeCategory {
} }
public class TimingNotice { public class TimingNotice {
public double Seconds; double Seconds;
NoticeCategory Category = NoticeCategory.Initial; NoticeCategory Category = NoticeCategory.Initial;
public TimingNotice Compare(double comparison) { public static TimingNotice Compare(double seconds, double? pbSeconds = null, double? lrSeconds = null) => lrSeconds switch {
double s = Math.Abs(comparison - Seconds); double lr when seconds < lr => new TimingNotice { Seconds = seconds, Category = NoticeCategory.Fastest },
NoticeCategory cat = comparison switch { _ => pbSeconds switch {
double c when Seconds < c => NoticeCategory.Faster, double pb when seconds < pb => new TimingNotice { Seconds = seconds, Category = NoticeCategory.Faster },
_ => NoticeCategory.Slower, double pb when seconds > pb => new TimingNotice { Seconds = seconds, Category = NoticeCategory.Slower },
}; _ => new TimingNotice { Seconds = seconds, Category = NoticeCategory.Initial },
}
return new TimingNotice { };
Seconds = s,
Category = cat,
};
}
public Label ToLabel() { public Label ToLabel() {
Label l = Category switch { Label l = Category switch {
+24 -17
View File
@@ -134,26 +134,33 @@ public class Timing: MonoBehaviour {
ui.HideRecentLap(); ui.HideRecentLap();
} }
public Lap PB() { public Lap LapRecord => lapService.LapRecord;
if (lapService == null) { public Lap Pb => lapService.Pb;
Debug.LogWarning("null lapservice");
return null; public TimingNotice CompareLap(Lap lap) {
} double? lrSeconds = LapRecord != null ? LapRecord.TotalTime : null;
return lapService.PB; double? pbSeconds = Pb != null ? Pb.TotalTime : null;
return TimingNotice.Compare(lap.TotalTime, pbSeconds, lrSeconds);
} }
public TimingNotice PBSectorDiff(SectorTime s) => PB() switch { public TimingNotice CompareSector(SectorTime s) {
Lap pb => pb.Sectors.SingleOrDefault(fls => fls.Sector == s.Sector) switch { double? lrSeconds = LapRecord switch {
SectorTime fastestSector => (new TimingNotice { Seconds = s.Seconds }).Compare(fastestSector.Seconds), null => null,
null => new TimingNotice { Seconds = s.Seconds }, // this one should never happen Lap lr => lr.Sectors.SingleOrDefault(lrs => lrs.Sector == s.Sector) switch {
}, SectorTime lrSector => lrSector.Seconds,
null => new TimingNotice { Seconds = s.Seconds }, // there is no pb _ => null,
}; },
};
public TimingNotice PBLapDiff(Lap lap) => PB() switch { double? pbSeconds = Pb switch {
Lap pb => (new TimingNotice { Seconds = lap.TotalTime }).Compare(pb.TotalTime), null => null,
null => new TimingNotice { Seconds = lap.TotalTime }, Lap pb => pb.Sectors.SingleOrDefault(pbs => pbs.Sector == s.Sector) switch {
}; SectorTime pbSector => pbSector.Seconds,
_ => null,
},
};
return TimingNotice.Compare(s.Seconds, pbSeconds, lrSeconds);
}
} }
+4 -4
View File
@@ -64,7 +64,7 @@ public class TimingUI : MonoBehaviour {
if (timerSectors == null) if (timerSectors == null)
Debug.LogWarning("null timerSectors"); Debug.LogWarning("null timerSectors");
Lap timerPbLap = timing.PB(); Lap timerPbLap = timing.Pb;
if (timerPbLap != null) if (timerPbLap != null)
timerPb.text = $"{timerPbLap.ToString()}"; timerPb.text = $"{timerPbLap.ToString()}";
@@ -73,7 +73,7 @@ public class TimingUI : MonoBehaviour {
foreach (Sector sector in timing.sectors) { foreach (Sector sector in timing.sectors) {
Label l = timing.sectorTimes Label l = timing.sectorTimes
.Where(s => s.Sector == sector.sector) .Where(s => s.Sector == sector.sector)
.Select(s => timing.PBSectorDiff(s).ToLabel()) .Select(s => timing.CompareSector(s).ToLabel())
.DefaultIfEmpty(new Label("-")) .DefaultIfEmpty(new Label("-"))
.Single(); .Single();
@@ -87,11 +87,11 @@ public class TimingUI : MonoBehaviour {
noticeTime.text = lap.ToString(); noticeTime.text = lap.ToString();
noticeDiff.Clear(); noticeDiff.Clear();
noticeDiff.Add(timing.PBLapDiff(lap).ToLabel()); noticeDiff.Add(timing.CompareLap(lap).ToLabel());
noticeSectors.Clear(); noticeSectors.Clear();
foreach (SectorTime sector in lap.Sectors) { foreach (SectorTime sector in lap.Sectors) {
Label l = timing.PBSectorDiff(sector).ToLabel(); Label l = timing.CompareSector(sector).ToLabel();
noticeSectors.Add(l); noticeSectors.Add(l);
} }
} }
+1 -2
View File
@@ -134,8 +134,7 @@ PlayerSettings:
vulkanEnableCommandBufferRecycling: 1 vulkanEnableCommandBufferRecycling: 1
loadStoreDebugModeEnabled: 0 loadStoreDebugModeEnabled: 0
bundleVersion: 0.1 bundleVersion: 0.1
preloadedAssets: preloadedAssets: []
- {fileID: 11400000, guid: 020903acd8b50dd45a683fb9312ba7af, type: 2}
metroInputSource: 0 metroInputSource: 0
wsaTransparentSwapchain: 0 wsaTransparentSwapchain: 0
m_HolographicPauseOnTrackingLoss: 1 m_HolographicPauseOnTrackingLoss: 1
@@ -13,8 +13,8 @@ using Server;
namespace Server.Migrations namespace Server.Migrations
{ {
[DbContext(typeof(SpaceRaceDbContext))] [DbContext(typeof(SpaceRaceDbContext))]
[Migration("20230829101729_InitSectors")] [Migration("20230831064847_Initialisation")]
partial class InitSectors partial class Initialisation
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -29,7 +29,6 @@ namespace Server.Migrations
modelBuilder.Entity("Server.Lap", b => modelBuilder.Entity("Server.Lap", b =>
{ {
b.Property<Guid>("Id") b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid"); .HasColumnType("uuid");
b.Property<DateTimeOffset>("Created") b.Property<DateTimeOffset>("Created")
@@ -37,7 +36,8 @@ namespace Server.Migrations
b.Property<string>("Map") b.Property<string>("Map")
.IsRequired() .IsRequired()
.HasColumnType("text"); .HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<List<double>>("Sectors") b.Property<List<double>>("Sectors")
.IsRequired() .IsRequired()
@@ -61,8 +61,8 @@ namespace Server.Migrations
b.HasData( b.HasData(
new new
{ {
Id = new Guid("589bfb11-59c1-4f7e-beef-973c301b8e08"), Id = new Guid("be3d3d80-a0c3-4aff-b373-711b6eb2c9f3"),
Created = new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(467), new TimeSpan(0, 0, 0, 0, 0)), Created = new DateTimeOffset(new DateTime(2023, 8, 31, 6, 48, 46, 941, DateTimeKind.Unspecified).AddTicks(8821), new TimeSpan(0, 0, 0, 0, 0)),
Map = "sr_testtrack", Map = "sr_testtrack",
Sectors = new List<double> { 64.0, 24.0, 24.0 }, Sectors = new List<double> { 64.0, 24.0, 24.0 },
Time = 128.0, Time = 128.0,
@@ -70,20 +70,20 @@ namespace Server.Migrations
}, },
new new
{ {
Id = new Guid("67bda0f2-ecf8-4521-ba21-08d252d9ce59"), Id = new Guid("a5f5815a-2ba5-4b9f-8f45-fe41f5b20102"),
Created = new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(723), new TimeSpan(0, 0, 0, 0, 0)), Created = new DateTimeOffset(new DateTime(2023, 8, 31, 6, 48, 46, 941, DateTimeKind.Unspecified).AddTicks(8875), new TimeSpan(0, 0, 0, 0, 0)),
Map = "sr_testtrack", Map = "sr_junglism",
Sectors = new List<double> { 64.0, 38.0, 24.0 }, Sectors = new List<double> { 64.0, 64.0, 128.0 },
Time = 132.0, Time = 256.0,
UserId = new Guid("22222222-2222-2222-2222-222222222222") UserId = new Guid("22222222-2222-2222-2222-222222222222")
}, },
new new
{ {
Id = new Guid("678183de-9df4-4d98-9807-f288b54a7f3a"), Id = new Guid("d2a3e508-8a8e-4959-8103-67c60567e294"),
Created = new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(745), new TimeSpan(0, 0, 0, 0, 0)), Created = new DateTimeOffset(new DateTime(2023, 8, 31, 6, 48, 46, 941, DateTimeKind.Unspecified).AddTicks(8882), new TimeSpan(0, 0, 0, 0, 0)),
Map = "sr_testtrack", Map = "sr_silverstorage",
Sectors = new List<double> { 64.0, 64.0, 24.0 }, Sectors = new List<double> { 64.0, 64.0, 128.0 },
Time = 148.0, Time = 256.0,
UserId = new Guid("33333333-3333-3333-3333-333333333333") UserId = new Guid("33333333-3333-3333-3333-333333333333")
}); });
}); });
@@ -115,8 +115,6 @@ namespace Server.Migrations
.HasColumnType("uuid"); .HasColumnType("uuid");
b.ToTable((string)null); b.ToTable((string)null);
b.ToSqlQuery("WITH ranked AS (\n SELECT *, rank() OVER (ORDER BY \"Time\" ASC) AS \"Position\", COUNT(\"Id\") OVER () AS \"Completions\"\n FROM \"Laps\"\n)\n\nSELECT * FROM ranked");
}); });
#pragma warning restore 612, 618 #pragma warning restore 612, 618
} }
@@ -9,7 +9,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace Server.Migrations namespace Server.Migrations
{ {
/// <inheritdoc /> /// <inheritdoc />
public partial class InitSectors : Migration public partial class Initialisation : Migration
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
@@ -23,7 +23,7 @@ namespace Server.Migrations
Created = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false), Created = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
Time = table.Column<double>(type: "double precision", nullable: false), Time = table.Column<double>(type: "double precision", nullable: false),
Sectors = table.Column<List<double>>(type: "double precision[]", nullable: false), Sectors = table.Column<List<double>>(type: "double precision[]", nullable: false),
Map = table.Column<string>(type: "text", nullable: false) Map = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false)
}, },
constraints: table => constraints: table =>
{ {
@@ -35,9 +35,9 @@ namespace Server.Migrations
columns: new[] { "Id", "Created", "Map", "Sectors", "Time", "UserId" }, columns: new[] { "Id", "Created", "Map", "Sectors", "Time", "UserId" },
values: new object[,] values: new object[,]
{ {
{ new Guid("589bfb11-59c1-4f7e-beef-973c301b8e08"), new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(467), new TimeSpan(0, 0, 0, 0, 0)), "sr_testtrack", new List<double> { 64.0, 24.0, 24.0 }, 128.0, new Guid("11111111-1111-1111-1111-111111111111") }, { new Guid("a5f5815a-2ba5-4b9f-8f45-fe41f5b20102"), new DateTimeOffset(new DateTime(2023, 8, 31, 6, 48, 46, 941, DateTimeKind.Unspecified).AddTicks(8875), new TimeSpan(0, 0, 0, 0, 0)), "sr_junglism", new List<double> { 64.0, 64.0, 128.0 }, 256.0, new Guid("22222222-2222-2222-2222-222222222222") },
{ new Guid("678183de-9df4-4d98-9807-f288b54a7f3a"), new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(745), new TimeSpan(0, 0, 0, 0, 0)), "sr_testtrack", new List<double> { 64.0, 64.0, 24.0 }, 148.0, new Guid("33333333-3333-3333-3333-333333333333") }, { new Guid("be3d3d80-a0c3-4aff-b373-711b6eb2c9f3"), new DateTimeOffset(new DateTime(2023, 8, 31, 6, 48, 46, 941, DateTimeKind.Unspecified).AddTicks(8821), new TimeSpan(0, 0, 0, 0, 0)), "sr_testtrack", new List<double> { 64.0, 24.0, 24.0 }, 128.0, new Guid("11111111-1111-1111-1111-111111111111") },
{ new Guid("67bda0f2-ecf8-4521-ba21-08d252d9ce59"), new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(723), new TimeSpan(0, 0, 0, 0, 0)), "sr_testtrack", new List<double> { 64.0, 38.0, 24.0 }, 132.0, new Guid("22222222-2222-2222-2222-222222222222") } { new Guid("d2a3e508-8a8e-4959-8103-67c60567e294"), new DateTimeOffset(new DateTime(2023, 8, 31, 6, 48, 46, 941, DateTimeKind.Unspecified).AddTicks(8882), new TimeSpan(0, 0, 0, 0, 0)), "sr_silverstorage", new List<double> { 64.0, 64.0, 128.0 }, 256.0, new Guid("33333333-3333-3333-3333-333333333333") }
}); });
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
@@ -26,7 +26,6 @@ namespace Server.Migrations
modelBuilder.Entity("Server.Lap", b => modelBuilder.Entity("Server.Lap", b =>
{ {
b.Property<Guid>("Id") b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid"); .HasColumnType("uuid");
b.Property<DateTimeOffset>("Created") b.Property<DateTimeOffset>("Created")
@@ -34,7 +33,8 @@ namespace Server.Migrations
b.Property<string>("Map") b.Property<string>("Map")
.IsRequired() .IsRequired()
.HasColumnType("text"); .HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<List<double>>("Sectors") b.Property<List<double>>("Sectors")
.IsRequired() .IsRequired()
@@ -58,8 +58,8 @@ namespace Server.Migrations
b.HasData( b.HasData(
new new
{ {
Id = new Guid("589bfb11-59c1-4f7e-beef-973c301b8e08"), Id = new Guid("be3d3d80-a0c3-4aff-b373-711b6eb2c9f3"),
Created = new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(467), new TimeSpan(0, 0, 0, 0, 0)), Created = new DateTimeOffset(new DateTime(2023, 8, 31, 6, 48, 46, 941, DateTimeKind.Unspecified).AddTicks(8821), new TimeSpan(0, 0, 0, 0, 0)),
Map = "sr_testtrack", Map = "sr_testtrack",
Sectors = new List<double> { 64.0, 24.0, 24.0 }, Sectors = new List<double> { 64.0, 24.0, 24.0 },
Time = 128.0, Time = 128.0,
@@ -67,20 +67,20 @@ namespace Server.Migrations
}, },
new new
{ {
Id = new Guid("67bda0f2-ecf8-4521-ba21-08d252d9ce59"), Id = new Guid("a5f5815a-2ba5-4b9f-8f45-fe41f5b20102"),
Created = new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(723), new TimeSpan(0, 0, 0, 0, 0)), Created = new DateTimeOffset(new DateTime(2023, 8, 31, 6, 48, 46, 941, DateTimeKind.Unspecified).AddTicks(8875), new TimeSpan(0, 0, 0, 0, 0)),
Map = "sr_testtrack", Map = "sr_junglism",
Sectors = new List<double> { 64.0, 38.0, 24.0 }, Sectors = new List<double> { 64.0, 64.0, 128.0 },
Time = 132.0, Time = 256.0,
UserId = new Guid("22222222-2222-2222-2222-222222222222") UserId = new Guid("22222222-2222-2222-2222-222222222222")
}, },
new new
{ {
Id = new Guid("678183de-9df4-4d98-9807-f288b54a7f3a"), Id = new Guid("d2a3e508-8a8e-4959-8103-67c60567e294"),
Created = new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(745), new TimeSpan(0, 0, 0, 0, 0)), Created = new DateTimeOffset(new DateTime(2023, 8, 31, 6, 48, 46, 941, DateTimeKind.Unspecified).AddTicks(8882), new TimeSpan(0, 0, 0, 0, 0)),
Map = "sr_testtrack", Map = "sr_silverstorage",
Sectors = new List<double> { 64.0, 64.0, 24.0 }, Sectors = new List<double> { 64.0, 64.0, 128.0 },
Time = 148.0, Time = 256.0,
UserId = new Guid("33333333-3333-3333-3333-333333333333") UserId = new Guid("33333333-3333-3333-3333-333333333333")
}); });
}); });
@@ -112,8 +112,6 @@ namespace Server.Migrations
.HasColumnType("uuid"); .HasColumnType("uuid");
b.ToTable((string)null); b.ToTable((string)null);
b.ToSqlQuery("SELECT *, rank() OVER (ORDER BY \"Time\" ASC) AS \"Position\", COUNT(\"Id\") OVER () AS \"Completions\"\n FROM \"Laps\"\n)\n\n");
}); });
#pragma warning restore 612, 618 #pragma warning restore 612, 618
} }
+10 -7
View File
@@ -31,7 +31,10 @@ public class Lap {
[Required] public DateTimeOffset Created { get; set; } [Required] public DateTimeOffset Created { get; set; }
[Required] public double Time { get; set; } [Required] public double Time { get; set; }
[Required] public List<double> Sectors { get; set; } [Required] public List<double> Sectors { get; set; }
[Required] public string Map { get; set; }
[Required]
[MaxLength(128)]
public string Map { get; set; }
} }
class SpaceRaceInitialiser { class SpaceRaceInitialiser {
@@ -55,17 +58,17 @@ class SpaceRaceInitialiser {
Created = DateTimeOffset.UtcNow, Created = DateTimeOffset.UtcNow,
Id = Guid.NewGuid(), Id = Guid.NewGuid(),
UserId = new Guid("22222222-2222-2222-2222-222222222222"), UserId = new Guid("22222222-2222-2222-2222-222222222222"),
Time = 132f, Time = 256f,
Sectors = new List<double> { 64f, 38f, 24f }, Sectors = new List<double> { 64f, 64f, 128f },
Map = "sr_testtrack", Map = "sr_junglism",
}, },
new Lap { new Lap {
Created = DateTimeOffset.UtcNow, Created = DateTimeOffset.UtcNow,
Id = Guid.NewGuid(), Id = Guid.NewGuid(),
UserId = new Guid("33333333-3333-3333-3333-333333333333"), UserId = new Guid("33333333-3333-3333-3333-333333333333"),
Time = 148f, Time = 256f,
Sectors = new List<double> { 64f, 64f, 24f }, Sectors = new List<double> { 64f, 64f, 128f },
Map = "sr_testtrack", Map = "sr_silverstorage",
} }
); );
} }