Skip to content

Commit

Permalink
BMF Incentives
Browse files Browse the repository at this point in the history
  • Loading branch information
thesemaphoreslim authored Feb 24, 2019
1 parent 6e3092f commit 3ed4840
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 33 deletions.
113 changes: 89 additions & 24 deletions Traffic_Award/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,15 @@ class Program
static string getpoolwallets = configuration["getpoolwallets"];
static string geteligibility = configuration["geteligibility"];
static string getexchangetrans = configuration["getexchangetrans"];
static string getexchangetransamt = configuration["getexchangetransamt"];
public static string getrecipients = configuration["getrecipients"];
static string checkfortable = configuration["checkfortable"];
static string createexchangetable = configuration["createexchangetable"];
static string createtranstable = configuration["createtranstable"];
static string createsummarytable = configuration["createsummarytable"];
static string getsummarytable = configuration["getsummarydata"];
static string getnewbmfmembers = configuration["getnewbmfmembers"];
static string getbmfdonations = configuration["getbmfdonations"];
public static string summarytableupsert = configuration["summarytableupsert"];
public static double startdayinterval = double.Parse(configuration["startdayinterval"]);
public static double enddayinterval = double.Parse(configuration["enddayinterval"]);
Expand Down Expand Up @@ -119,13 +122,15 @@ class Program
public static List<string> exchangewallets = new List<string>{ poloid, bittid, liveid };
public static int transactionaward = int.Parse(configuration["transactionaward"]);
public static int exchangeaward = int.Parse(configuration["exchangeaward"]);
public static int bmfaward = int.Parse(configuration["bmfaward"]);
public static List<Summary> summary = new List<Summary>();
static List<string> examt = new List<string>();
static string displaystr = null;
#endregion


#region Calculating timestamp
public static DateTime burstepoch = new DateTime(2014, 08, 11, 2, 0, 0);
public static DateTime burstepoch = new DateTime(2014, 08, 11, 2, 0, 0, DateTimeKind.Utc);
public static DateTime startdate = DateTime.Now.AddDays(startdayinterval);
public static DateTime enddate = DateTime.Now.AddDays(enddayinterval);
public static string startdatetime = configuration["startdatetime"];
Expand Down Expand Up @@ -158,42 +163,44 @@ static void RunSetup()
Console.WriteLine("Press any key to continue");
Console.ReadKey(true);
}
//Console.WriteLine(Environment.NewLine + Environment.NewLine + "Running initial setup...this may take a moment." + Environment.NewLine + Environment.NewLine);


#region Check for schema
queryParameters.Add("@table_name", "exchange_wallets");
queryParameters.Add("@db_name", db_name);
if (string.IsNullOrEmpty(Utilities.GetWinnerData(checkfortable, queryParameters, true)))
{
Utilities.TestDBUpdate(createexchangetable, queryParameters, true);
Utilities.DBUpdate(createexchangetable, queryParameters, true);
}
queryParameters.Add("@table_name", "all_weekly_trans");
queryParameters.Add("@db_name", db_name);
if (string.IsNullOrEmpty(Utilities.GetWinnerData(checkfortable, queryParameters, true)))
{
Utilities.TestDBUpdate(createtranstable, queryParameters, true);
Utilities.DBUpdate(createtranstable, queryParameters, true);
}
queryParameters.Add("@table_name", "raffle_summary");
queryParameters.Add("@db_name", db_name);
if (string.IsNullOrEmpty(Utilities.GetWinnerData(checkfortable, queryParameters, true)))
{
Utilities.TestDBUpdate(createsummarytable, queryParameters, true);
Utilities.DBUpdate(createsummarytable, queryParameters, true);
}
#endregion


#region Clearing testdb tables
Utilities.TestDBUpdate("TRUNCATE TABLE exchange_wallets;", queryParameters, true);
Utilities.TestDBUpdate("TRUNCATE TABLE all_weekly_trans;", queryParameters, true);
Utilities.TestDBUpdate("TRUNCATE TABLE raffle_summary;", queryParameters, true);
Utilities.DBUpdate("TRUNCATE TABLE exchange_wallets;", queryParameters, true);
Utilities.DBUpdate("TRUNCATE TABLE all_weekly_trans;", queryParameters, true);
Utilities.DBUpdate("TRUNCATE TABLE raffle_summary;", queryParameters, true);
#endregion


#region Capturing exchange wallets
//Console.WriteLine("Adding except for exchange wallets.");
queryParameters.Add("@poloid", poloid);
queryParameters.Add("@bittid", bittid);
queryParameters.Add("@brsid", brsid);
queryParameters.Add("@mortid", mortid);
queryParameters.Add("@liveid", liveid);
Utilities.TestDBUpdate(allexchangewallets, queryParameters, false);
Utilities.DBUpdate(allexchangewallets, queryParameters, false);
#endregion


