async def view_pool_report(self, query: CallbackQuery): _, pool = query.data.split(':') address = self.data[self.KEY_ACTIVE_ADDRESS] # POST A LOADING STICKER sticker = await query.message.answer_sticker(LOADING_STICKER, disable_notification=True) # WORK... lpf = LiqPoolFetcher(self.deps) liq = await lpf.fetch_one_pool_liquidity_info(address, pool) ppf = PoolPriceFetcher(self.deps) stake_report = await lpf.fetch_stake_report_for_pool(liq, ppf) value_hidden = not self.data.get(self.KEY_CAN_VIEW_VALUE, True) picture = await lp_pool_picture(stake_report, self.loc, value_hidden=value_hidden) picture_io = img_to_bio(picture, f'Thorchain_LP_{pool}.png') # ANSWER await self.show_my_pools(query, edit=False) await query.message.answer_photo(picture_io, # caption=self.loc.TEXT_LP_IMG_CAPTION, disable_notification=True) # CLEAN UP await asyncio.gather(query.message.delete(), sticker.delete())
async def view_address_summary(self, query: CallbackQuery): address = self.data[self.KEY_ACTIVE_ADDRESS] # POST A LOADING STICKER sticker = await query.message.answer_sticker(LOADING_STICKER, disable_notification=True) # WORK ppf = PoolPriceFetcher(self.deps) lpf = LiqPoolFetcher(self.deps) my_pools = self.data[self.KEY_MY_POOLS] liqs = await lpf.fetch_all_pool_liquidity_info(address, my_pools) pools = list(liqs.keys()) liqs = list(liqs.values()) weekly_charts = await lpf.fetch_all_pools_weekly_charts(address, pools) stake_reports = await asyncio.gather(*[lpf.fetch_stake_report_for_pool(liq, ppf) for liq in liqs]) value_hidden = not self.data.get(self.KEY_CAN_VIEW_VALUE, True) picture = await lp_address_summary_picture(stake_reports, weekly_charts, self.loc, value_hidden=value_hidden) picture_io = img_to_bio(picture, 'Thorchain_LP_Summary.png') # ANSWER await self.show_my_pools(query, edit=False) await query.message.answer_photo(picture_io, disable_notification=True) # CLEAN UP await asyncio.gather(query.message.delete(), sticker.delete())
def queue_graph_sync(points, loc: BaseLocalization): df = series_to_pandas(points, shift_time=False) df["t"] = pd.to_datetime(df["t"], unit='s') df = df.resample(RESAMPLE_TIME, on='t').sum() gr = PlotBarGraph() gr.plot_bars(df, 'outbound_queue', gr.PLOT_COLOR) gr.plot_bars(df, 'swap_queue', gr.PLOT_COLOR_2) gr.update_bounds_y() gr.max_y = max(gr.max_y, 20) gr.add_title(loc.TEXT_QUEUE_PLOT_TITLE) return img_to_bio(gr.finalize(), 'kylin_queue.png')
async def price_graph_from_db(db: DB, loc: BaseLocalization, period=DAY): series = PriceTimeSeries(RUNE_SYMBOL, db) det_series = PriceTimeSeries(RUNE_SYMBOL_DET, db) prices = await series.get_last_values(period, with_ts=True) det_prices = await det_series.get_last_values(period, with_ts=True) time_scale_mode = 'time' if period <= DAY else 'date' img = await price_graph(prices, det_prices, loc, time_scale_mode=time_scale_mode) return img_to_bio(img, 'price.jpg')
async def handle_avatar_picture(self, message: Message, loc: BaseLocalization, explicit_picture: PhotoSize = None): async with AsyncExitStack() as stack: stack.enter_async_context(self._work_lock) # POST A LOADING STICKER sticker = await message.answer_sticker( LOADING_STICKER, disable_notification=True, reply_markup=ReplyKeyboardRemove()) # CLEAN UP IN THE END stack.push_async_callback(sticker.delete) if explicit_picture is not None: user_pic = await download_tg_photo(explicit_picture) else: user_pic = await get_userpic(message.from_user) if user_pic is None: await message.reply(loc.TEXT_AVA_ERR_NO_PIC, reply_markup=self.menu_kbd()) return w, h = user_pic.size if w != h: await message.reply(loc.TEXT_AVA_ERR_SQUARE, reply_markup=self.menu_kbd()) return if not w or not h: await message.reply(loc.TEXT_AVA_ERR_INVALID, reply_markup=self.menu_kbd()) return pic = await combine_frame_and_photo(user_pic) pic = img_to_bio(pic, name='thor_ava.png') await message.reply_document(pic, caption=loc.TEXT_AVA_READY, reply_markup=self.menu_kbd())