Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
PyFund
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈涛
PyFund
Commits
fba9f352
Commit
fba9f352
authored
May 19, 2023
by
陈涛
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
scheduler采用依赖注入
parent
0d718040
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
112 additions
and
2 deletions
+112
-2
fund.py
api/fund.py
+1
-2
test1.py
test1.py
+111
-0
No files found.
api/fund.py
View file @
fba9f352
...
...
@@ -4,7 +4,7 @@ from typing import Union, Optional
import
pytz
from
apscheduler.schedulers.asyncio
import
AsyncIOScheduler
from
fastapi
import
APIRouter
,
Depends
,
Query
,
Request
from
fastapi
import
APIRouter
,
Depends
,
Query
from
motor.core
import
AgnosticCollection
from
pymongo
import
ReturnDocument
...
...
@@ -44,7 +44,6 @@ async def create(
data
=
create_model
.
dict
()
response_model
=
fund_type_map
[
data
[
'fund_type'
]]
await
fund_collect
.
insert_one
(
data
)
# await calculate_nav_task(data['id'], scheduler, fund_collect, user.id)
await
create_default_role_and_user
(
data
[
'id'
],
user
.
email
,
permission_user_collect
,
permission_role_collect
)
job_id
=
f
"calculate_nav_{data['id']}"
time_obj
=
datetime
.
datetime
.
strptime
(
data
[
"settlement_time"
],
"
%
H:
%
M"
)
...
...
test1.py
0 → 100644
View file @
fba9f352
#
#
# # def arimean(*args):
# # return sum(args) / len(args)
# #
# #
# # def curry(func):
# # """
# # curry()函数是一个装饰器函数,它接受一个函数作为参数并返回一个新函数。
# # 新函数可以被多次调用,并将参数累加到先前传递的参数中。
# # 只有在调用时不带任何参数时,它才会调用原始函数并将累积的参数传递给它。
# # f_args和f_kwargs分别用于存储传递给新函数的位置参数和关键字参数。
# # 然后,它返回一个闭包f(),该函数可以被多次调用。
# # 每次调用时,如果有参数,则将它们添加到f_args和f_kwargs中,并返回f以便可以继续添加更多参数。
# # 如果没有参数,则f()将调用原始函数,并将累积的参数传递给它。
# # 最后,f_args和f_kwargs被重置为空列表和字典,以便可以进行下一次调用
# # :param func:
# # :return:
# # """
# # # to keep the name of the curried function:
# # curry.__curried_func_name__ = func.__name__ # 这里为什么这么做? 目的是什么?
# # """
# # 这一行代码为curry()函数设置了一个特殊的属性__curried_func_name__,其值是被装饰的函数的名称。
# # 这个属性的作用是为了方便调试和日志记录。当一个函数被装饰时,它的名称通常会被改变,因为它现在是一个新函数。
# # 然而,在某些情况下,我们仍然希望知道这个新函数是从哪个旧函数生成的。
# # 通过在curry()函数中设置一个特殊的属性,我们可以让新函数保留对原始函数的引用。
# # 在调试或日志记录时,我们可以使用这个属性来追踪一个函数的来源.
# # 在Python中,双下划线__前缀和后缀用于指示特殊属性或方法,通常称为"魔法方法"或"魔法属性"。
# # 这些特殊的名称通常具有特殊的含义和行为,例如__init__方法用于类的初始化,__str__方法用于将对象转换为字符串,等等。
# # 类似地,__curried_func_name__是一个特殊的属性,它用于保存被装饰函数的名称。
# # 使用双下划线作为前缀和后缀是一种Python约定,用于指示这是一个特殊属性,应该避免与其他变量名冲突。
# # Python还有单下划线和双下划线的命名惯例。
# # 例如,单下划线前缀通常用于指示一个名称是受保护的或私有的,而双下划线前缀和后缀用于名称修饰,避免名称冲突等
# # """
# # f_args, f_kwargs = [], {} # `f_args` 和 `f_kwargs` 是 `curry` 函数中的变量,它们用于存储调用原始函数时传递的所有参数
# #
# # def f(*args, **kwargs):
# # """
# # f()函数是curry()函数的返回值
# # 用于处理传递给curry()函数的原始函数。
# # 该闭包函数可以被多次调用,每次调用时可以传递一些参数。它的作用是将这些参数累加到一个列表和一个字典中,并在适当的时候调用原始函数。
# # :param args:
# # :param kwargs:
# # :return:
# # """
# # nonlocal f_args, f_kwargs # 使用nonlocal关键字我们可以告诉Python解释器在f函数中使用外部函数curry中定义的变量f_arg 和f_kwargs
# # if args or kwargs: # 判断arg、kwargs
# # f_args += args
# # f_kwargs.update(kwargs)
# # return f
# # else: # 没有则调用传入的func方法,重置f_args, f_kwargs的值
# # result = func(*f_args, *f_kwargs)
# # """
# # 表示将f_args列表和f_kwargs字典中的元素解包后传递给func函数,func函数是作为参数传入的
# # """
# # f_args, f_kwargs = [], {}
# # return result
# #
# # return f
# #
# #
# # curried_arimean = curry(arimean) # 给curry函数传入arimean方法,并存储到变量curried_arimean中
# # curried_arimean(2)(5)(9)(4, 5) # 对curried_arimean进行多次调用,分别执行(2)、(5)、(9)、(4,5)
# # # it will keep on currying:
# # curried_arimean(5, 9) # 对curried_arimean进行调用,执行(5, 9)
# # print(curried_arimean()) # 对curried_arimean进行调用,执行()这里arg与kwargs都没有传入走else逻辑
# # # calculating the arithmetic mean of 3, 4, and 7
# # print(curried_arimean(3)(4)(7)())
# # # calculating the arithmetic mean of 4, 3, and 7
# # print(curried_arimean(4)(3, 7)())
#
# from sqlalchemy import create_engine, Column, Integer, String
# from sqlalchemy.orm import sessionmaker
# from sqlalchemy.ext.declarative import declarative_base
#
# # 创建数据库引擎
# engine = create_engine('sqlite:///example.db')
#
# # 创建一个会话工厂
# Session = sessionmaker(bind=engine)
#
# # 创建一个基类
# Base = declarative_base()
#
#
# # 定义一个数据模型
# class User(Base):
# __tablename__ = 'users'
#
# id = Column(Integer, primary_key=True)
# name = Column(String)
# age = Column(Integer)
#
#
# # 创建数据表
# Base.metadata.create_all(engine)
#
# # 创建一个会话
# session = Session()
#
# # # 插入一些数据
# user1 = User(name='Alice', age=25)
# user2 = User(name='Bob', age=30)
# session.add_all([user1, user2])
# session.commit()
#
# # 查询数据
# users = session.query(User).all()
#
# for user in users:
# print(user.id, user.name, user.age)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment