Skip to content

Commit

Permalink
Merge pull request #714 from JoshYuen/dump-pokemon-stats
Browse files Browse the repository at this point in the history
Dump pokemon stats to file
  • Loading branch information
NecronomiconCoding authored Jul 28, 2016
2 parents eea5b2a + c27e26d commit f85f02b
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 3 deletions.
69 changes: 69 additions & 0 deletions PoGo.NecroBot.Logic/DataDumper/Dumper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#region using directives

using System;
using System.IO;
using PoGo.NecroBot.Logic;
using PoGo.NecroBot.Logic.State;

#endregion

namespace PoGo.NecroBot.Logic.DataDumper
{
public static class Dumper
{
private static IDumper _dumper;
private static string _subPath;

/// <summary>
/// This is used for dumping contents to a file stored in the Logs folder.
/// </summary>
/// <param name="data">Dumps the string data to the file</param>
/// <param name="filename">Filename to be used for naming the file.</param>
private static void DumpToFile(Session ctx, string data, string filename)
{
string path = Path.Combine(ctx.LogicSettings.ProfilePath,"Dumps",$"NecroBot-{filename}-{DateTime.Today.ToString("yyyy-MM-dd")}-{DateTime.Now.ToString("HH")}.txt");

using (
var dumpFile =
File.AppendText(path)
)
{
dumpFile.WriteLine(data);
dumpFile.Flush();
}
}

/// <summary>
/// Set the dumper.
/// </summary>
/// <param name="dumper"></param>
public static void SetDumper(IDumper dumper, string subPath = "")
{
_dumper = dumper;
_subPath = subPath;
}

/// <summary>
/// Clears the specified dumpfile.
/// </summary>
/// <param name="filename">File to clear/param>
public static void ClearDumpFile(Session ctx, string filename)
{
string path = Path.Combine(ctx.LogicSettings.ProfilePath,"Dumps",$"NecroBot-{filename}-{DateTime.Today.ToString("yyyy-MM-dd")}-{DateTime.Now.ToString("HH")}.txt");
// Clears all contents of a file first if overwrite is true
File.WriteAllText(path, string.Empty);
}

/// <summary>
/// Dumps data to a file
/// </summary>
/// <param name="data">Dumps the string data to the file</param>
/// <param name="filename">Filename to be used for naming the file.</param>
public static void Dump(Session ctx, string data, string filename)
{
string uniqueFileName = $"{filename}";

DumpToFile(ctx, data, uniqueFileName);
}
}
}
18 changes: 18 additions & 0 deletions PoGo.NecroBot.Logic/DataDumper/IDumper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#region using directives

using System;

#endregion

namespace PoGo.NecroBot.Logic.DataDumper
{
public interface IDumper
{
/// <summary>
/// Dump specific data.
/// </summary>
/// <param name="data">The data to dump.</param>
/// <param name="filename">File to dump to</param>
void Dump(string data, string filename);
}
}
1 change: 1 addition & 0 deletions PoGo.NecroBot.Logic/ILogicSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public interface ILogicSettings
int UseLuckyEggsMinPokemonAmount { get; }
bool EvolveAllPokemonAboveIv { get; }
float EvolveAboveIvValue { get; }
bool DumpPokemonStats { get; }
bool RenameAboveIv { get; }
int AmountOfPokemonToDisplayOnStart { get; }
string TranslationLanguageCode { get; }
Expand Down
1 change: 1 addition & 0 deletions PoGo.NecroBot.Logic/Logging/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public static void Write(string message, LogLevel level = LogLevel.Info, Console
_logger.Write(message, level, color);
Log(string.Concat($"[{DateTime.Now.ToString("HH:mm:ss")}] ", message));
}

}

public enum LogLevel
Expand Down
2 changes: 2 additions & 0 deletions PoGo.NecroBot.Logic/PoGo.NecroBot.Logic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="DataDumper\IDumper.cs" />
<Compile Include="DataDumper\Dumper.cs" />
<Compile Include="Common\Translations.cs" />
<Compile Include="Event\DisplayHighestsPokemonEvent.cs" />
<Compile Include="Event\EggHatchedEvent.cs" />
Expand Down
4 changes: 3 additions & 1 deletion PoGo.NecroBot.Logic/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public class GlobalSettings
public float EvolveAboveIvValue = 90;
public bool EvolveAllPokemonAboveIv = true;
public bool EvolveAllPokemonWithEnoughCandy = false;
public bool DumpPokemonStats = false;
public string GpxFile = "GPXPath.GPX";

public List<KeyValuePair<ItemId, int>> ItemRecycleFilter = new List<KeyValuePair<ItemId, int>>
Expand Down Expand Up @@ -363,11 +364,12 @@ public LogicSettings(GlobalSettings settings)
public float EvolveAboveIvValue => _settings.EvolveAboveIvValue;
public bool RenameAboveIv => _settings.RenameAboveIv;
public int AmountOfPokemonToDisplayOnStart => _settings.AmountOfPokemonToDisplayOnStart;
public bool DumpPokemonStats => _settings.DumpPokemonStats;
public string TranslationLanguageCode => _settings.TranslationLanguageCode;
public ICollection<KeyValuePair<ItemId, int>> ItemRecycleFilter => _settings.ItemRecycleFilter;
public ICollection<PokemonId> PokemonsToEvolve => _settings.PokemonsToEvolve;
public ICollection<PokemonId> PokemonsNotToTransfer => _settings.PokemonsNotToTransfer;
public ICollection<PokemonId> PokemonsNotToCatch => _settings.PokemonsToIgnore;
public Dictionary<PokemonId, TransferFilter> PokemonsTransferFilter => _settings.PokemonsTransferFilter;
}
}
}
4 changes: 2 additions & 2 deletions PoGo.NecroBot.Logic/Tasks/DisplayPokemonStatsTask.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region using directives
#region using directives

using System;
using System.Linq;
Expand Down Expand Up @@ -42,4 +42,4 @@ public static async Task Execute(ISession session)
await Task.Delay(500);
}
}
}
}

0 comments on commit f85f02b

Please sign in to comment.