async def get(self): code = self.get_arg('code') records = FundHistoryNetWorth.query.find( {'code': code, 'is_delete': FundHistoryNetWorth.DELETE_NO}).sort([('date', 1)]) data = dict() labels, series = list(), list() async for record in records: if not labels: data['fund_name'] = record['fund_name'] data['fund_name'] = record['fund_name'] series.append(round(int(record['net_worth']) / 1000, 4)) labels.append(dt.dt_to_str(record['date'], '%m-%d')) data = {'labels': labels, 'series': series} return self.write_success(data)
async def get(self): code = self.get_arg('code') records = FundHistoryNetWorth.query.find({ 'code': code, 'is_delete': FundHistoryNetWorth.DELETE_NO }) data = list() async for record in records: data.append({ 'code': record['code'], 'fund_name': record['fund_name'], 'net_worth': record['net_worth'], 'date': dt.dt_to_str(record['date'], '%Y-%m-%d'), 'daily_growth_rate': record['daily_growth_rate'] }) return self.write_success(data)
def dt_to_str(self, datetime, format="%Y-%m-%d %H:%M:%S"): return dt.dt_to_str(datetime, format)
def datetime_to_str(self, datetime): return dt.dt_to_str(datetime)
def date_to_str(self, datetime): return dt.dt_to_str(datetime, "%Y-%m-%d")