Expand All @@ -203,7 +210,6 @@ static void RunSetup()
queryParameters.Add("@burstamount", burstamount);
queryParameters.Add("@feeamount", feeamount);
queryParameters.Add("@minfeeamount", minfeeamount);
//Console.WriteLine("Querying Burst blockchain for all transactions over " + burstamount + " planck between " + starttimestamp + " and " + endtimestamp + Environment.NewLine);
using (DataTable dt = Utilities.DataTableQuery(getalltransactions, queryParameters, true))
{
sb.Append("INSERT INTO all_weekly_trans (amount, fee, recipient_id, sender_id, timestamp, trans_id) VALUES ");
Expand All @@ -214,7 +220,7 @@ static void RunSetup()
sb.Append(string.Join(",", alltrans)).Append(";");
if (alltrans.Count > 0)
{
Utilities.TestDBUpdate(sb.ToString(), queryParameters, true);
Utilities.DBUpdate(sb.ToString(), queryParameters, true);
}
else
{
Expand Down Expand Up @@ -286,15 +292,17 @@ static async Task RunAsync()
}
} while (string.IsNullOrEmpty(mySelection));
RunSetup();
rafflemembers.Clear();
#endregion


Console.WriteLine("If you hang here, there may be a problem with your database connection.");
Console.WriteLine("Close any open connections or restart the application.");


