Skip to content
This repository has been archived by the owner on Oct 28, 2019. It is now read-only.

Commit

Permalink
ADD: ability to sort games by avg. card value
Browse files Browse the repository at this point in the history
This is the last feature to be added from the python version that didn't
make it in the C# conversion.  This implementation should be
significantly faster than the previous method thanks to a newly
developed API that batches these requests together.
  • Loading branch information
jshackles committed Feb 9, 2015
1 parent 79fc5c1 commit f139637
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 7 deletions.
3 changes: 3 additions & 0 deletions Source/IdleMaster/IdleMaster.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
<Reference Include="Microsoft.mshtml, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Steamworks.NET, Version=5.0.0.0, Culture=neutral, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Steamworks.NET\Steamworks.NET.dll</HintPath>
Expand Down
40 changes: 40 additions & 0 deletions Source/IdleMaster/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

using HtmlAgilityPack;
using Steamworks;
using Newtonsoft.Json;

namespace IdleMaster
{
Expand Down Expand Up @@ -71,6 +72,7 @@ private void CopyResource(string resourceName, string file)

public void SortBadges(String method)
{
lblDrops.Text = "Sorting results based on your settings, please wait...";
Dictionary<string, string> tempBadgesLeft = new Dictionary<string, string>();
switch (method)
{
Expand All @@ -93,6 +95,44 @@ orderby pair.Value ascending
{
tempBadgesLeft.Add(pair.Key, pair.Value);
}
break;
case "mostvalue":
// Compile the list of appids that need to be idled
string appids = "";
foreach (KeyValuePair<string, string> pair in badgesLeft)
{
appids += pair.Key + ",";
}
appids = appids.Remove(appids.Length-1);

// Query the API to retrieve the average card values of each appid
WebRequest request = WebRequest.Create("http://api.enhancedsteam.com/market_data/average_card_prices/im.php?appids=" + appids);
WebResponse response = request.GetResponse();
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream, Encoding.UTF8);
string json = reader.ReadToEnd();
reader.Close();
response.Close();

// Parse the response and sort it appropriately
DataSet dataSet = JsonConvert.DeserializeObject<DataSet>(json);
DataTable dataTable = dataSet.Tables["avg_values"];
DataView dataView = dataTable.DefaultView;
dataView.Sort = "avg_price desc";
DataTable sorted = dataView.ToTable();

foreach (DataRow row in sorted.Rows)
{
if (row["avg_price"].ToString() != "")
{
string DropsLeft = "";
if (badgesLeft.TryGetValue(row["appid"].ToString(), out DropsLeft))
{
tempBadgesLeft.Add(row["appid"].ToString(), DropsLeft);
}
}
}

break;
default:
return;
Expand Down
28 changes: 21 additions & 7 deletions Source/IdleMaster/frmSettings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Source/IdleMaster/frmSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ private void btnOK_Click(object sender, EventArgs e)
{
Properties.Settings.Default.sort = "mostcards";
}
if (radIdleMostValue.Checked == true)
{
Properties.Settings.Default.sort = "mostvalue";
}

if (chkMinToTray.Checked == true)
{
Expand All @@ -60,6 +64,9 @@ private void frmSettings_Load(object sender, EventArgs e)
case "mostcards":
radIdleMostDrops.Checked = true;
break;
case "mostvalue":
radIdleMostValue.Checked = true;
break;
default:
break;
}
Expand Down
1 change: 1 addition & 0 deletions Source/IdleMaster/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="HtmlAgilityPack" version="1.4.9" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
</packages>

0 comments on commit f139637

Please sign in to comment.