-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from AffectedArc07/para-stuff
- Loading branch information
Showing
15 changed files
with
324 additions
and
52 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using CentCom.Common.Models; | ||
using CentCom.Common.Models.Byond; | ||
using CentCom.Common.Models.Rest; | ||
|
||
namespace CentCom.Exporter.Data.Ban; | ||
public class ParadiseExportedBan : ExportedBan { | ||
public new BanType BanType => ((InternalBanType.Equals("PERMABAN") || InternalBanType.Equals("TEMPBAN")) ? BanType.Server : BanType.Job); | ||
|
||
/// <summary> | ||
/// The internal type for this ban. | ||
/// </summary> | ||
public string InternalBanType { get; set; } | ||
|
||
// If you dont override this, stuff breaks | ||
public static implicit operator RestBan(ParadiseExportedBan ban) => new RestBan | ||
( | ||
ban.Id, | ||
ban.BanType, | ||
ban.CKey, | ||
ban.BannedAt, | ||
ban.BannedBy, | ||
ban.Reason, | ||
ban.Expiration, | ||
ban.UnbannedBy, | ||
ban.BanType == BanType.Job ? new[] { new RestJobBan(ban.Role) } : null, | ||
ban.RoundId | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
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,19 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using CentCom.Common.Abstract; | ||
using CentCom.Common.Models; | ||
using CentCom.Common.Models.Rest; | ||
|
||
namespace CentCom.Exporter.Data.Clustering; | ||
|
||
/// <summary> | ||
/// Provides utilities for clustering bans such that job bans are correctly grouped into one ban | ||
/// </summary> | ||
public interface IBanClusterer { | ||
/// <summary> | ||
/// Clusters a collection of IRestBans to ensure that all job bans are grouped appropriately | ||
/// </summary> | ||
/// <param name="bans">The bans to cluster</param> | ||
/// <returns>The collection of bans with all job bans clustered appropriately</returns> | ||
public IEnumerable<IRestBan> ClusterBans(IEnumerable<IRestBan> bans); | ||
} |
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,30 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using CentCom.Common.Abstract; | ||
using CentCom.Common.Models; | ||
using CentCom.Common.Models.Rest; | ||
|
||
namespace CentCom.Exporter.Data.Clustering; | ||
|
||
public class ParadiseBanClusterer : IBanClusterer { | ||
/// <inheritdoc/> | ||
/// <remarks> | ||
/// Job bans are considered to be in a group if the ckey, banning ckey, reason, | ||
/// expiration timestamp, and unbanned ckey are the same. | ||
/// </remarks> | ||
public IEnumerable<IRestBan> ClusterBans(IEnumerable<IRestBan> bans) { | ||
var clusteredBans = bans.Where(x => x.BanType == BanType.Server).ToList(); | ||
clusteredBans.AddRange(bans.Where(x => x.BanType == BanType.Job).GroupBy(x => | ||
new { x.CKey, x.BannedBy, x.Reason, x.UnbannedBy, x.RoundId }).Select(group => { | ||
var ban = group.Last(); | ||
return new RestBan(ban.Id, ban.BanType, ban.CKey, ban.BannedOn, ban.BannedBy, ban.Reason, ban.Expires, | ||
ban.UnbannedBy, | ||
group.SelectMany(j => j.JobBans) | ||
.Select(j => j.Job) | ||
.Distinct() | ||
.Select(j => (IRestJobBan)new RestJobBan(j)).ToList(), | ||
ban.RoundId); | ||
})); | ||
return clusteredBans.OrderByDescending(x => x.Id); | ||
} | ||
} |
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,29 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using CentCom.Common.Abstract; | ||
using CentCom.Common.Models; | ||
using CentCom.Common.Models.Rest; | ||
|
||
namespace CentCom.Exporter.Data.Clustering; | ||
|
||
public class TgBanClusterer : IBanClusterer { | ||
/// <inheritdoc/> | ||
/// <remarks> | ||
/// Job bans are considered to be in a group if the ckey, banning ckey, reason, | ||
/// banned timestamp, expiration timestamp, and unbanned ckey are the same. | ||
/// </remarks> | ||
public IEnumerable<IRestBan> ClusterBans(IEnumerable<IRestBan> bans) { | ||
var clusteredBans = bans.Where(x => x.BanType == BanType.Server).ToList(); | ||
clusteredBans.AddRange(bans.Where(x => x.BanType == BanType.Job).GroupBy(x => | ||
new { x.CKey, x.BannedBy, x.Reason, x.BannedOn, x.Expires, x.UnbannedBy }).Select(group => { | ||
var ban = group.Last(); | ||
return new RestBan(ban.Id, ban.BanType, ban.CKey, ban.BannedOn, ban.BannedBy, ban.Reason, ban.Expires, | ||
ban.UnbannedBy, | ||
group.SelectMany(j => j.JobBans) | ||
.Select(j => j.Job) | ||
.Distinct() | ||
.Select(j => (IRestJobBan)new RestJobBan(j)).ToList(), null); | ||
})); | ||
return clusteredBans.OrderByDescending(x => x.Id); | ||
} | ||
} |
Oops, something went wrong.