示例#1
0
def distribute_sjcx(conn, cursor, payment_date):
    """Distributes the sjcx among the farmers and calculates the value
    of the sjcx rewards in dollars.

    Args:
        conn: sqlite3 connection
        cursor: conn's cursor
        payment_date: date when farmer's rewards are calculated
    """
    cursor.execute("SELECT sum(points) FROM rewards WHERE payment_date = ?", (str(payment_date),))
    data = cursor.fetchone()
    total_points = data[0]

    cursor.execute("UPDATE rewards SET sjcx_reward = ? * points / ?", (SJCX_TOTAL_REWARDS, total_points))
    btc_sjcx_rate = exchange_rates.btc_sjcx_rate(payment_date)
    btc_usd_rate = exchange_rates.btc_usd_rate(payment_date)
    cursor.execute("UPDATE rewards SET usd_reward = sjcx_reward * ? * ?", (btc_sjcx_rate, btc_usd_rate))
    conn.commit()
 def test_btc_sjcx(self):
     date = dt.datetime.now() - timedelta(seconds = 86400)
     btc_sjcx = exchange_rate.btc_sjcx_rate(date)
     self.assertTrue(isinstance(btc_sjcx, float))