#region Collect Pool wallets
if (removePoolAddresses)
{
//Console.WriteLine("Collecting pool wallets..." + Environment.NewLine);
using (DataTable dt = Utilities.DataTableQuery(getpoolwallets, queryParameters, true))
{
foreach (DataRow row in dt.Rows)
Expand All @@ -308,9 +316,48 @@ static async Task RunAsync()
#endregion


#region Capturing qualifying BMF donations
queryParameters.Add("@starttime", starttimestamp);
queryParameters.Add("@endtime", endtimestamp);
queryParameters.Add("@bmfid", bmfid);
queryParameters.Add("@bmfaward", bmfaward);
queryParameters.Add("@burstamount", burstamount);
queryParameters.Add("@bmfpid", bmfpid);
queryParameters.Add("@devid", devid);
Utilities.DBUpdate(getbmfdonations, queryParameters, true);
using (DataTable dt = Utilities.DataTableQuery("SELECT * from raffle_summary where bmf_entries>0;", queryParameters, true))
{
foreach (DataRow row in dt.Rows)
{
for (int i = 0; i < bmfaward; i++)
{
rafflemembers.Add(row[0].ToString());
}
}
}
#endregion


#region Capturing qualifying BMF pool members
//queryParameters.Add("@starttime", starttimestamp);
//queryParameters.Add("@endtime", endtimestamp);
//queryParameters.Add("@bmfpid", bmfpid);
//queryParameters.Add("@bmfaward", bmfaward);
//Utilities.DBUpdate(getnewbmfmembers, queryParameters, true);
//using (DataTable dt = Utilities.DataTableQuery("SELECT * FROM raffle_summary WHERE bmf_entries>0;", queryParameters, true))
//{
// foreach (DataRow row in dt.Rows)
// {
// for (int i = 0; i < bmfaward; i++)
// {
// rafflemembers.Add(row[0].ToString());
// }
// }
//}
#endregion


#region Capturing qualifying transactions
rafflemembers.Clear();
//Console.WriteLine("Querying blockchain to find qualifying transactions for the raffle" + Environment.NewLine);
excheck.Clear();
queryParameters.Add("@poloid", poloid);
queryParameters.Add("@bittid", bittid);
Expand All @@ -333,7 +380,6 @@ static async Task RunAsync()


#region Capture qualifying exchange purchases
//Console.WriteLine("Querying blockchain to find qualifying exchange purchases" + Environment.NewLine);
excheck.Clear();
queryParameters.Add("@starttime", starttimestamp);
queryParameters.Add("@endtime", endtimestamp);
Expand All @@ -342,11 +388,28 @@ static async Task RunAsync()
queryParameters.Add("@bittid", bittid);
queryParameters.Add("@devid", devid);
queryParameters.Add("@liveid", liveid);
using (DataTable dt = Utilities.DataTableQuery(getexchangetransamt, queryParameters, true))
{
foreach (DataRow row in dt.Rows)
{
examt.Add(row[0].ToString());
}
}
queryParameters.Add("@starttime", starttimestamp);
queryParameters.Add("@endtime", endtimestamp);
queryParameters.Add("@exchangemin", exchangemin);
queryParameters.Add("@poloid", poloid);
queryParameters.Add("@bittid", bittid);
queryParameters.Add("@devid", devid);
queryParameters.Add("@liveid", liveid);
using (DataTable dt = Utilities.DataTableQuery(getexchangetrans, queryParameters, true))
{
foreach (DataRow row in dt.Rows)
{
excheck.Add(new ExCheck { recipientid = row[0].ToString(), penalize = false, penalid = -1 });
if (examt.Contains(row[0].ToString()))
{
excheck.Add(new ExCheck { recipientid = row[0].ToString(), penalize = false, penalid = -1 });
}
}
}
Console.WriteLine("Checking all " + excheck.Count + " exchange purchases for sell activity. This may take a moment." + Environment.NewLine);
Expand Down Expand Up @@ -380,7 +443,7 @@ static async Task RunAsync()
{
queryParameters.Add("@wallet_address", address.Value);
queryParameters.Add("@wallet_id", address.Key);
Utilities.TestDBUpdate("UPDATE raffle_summary SET wallet_address=@wallet_address WHERE wallet_id=@wallet_id;", Program.queryParameters, true);
Utilities.DBUpdate("UPDATE raffle_summary SET wallet_address=@wallet_address WHERE wallet_id=@wallet_id;", Program.queryParameters, true);
do
{
index = rafflemembers.IndexOf(address.Key);
Expand Down Expand Up @@ -415,7 +478,7 @@ static async Task RunAsync()
{
queryParameters.Add("@wallet_address", address.Value);
queryParameters.Add("@wallet_id", address.Key);
Utilities.TestDBUpdate("UPDATE raffle_summary SET wallet_address=@wallet_address WHERE wallet_id=@wallet_id;", Program.queryParameters, true);
Utilities.DBUpdate("UPDATE raffle_summary SET wallet_address=@wallet_address WHERE wallet_id=@wallet_id;", Program.queryParameters, true);
}
int reducecount = -1;
var distinctlist = from item in rafflemembers group item by item into grp select new { member = grp.Key, count = grp.Count() };
Expand Down Expand Up @@ -449,20 +512,22 @@ static async Task RunAsync()
queryParameters.Add("@total_entries", member.count);
}
queryParameters.Add("@wallet_address", member.member);
Utilities.TestDBUpdate("UPDATE raffle_summary SET total_entries=@total_entries WHERE wallet_address=@wallet_address;", Program.queryParameters, true);
Utilities.DBUpdate("UPDATE raffle_summary SET total_entries=@total_entries WHERE wallet_address=@wallet_address;", Program.queryParameters, true);
}
if (reducecount >= 0)
{
Console.WriteLine(Environment.NewLine + "There are now a total of " + rafflemembers.Count + " raffle entries." + Environment.NewLine);
}
sb.Clear();
//distinctlist = from item in rafflemembers group item by item into grp select new { member = grp.Key, count = grp.Count() };
using (DataTable dt = Utilities.DataTableQuery("SELECT wallet_address, total_entries, exchange_entries, trans_entries, reductions FROM raffle_summary order by total_entries desc;", queryParameters, true))
using (DataTable dt = Utilities.DataTableQuery("SELECT wallet_address, total_entries, bmf_entries, exchange_entries, trans_entries, reductions FROM raffle_summary order by total_entries desc;", queryParameters, true))
//using (DataTable dt = Utilities.DataTableQuery("SELECT wallet_address, total_entries, exchange_entries, trans_entries, reductions FROM raffle_summary order by total_entries desc, wallet_address;", queryParameters, true))
{
sb.Append("Burst Address,Total Entries,Exchange Entries,Transaction Entries,Reductions").Append(Environment.NewLine);
sb.Append("Burst Address,Total Entries,BMF Entries,Exchange Entries,Transaction Entries,Reductions").Append(Environment.NewLine);
//sb.Append("Burst Address,Total Entries,Exchange Entries,Transaction Entries,Reductions").Append(Environment.NewLine);
foreach (DataRow row in dt.Rows)
{
sb.Append(row[0].ToString()).Append(",").Append(row[1].ToString()).Append(",").Append(row[2].ToString()).Append(",").Append(row[3].ToString()).Append(",").Append(row[4].ToString()).Append(Environment.NewLine);
sb.Append(row[0].ToString()).Append(",").Append(row[1].ToString()).Append(",").Append(row[2].ToString()).Append(",").Append(row[3].ToString()).Append(",").Append(row[4].ToString()).Append(",").Append(row[5].ToString()).Append(Environment.NewLine);
//sb.Append(row[0].ToString()).Append(",").Append(row[1].ToString()).Append(",").Append(row[2].ToString()).Append(",").Append(row[3].ToString()).Append(",").Append(row[4].ToString()).Append(Environment.NewLine);
}
}
try
Expand Down
4 changes: 2 additions & 2 deletions Traffic_Award/Utilitiescs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public static void AddRaffleEntries(int reward)
Program.queryParameters.Add("@trans_entries", reward);
}
Program.queryParameters.Add("@reductions", reductions);
TestDBUpdate(Program.summarytableupsert, Program.queryParameters, true);
DBUpdate(Program.summarytableupsert, Program.queryParameters, true);
for (int i = 0; i < loopcount; i++)
{
Program.rafflemembers.Add(recipient.recipientid);
Expand All @@ -160,7 +160,7 @@ public static void AddRaffleEntries(int reward)

}

public static void TestDBUpdate(string query, Dictionary<string, object> parameters, bool showerrors)
public static void DBUpdate(string query, Dictionary<string, object> parameters, bool showerrors)
{
try
{
Expand Down
Loading

0 comments on commit 3ed4840

Please sign in to comment.