-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a simple ability to export match records (#291)
- Loading branch information
Showing
9 changed files
with
75 additions
and
7 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/Modules/MatchTrackerModule/Controllers/MatchTrackerCommandsController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using EvoSC.Commands.Attributes; | ||
using EvoSC.Commands.Interfaces; | ||
using EvoSC.Common.Controllers; | ||
using EvoSC.Common.Controllers.Attributes; | ||
using EvoSC.Modules.Official.MatchTrackerModule.Interfaces; | ||
|
||
namespace EvoSC.Modules.Official.MatchTrackerModule.Controllers; | ||
|
||
[Controller] | ||
public class MatchTrackerCommandsController(IMatchTrackerExportService exportService) : EvoScController<ICommandInteractionContext> | ||
{ | ||
[ChatCommand("matchtrackerexport", "Export all match tracker data to a csv file.")] | ||
[CommandAlias("/mtexport", true)] | ||
public Task ExportCsvAsync(string file) => exportService.ExportCsv(file); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/Modules/MatchTrackerModule/Interfaces/IMatchTrackerExportService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace EvoSC.Modules.Official.MatchTrackerModule.Interfaces; | ||
|
||
public interface IMatchTrackerExportService | ||
{ | ||
public Task ExportCsv(string file); | ||
} |
2 changes: 2 additions & 0 deletions
2
src/Modules/MatchTrackerModule/Interfaces/ITrackerStoreService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
using EvoSC.Modules.Official.MatchTrackerModule.Interfaces.Models; | ||
using EvoSC.Modules.Official.MatchTrackerModule.Interfaces.Stores; | ||
|
||
namespace EvoSC.Modules.Official.MatchTrackerModule.Interfaces; | ||
|
||
public interface ITrackerStoreService | ||
{ | ||
public Task SaveTimelineAsync(IMatchTimeline timeline); | ||
public Task SaveState(IMatchState state); | ||
public void AddStore(IMatchTrackerStore store); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
using EvoSC.Modules.Attributes; | ||
using EvoSC.Modules.Official.MatchTrackerModule.Interfaces; | ||
using EvoSC.Modules.Official.MatchTrackerModule.Interfaces.Stores; | ||
|
||
namespace EvoSC.Modules.Official.MatchTrackerModule; | ||
|
||
[Module(IsInternal = true)] | ||
public class MatchTrackerModule : EvoScModule | ||
{ | ||
public MatchTrackerModule(IDatabaseMatchTrackerStore dbStore, ITrackerStoreService stores) | ||
{ | ||
stores.AddStore(dbStore); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/Modules/MatchTrackerModule/Services/MatchTrackerExportService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Text; | ||
using EvoSC.Common.Services.Attributes; | ||
using EvoSC.Modules.Official.MatchTrackerModule.Interfaces; | ||
|
||
namespace EvoSC.Modules.Official.MatchTrackerModule.Services; | ||
|
||
[Service] | ||
public class MatchTrackerExportService(IMatchRecordRepository repository) : IMatchTrackerExportService | ||
{ | ||
public async Task ExportCsv(string file) | ||
{ | ||
var records = await repository.GetRecordsAsync(); | ||
var sb = new StringBuilder(); | ||
|
||
sb.AppendLine("Id,Timestamp,TimelineId,Status,Report"); | ||
|
||
foreach (var record in records) | ||
{ | ||
sb.Append(record.Id); | ||
sb.Append(","); | ||
sb.Append(record.Timestamp); | ||
sb.Append(","); | ||
sb.Append(record.TimelineId); | ||
sb.Append(","); | ||
sb.Append(record.Status); | ||
sb.Append(",\""); | ||
sb.Append(EscapeCsvValue(record.Report)); | ||
sb.AppendLine("\""); | ||
} | ||
|
||
await File.WriteAllTextAsync(file, sb.ToString()); | ||
} | ||
|
||
private static string EscapeCsvValue(string value) | ||
{ | ||
return value.Replace("\"", "\"\""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters