Skip to content

Commit a441d52

Browse files
committed
2 parents bd55cea + 5ac342f commit a441d52

45 files changed

Lines changed: 480 additions & 457 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Fixer/BattleBalanceData.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
using System;
1+
using Ratings;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Text;
56
using ZkData;
67

78
namespace Fixer
89
{
10+
/*
11+
* TODO: Replace Elo by AccountRating
912
public class BattleBalanceData
1013
{
14+
1115
public static int MAX_TEAMSIZE = 12;
1216
int battleID;
1317
double t1Avg;
@@ -20,6 +24,7 @@ public class BattleBalanceData
2024
List<string> t2Names;
2125
static string header = GetStringHeader();
2226
27+
2328
public BattleBalanceData(int battleID)
2429
{
2530
ZkDataContext db = new ZkDataContext();
@@ -152,12 +157,7 @@ public static void AnalyseBalance()
152157
int count = 0;
153158
foreach (SpringBattlePlayer player in game.SpringBattlePlayers.Where(x => !x.IsSpectator))
154159
{
155-
if (player.Account.EloWeight < 5)
156-
{
157-
anyInvalidPlayers = true;
158-
break;
159-
}
160-
else count++;
160+
count++;
161161
}
162162
if (!anyInvalidPlayers && count >= 6 && count <= 24) games2.Add(game);
163163
numProcessed++;
@@ -167,5 +167,5 @@ public static void AnalyseBalance()
167167
Console.WriteLine(games2.Count);
168168
BattleBalanceData.PrintBattleData(games2);
169169
}
170-
}
170+
}*/
171171
}

Fixer/PlanetwarsFixer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,10 @@ public static void RandomizePlanetOwners(int galaxyID, double proportionNeutral
170170
List<int> forceNeutral = new List<int>(new int[] { 3930, 3964 });
171171

172172
List<List<Account>> accountsByFaction = new List<List<Account>>();
173+
var minDate = DateTime.UtcNow.AddDays(-15);
173174
foreach (Faction f in factions)
174175
{
175-
accountsByFaction.Add(f.Accounts.Where(x => x.LastLogin > DateTime.UtcNow.AddDays(-15)).OrderByDescending(x => x.EloPw).ToList());
176+
accountsByFaction.Add(f.Accounts.Where(x => x.LastLogin > minDate).OrderByDescending(x => x.AccountRatings.Where(r => r.RatingCategory == Ratings.RatingCategory.Planetwars).Select(y => y.RealElo).DefaultIfEmpty(1500).FirstOrDefault()).ToList());
176177
}
177178
List<Account> alreadyAssigned = new List<Account>();
178179

Fixer/Program.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,9 @@ static void Main(string[] args)
429429
if (Console.ReadLine()?.StartsWith("i read the code") != true) return;
430430

431431

432-
GlobalConst.Mode = ModeType.Live;
433-
434-
RemoveUnusedMaps();
432+
GlobalConst.Mode = ModeType.Local;
433+
434+
//RemoveUnusedMaps();
435435

436436

437437
//PlanetwarsFixer.AddWormholes(28);
@@ -580,7 +580,7 @@ static void GetModuleUsage(int moduleID, List<Commander> comms, ZkDataContext db
580580
System.Console.WriteLine("Total cost: " + numModules * moduleCost);
581581
System.Console.WriteLine();
582582
}
583-
583+
/*
584584
public static void AnalyzeModuleUsagePatterns()
585585
{
586586
var db = new ZkDataContext();
@@ -614,7 +614,7 @@ public static void AnalyzeCommUsagePatterns()
614614
int chassisCount = comms.Count;
615615
System.Console.WriteLine("CHASSIS " + chassis.Name + " : " + chassisCount);
616616
}
617-
}
617+
}*/
618618

619619
public static void ProgressCampaign(ZkDataContext db, Account acc, Mission mission, bool completeNext = false, string missionVars = "")
620620
{
@@ -787,7 +787,7 @@ public static void UpdateMissionProgression(int planetID, bool completeNext = fa
787787
}
788788
}
789789

790-
790+
/*
791791
public static void GetClanStackWinRate(int clanID, int minElo)
792792
{
793793
int won = 0, lost = 0;
@@ -833,7 +833,7 @@ public static void GetAverageElo()
833833
}
834834
double average = eloSum / count;
835835
System.Console.WriteLine(String.Format("Average: {0}, Total players: {1}", average, count));
836-
}
836+
}*/
837837

838838
public static void RenameOldAccounts()
839839
{
@@ -868,6 +868,7 @@ public class EloEntry
868868

869869
}
870870

871+
/*
871872
public static void Test1v1Elo()
872873
{
873874
var db = new ZkDataContext();
@@ -947,8 +948,9 @@ public static void Test1v1Elo()
947948
Console.WriteLine("{0};{1:f0};{2:f0};{3};{4}", entry.Key.Name, entry.Value.Elo, entry.Key.EffectiveElo, entry.Value.Cnt, entry.Key.SpringBattlePlayers.Count(x => !x.IsSpectator && x.SpringBattle.PlayerCount > 2));
948949
}
949950
950-
}
951+
}*/
951952

953+
/*
952954
public static void TestPrediction()
953955
{
954956
var db = new ZkDataContext();
@@ -1024,7 +1026,7 @@ static void ImportSpringiePlayers()
10241026
}
10251027
}
10261028
db.SaveChanges();
1027-
}
1029+
}*/
10281030

10291031
static void FixMaps()
10301032
{

Shared/PlasmaShared/GlobalConst.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ public static BasicHttpBinding CreateBasicHttpBinding()
135135
public const int MinDurationForElo = 60;
136136
public const int MinDurationForPlanetwars = 0;
137137

138-
public const int LadderActivityDays = 70;
138+
public const int LadderActivityDays = 30;
139139
public const int LadderSize = 50; // Amount of players shown on ladders
140-
public const float MinimumDynamicMaxLadderUncertainty = 50; // uncertainties > this are marked unranked, max age ~ 2-3 months
141-
public const float EloDecayPerDaySquared = 30; //whr thingie
140+
public const float MinimumDynamicMaxLadderUncertainty = 100; // uncertainties > this are marked unranked, max age ~ 2-3 months
141+
public const float EloDecayPerDaySquared = 35; //whr thingie
142142
public const float LadderUpdatePeriod = 1; //Ladder is fully updated every X hours
143143

144144
public const int XpForMissionOrBots = 25;

Shared/PlasmaShared/Utils.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public static void ForEach<T>(this IEnumerable<T> enumeration, Action<T> action)
4343
}
4444
}
4545

