-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Robert Meyer
committed
Mar 27, 2018
1 parent
abb924c
commit 0f8f461
Showing
7 changed files
with
304 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import pytest | ||
|
||
import pandas as pd | ||
import trufflepig.bchain.getdata as tpgd | ||
import trufflepig.preprocessing as tppp | ||
import trufflepig.bchain.getaccountdata as tpad | ||
from trufflepig.bchain.poster import Poster | ||
import trufflepig.trending0bidbots as tt0b | ||
from trufflepig.testutils.pytest_fixtures import steem | ||
from trufflepig import config | ||
|
||
|
||
@pytest.mark.skipif(config.PASSWORD is None, reason="needs posting key") | ||
def test_create_trending_post(steem): | ||
|
||
current_datetime = pd.datetime.utcnow() | ||
|
||
data_frame = tpgd.scrape_hour_data(steem=steem, | ||
current_datetime=current_datetime, | ||
ncores=32, | ||
offset_hours=8, | ||
hours=1, stop_after=20) | ||
|
||
|
||
min_datetime = data_frame.created.min() | ||
max_datetime = data_frame.created.max() + pd.Timedelta(days=8) | ||
upvote_payments = tpad.get_upvote_payments_to_bots(steem=steem, | ||
min_datetime=min_datetime, | ||
max_datetime=max_datetime, | ||
bots=['booster']) | ||
|
||
data_frame = df = tppp.preprocess(data_frame, ncores=1) | ||
|
||
data_frame = tppp.compute_bidbot_correction(post_frame=data_frame, | ||
upvote_payments=upvote_payments) | ||
account = config.ACCOUNT | ||
poster = Poster(account=account, steem=steem) | ||
|
||
tt0b.create_trending_post(data_frame, upvote_payments, poster, 'test', | ||
'test', current_datetime) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from steem.amount import Amount | ||
import trufflepig.bchain.postdata as tbpd | ||
import logging | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
|
||
def compute_total_sbd(upvote_payments): | ||
sbd = 0 | ||
steem = 0 | ||
for (author, permalink), payments in upvote_payments.items(): | ||
for payment in payments.values(): | ||
amount = Amount(payment['amount']) | ||
value = amount.amount | ||
asset = amount.asset | ||
if asset == 'SBD': | ||
sbd += value | ||
elif asset == 'STEEM': | ||
steem += value | ||
return sbd, steem | ||
|
||
|
||
def create_trending_post(post_frame, upvote_payments, poster, topN_permalink, | ||
overview_permalink, current_datetime): | ||
total_paid_sbd, total_paid_steem = compute_total_sbd(upvote_payments) | ||
|
||
logger.info('People spend {} SBD and {} Steem on Bid Bots the last 24 ' | ||
'hours.'.format(total_paid_sbd, total_paid_steem)) | ||
|
||
no_bid_bots_frame = post_frame.loc[post_frame.bought_votes == 0, :].copy() | ||
no_bid_bots_frame.sort_values('reward', inplace=True, ascending=False) | ||
|
||
logger.info('Voted Posts {} out of {}'.format(len(post_frame) - len(no_bid_bots_frame), | ||
len(post_frame))) | ||
|
||
tbpd.post_top_trending_list(no_bid_bots_frame, poster, current_datetime, | ||
overview_permalink=overview_permalink, | ||
trufflepicks_permalink=topN_permalink, | ||
steem_amount=total_paid_steem, | ||
sbd_amount=total_paid_sbd) | ||
|