46+
public static HashSet<T> ToHashSet<T>(this IEnumerable<T> source, IEqualityComparer<T> comparer = null)
47+
{
48+
return new HashSet<T>(source, comparer);
49+
}
50+
4651
public static T Clamp<T>(this T val, T min, T max) where T : IComparable<T>
4752
{
4853
if (val.CompareTo(min) < 0) return min;
@@ -598,12 +603,7 @@ public static void SafeDelete(string path)
598603
}
599604
catch { }
600605
}
601-
602-
public static int GetWinChancePercent(double eloDiff)
603-
{
604-
return (int)Math.Round((1.0 / (1.0 + Math.Pow(10, (eloDiff) / 400.0))) * 100.0);
605-
}
606-
606+
607607

608608
public static string ToHex(this byte[] array)
609609
{

Zero-K.info/AppCode/Global.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ public static void StartApplication(MvcApplication mvcApplication)
129129

130130
GlobalConst.SiteDiskPath = MapPath("~");
131131

132-
LadderCalculator = new LadderCalculator();
133-
LadderCalculator.RecomputeNow();
132+
AwardCalculator = new AwardCalculator();
133+
AwardCalculator.RecomputeNow();
134134

135135
var sitePath = mvcApplication.Server.MapPath("~");
136-
ZkServerRunner = new ServerRunner(sitePath, new PlanetwarsEventCreator(), LadderCalculator);
136+
ZkServerRunner = new ServerRunner(sitePath, new PlanetwarsEventCreator());
137137
Server = ZkServerRunner.ZkLobbyServer;
138138

139139
Trace.TraceInformation("Starting lobby server");
@@ -163,7 +163,7 @@ public static void StartApplication(MvcApplication mvcApplication)
163163

164164
public static SteamDepotGenerator SteamDepotGenerator { get; private set; }
165165

166-
public static LadderCalculator LadderCalculator { get; private set; }
166+
public static AwardCalculator AwardCalculator { get; private set; }
167167

168168
public static ForumPostIndexer ForumPostIndexer { get; private set; }
169169

Zero-K.info/AppCode/LadderCalculator.cs

Lines changed: 12 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,29 @@
1313

1414
namespace ZeroKWeb
1515
{
16-
public class LadderCalculator: ITopPlayerProvider
16+
public class AwardCalculator
1717
{
1818
private const int LadderRefreshMinutes = 30;
1919

20-
private LadderModel ladderModel = new LadderModel();
20+
private AwardModel awardModel = new AwardModel();
2121

2222
private Timer timer;
2323

24-
public LadderCalculator()
24+
public AwardCalculator()
2525
{
26-
timer = new Timer((t) => { ladderModel = ComputeLadder(); }, this, LadderRefreshMinutes * 60 * 1000, LadderRefreshMinutes * 60 * 1000);
26+
timer = new Timer((t) => { awardModel = ComputeLadder(); }, this, LadderRefreshMinutes * 60 * 1000, LadderRefreshMinutes * 60 * 1000);
2727
}
2828

2929
public void RecomputeNow()
3030
{
31-
ladderModel = ComputeLadder();
32-
TopPlayersUpdated?.Invoke(this, this);
31+
awardModel = ComputeLadder();
3332
}
3433

35-
public LadderModel GetLadder()
34+
public AwardModel GetAwards()
3635
{
37-
return ladderModel;
36+
return awardModel;
3837
}
39-
40-
public List<Account> GetTop() => ladderModel?.TopAccounts;
41-
public List<Account> GetTopCasual() => ladderModel?.TopCasual;
42-
public event EventHandler<ITopPlayerProvider> TopPlayersUpdated;
38+
4339

4440

4541
private static List<AwardItem> CalculateAwards(ZkDataContext db)
@@ -108,138 +104,23 @@ private static List<AwardItem> CalculateAwards(ZkDataContext db)
108104
}
109105

110106
object computeLadderLock = new object();
111-
private LadderModel ComputeLadder()
107+
private AwardModel ComputeLadder()
112108
{
113109
lock (computeLadderLock)
114110
{
115111
try
116112
{
117-
if (!RatingSystems.DisableRatingSystems)
118-
{
119-
RatingSystems.BackupToDB();
120-
}
121113

122114
var db = new ZkDataContext();
123115
db.Database.CommandTimeout = 600;
124116

125117
var awardItems = CalculateAwards(db);
126-
127-
var ladderTimeout = DateTime.UtcNow.AddDays(-GlobalConst.LadderActivityDays);
128-
129-
// set unused accounts weight to 1
130-
db.Accounts.Where(x => !x.SpringBattlePlayers.Any(
131-
y => (y.SpringBattle.StartTime > ladderTimeout) && !y.SpringBattle.IsMatchMaker && !y.IsSpectator))
132-
.Update(acc => new Account() { EloWeight = 1 });
133-
134-
db.Accounts.Where(x => !x.SpringBattlePlayers.Any(y => (y.SpringBattle.StartTime > ladderTimeout) && y.SpringBattle.IsMatchMaker && !y.IsSpectator)).Update(acc => new Account() { EloMmWeight = 1 });
135-
136-
db.SaveChanges();
137-
138-
139-
foreach (
140-
var entry in
141-
db.Accounts.Where(x => x.EloWeight > 1)
142-
.Select(
143-
acc =>
144-
new
145-
{
146-
Account = acc,
147-
LastGame =
148-
acc.SpringBattlePlayers.Where(x => !x.IsSpectator && !x.SpringBattle.IsMatchMaker)
149-
.OrderByDescending(x => x.SpringBattleID)
150-
.Select(x =>x.SpringBattle.StartTime).FirstOrDefault()
151-
}))
152-
{
153-
var days = DateTime.UtcNow.Subtract(entry.LastGame).TotalDays;
154-
var decayRatio = ((days-7)/(GlobalConst.LadderActivityDays-7)).Clamp(0,1);
155-
entry.Account.EloWeight = Math.Min(entry.Account.EloWeight,
156-
Math.Max(1, GlobalConst.EloWeightMax - (GlobalConst.EloWeightMax - 1)*decayRatio));
157-
}
158-
159-
db.SaveChanges();
160-
161-
162-
foreach (
163-
var entry in
164-
db.Accounts.Where(x => x.EloMmWeight > 1)
165-
.Select(
166-
acc =>
167-
new
168-
{
169-
Account = acc,
170-
LastGame =
171-
acc.SpringBattlePlayers.Where(x => !x.IsSpectator && x.SpringBattle.IsMatchMaker)
172-
.OrderByDescending(x => x.SpringBattleID)
173-
.Select(x => x.SpringBattle.StartTime).FirstOrDefault()
174-
}))
175-
{
176-
var days = DateTime.UtcNow.Subtract(entry.LastGame).TotalDays;
177-
var decayRatio = ((days - 7) / (GlobalConst.LadderActivityDays - 7)).Clamp(0, 1);
178-
entry.Account.EloMmWeight = Math.Min(entry.Account.EloMmWeight,
179-
Math.Max(1, GlobalConst.EloWeightMax - (GlobalConst.EloWeightMax - 1) * decayRatio));
180-
}
181-
db.SaveChanges();
182-
183-
184-
// recalc competitive ranking
185-
var cnt = 0;
186-
foreach (var a in
187-
db.Accounts.Where(
188-
x =>
189-
x.SpringBattlePlayers.Any(
190-
y => (y.SpringBattle.StartTime > ladderTimeout) && y.SpringBattle.IsMatchMaker && !y.IsSpectator))
191-
.OrderByDescending(x => x.EffectiveMmElo)
192-
.WithTranslations())
193-
{
194-
cnt++;
195-
a.CompetitiveRank = cnt;
196-
}
197-
db.SaveChanges();
198-
199-
cnt = 0;
200-
foreach (var a in
201-
db.Accounts.Where(
202-
x =>
203-
x.SpringBattlePlayers.Any(
204-
y => (y.SpringBattle.StartTime > ladderTimeout) && !y.SpringBattle.IsMatchMaker && !y.IsSpectator))
205-
.OrderByDescending(x => x.EffectiveElo)
206-
.WithTranslations())
207-
{
208-
cnt++;
209-
a.CasualRank = cnt;
210-
}
211-
db.SaveChanges();
212-
213-
var topAccounts =
214-
db.Accounts.Where(
215-
x =>
216-
x.SpringBattlePlayers.Any(
217-
y => (y.SpringBattle.StartTime > ladderTimeout) && y.SpringBattle.IsMatchMaker && !y.IsSpectator))
218-
.Include(x => x.Clan)
219-
.Include(x => x.Faction)
220-
.OrderByDescending(x => x.EffectiveMmElo)
221-
.WithTranslations()
222-
.Take(GlobalConst.LadderSize)
223-
.ToList();
224-
225-
var topCasual =
226-
db.Accounts.Where(
227-
x =>
228-
x.SpringBattlePlayers.Any(
229-
y => (y.SpringBattle.StartTime > ladderTimeout) && !y.SpringBattle.IsMatchMaker && !y.IsSpectator))
230-
.Include(x => x.Clan)
231-
.Include(x => x.Faction)
232-
.OrderByDescending(x => x.EffectiveElo)
233-
.WithTranslations()
234-
.Take(GlobalConst.LadderSize)
235-
.ToList();
236-
237-
return new LadderModel { AwardItems = awardItems, TopAccounts = topAccounts, TopCasual = topCasual };
118+
return new AwardModel { AwardItems = awardItems };
238119
}
239120
catch (Exception ex)
240121
{
241122
Trace.TraceError("Error computing ladder: {0}", ex);
242-
return new LadderModel();
123+
return new AwardModel();
243124
}
244125
}
245126
}
@@ -256,11 +137,9 @@ public class AwardItem
256137
public Account TopScoreHolderM;
257138
}
258139

259-
public class LadderModel
140+
public class AwardModel
260141
{
261142
public List<AwardItem> AwardItems = new List<AwardItem>();
262-
public List<Account> TopAccounts = new List<Account>();
263-
public List<Account> TopCasual = new List<Account>();
264143
}
265144

266145
}

0 commit comments

Comments
 (0)