Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
R
robo-dividend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
wenwen.tang
robo-dividend
Commits
228349ea
Commit
228349ea
authored
2 years ago
by
jichao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
依赖注入实现中
parent
4175cece
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
152 additions
and
110 deletions
+152
-110
api.py
api.py
+13
-0
config.yml
config.yml
+47
-46
robo_base_datum.py
datas/datum/robo_base_datum.py
+1
-1
impl.py
datas/impl.py
+16
-0
api.py
datas/navs/api.py
+2
-2
robo_exrate.py
datas/navs/robo_exrate.py
+2
-2
robo_fund_navs.py
datas/navs/robo_fund_navs.py
+2
-2
__env_config.py
framework/__env_config.py
+0
-0
__init__.py
framework/__init__.py
+4
-2
__logger.py
framework/__logger.py
+2
-2
base.py
framework/base.py
+0
-0
date_utils.py
framework/date_utils.py
+0
-0
datebase.py
framework/datebase.py
+15
-2
injectable.py
framework/injectable.py
+26
-47
fund_optimize.py
fund_pool/fund_optimize.py
+1
-1
service.py
fund_pool/service.py
+12
-0
main.py
main.py
+9
-3
No files found.
api.py
0 → 100644
View file @
228349ea
from
abc
import
ABCMeta
,
abstractmethod
class
BaseBean
(
metaclass
=
ABCMeta
):
@
abstractmethod
def
do_something
(
self
):
pass
class
ServiceBean
(
metaclass
=
ABCMeta
):
@
abstractmethod
def
do_service
(
self
):
pass
This diff is collapsed.
Click to expand it.
config.yml
View file @
228349ea
database
:
framework
:
database
:
host
:
${MYSQL_HOST:127.0.0.1}
host
:
${MYSQL_HOST:127.0.0.1}
port
:
${MYSQL_PORT:3306}
port
:
${MYSQL_PORT:3306}
user
:
${MYSQL_USER:root}
user
:
${MYSQL_USER:root}
password
:
${MYSQL_PWD:123456}
password
:
${MYSQL_PWD:123456}
dbname
:
${MYSQL_DBNAME:jftech_robo}
dbname
:
${MYSQL_DBNAME:jftech_robo}
database_from
:
database_from
:
host
:
${MYSQL_HOST:127.0.0.1}
host
:
${MYSQL_HOST:127.0.0.1}
port
:
${MYSQL_PORT:3306}
port
:
${MYSQL_PORT:3306}
user
:
${MYSQL_USER:root}
user
:
${MYSQL_USER:root}
password
:
${MYSQL_PWD:123456}
password
:
${MYSQL_PWD:123456}
dbname
:
${MYSQL_DBNAME:robo_pmpt}
dbname
:
${MYSQL_DBNAME:robo_pmpt}
email
:
email
:
server
:
smtphz.qiye.163.com
server
:
smtphz.qiye.163.com
user
:
jft-ra@thizgroup.com
user
:
jft-ra@thizgroup.com
password
:
5dbb#30ec6d3
password
:
5dbb#30ec6d3
logger
:
logger
:
version
:
1
version
:
1
use
:
${LOG_NAME:root}
use
:
${LOG_NAME:root}
formatters
:
formatters
:
...
...
This diff is collapsed.
Click to expand it.
datas/datum/robo_base_datum.py
View file @
228349ea
from
utils
import
read
,
write
,
config
,
format_date
,
parse_date
,
where
from
framework
import
read
,
write
,
config
,
format_date
,
parse_date
,
where
import
json
import
json
from
datetime
import
datetime
from
datetime
import
datetime
from
datas.datum.enums
import
DatumType
from
datas.datum.enums
import
DatumType
...
...
This diff is collapsed.
Click to expand it.
datas/impl.py
0 → 100644
View file @
228349ea
from
api
import
BaseBean
from
framework
import
component
@
component
(
bean_name
=
"one"
)
class
OneImplBean
(
BaseBean
):
def
do_something
(
self
):
print
(
"one bean"
)
@
component
(
bean_name
=
"two"
)
class
TwoImplBean
(
BaseBean
):
def
do_something
(
self
):
print
(
"two bean"
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
datas/navs/api.py
View file @
228349ea
import
pandas
as
_pd
import
pandas
as
_pd
from
datas.navs
import
robo_exrate
as
_re
,
robo_fund_navs
as
_navs
from
datas.navs
import
robo_exrate
as
_re
,
robo_fund_navs
as
_navs
from
datas
import
datum
as
_datum
,
DatumType
from
datas
import
datum
as
_datum
,
DatumType
from
utils
import
config
,
to_bool
from
framework
import
config
,
to_bool
from
datetime
import
timedelta
from
datetime
import
timedelta
navs_config
=
config
[
'datas'
][
'navs'
]
if
'datas'
in
config
and
'navs'
in
config
[
'datas'
]
else
{}
navs_config
=
config
[
'datas'
][
'navs'
]
if
'datas'
in
config
and
'navs'
in
config
[
'datas'
]
else
{}
...
@@ -27,6 +27,6 @@ def get_navs(fund_id=None, min_date=None, max_date=None):
...
@@ -27,6 +27,6 @@ def get_navs(fund_id=None, min_date=None, max_date=None):
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
from
utils
import
parse_date
from
framework
import
parse_date
print
(
get_navs
(
min_date
=
parse_date
(
'2022-11-01'
)))
print
(
get_navs
(
min_date
=
parse_date
(
'2022-11-01'
)))
This diff is collapsed.
Click to expand it.
datas/navs/robo_exrate.py
View file @
228349ea
from
utils
import
read
,
where
,
format_date
from
framework
import
read
,
where
,
format_date
@
read
@
read
...
@@ -21,6 +21,6 @@ def get_exrate(ticker, date):
...
@@ -21,6 +21,6 @@ def get_exrate(ticker, date):
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
from
utils
import
parse_date
from
framework
import
parse_date
print
(
get_exrate
(
date
=
parse_date
(
'2022-11-01'
),
ticker
=
'EURUSD BGN Curncy'
))
print
(
get_exrate
(
date
=
parse_date
(
'2022-11-01'
),
ticker
=
'EURUSD BGN Curncy'
))
This diff is collapsed.
Click to expand it.
datas/navs/robo_fund_navs.py
View file @
228349ea
from
utils
import
read
,
where
,
format_date
from
framework
import
read
,
where
,
format_date
@
read
@
read
...
@@ -16,6 +16,6 @@ def get_navs(fund_id=None, min_date=None, max_date=None):
...
@@ -16,6 +16,6 @@ def get_navs(fund_id=None, min_date=None, max_date=None):
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
from
utils
import
parse_date
from
framework
import
parse_date
navs
=
get_navs
(
fund_id
=
1
,
min_date
=
parse_date
(
'2022-11-01'
))
navs
=
get_navs
(
fund_id
=
1
,
min_date
=
parse_date
(
'2022-11-01'
))
print
(
navs
)
print
(
navs
)
This diff is collapsed.
Click to expand it.
utils
/__env_config.py
→
framework
/__env_config.py
View file @
228349ea
File moved
This diff is collapsed.
Click to expand it.
utils
/__init__.py
→
framework
/__init__.py
View file @
228349ea
...
@@ -3,6 +3,8 @@ from .base import *
...
@@ -3,6 +3,8 @@ from .base import *
from
.datebase
import
read
,
write
,
transaction
,
where
from
.datebase
import
read
,
write
,
transaction
,
where
from
.__env_config
import
config
,
get_config
from
.__env_config
import
config
,
get_config
from
.__logger
import
build_logger
,
logger
from
.__logger
import
build_logger
,
logger
from
.injectable
import
component
from
.injectable
import
component
,
autowired
,
get_instance
,
init_injectable
as
_init_injectable
del
injectable
,
__logger
,
__env_config
,
datebase
,
base
,
date_utils
_init_injectable
()
del
injectable
,
__logger
,
__env_config
,
datebase
,
base
,
date_utils
,
_init_injectable
This diff is collapsed.
Click to expand it.
utils
/__logger.py
→
framework
/__logger.py
View file @
228349ea
...
@@ -14,5 +14,5 @@ def build_logger(config, name='root'):
...
@@ -14,5 +14,5 @@ def build_logger(config, name='root'):
return
getLogger
(
name
)
return
getLogger
(
name
)
if
'
logger'
in
config
:
if
'
framework'
in
config
and
'logger'
in
config
[
'framework'
]
:
logger
=
build_logger
(
config
[
'
logger'
],
name
=
config
[
'logger'
][
'use'
])
logger
=
build_logger
(
config
[
'
framework'
][
'logger'
],
name
=
config
[
'framework'
]
[
'logger'
][
'use'
])
This diff is collapsed.
Click to expand it.
utils
/base.py
→
framework
/base.py
View file @
228349ea
File moved
This diff is collapsed.
Click to expand it.
utils
/date_utils.py
→
framework
/date_utils.py
View file @
228349ea
File moved
This diff is collapsed.
Click to expand it.
utils
/datebase.py
→
framework
/datebase.py
View file @
228349ea
...
@@ -2,14 +2,27 @@ import functools
...
@@ -2,14 +2,27 @@ import functools
import
pymysql
import
pymysql
import
threading
import
threading
from
pymysql.cursors
import
DictCursor
from
pymysql.cursors
import
DictCursor
from
.__env_config
import
config
as
default
_config
from
.__env_config
import
config
as
global
_config
from
.date_utils
import
format_date
,
datetime
from
.date_utils
import
format_date
,
datetime
from
enum
import
Enum
from
enum
import
Enum
_CONFIG
=
global_config
[
'framework'
][
'database'
]
if
'framework'
in
global_config
and
'database'
in
global_config
[
'framework'
]
else
None
class
DatabaseError
(
Exception
):
def
__init__
(
self
,
msg
):
self
.
__msg
=
msg
def
__str__
(
self
):
return
self
.
__msg
class
Database
:
class
Database
:
def
__init__
(
self
,
config
):
def
__init__
(
self
,
config
):
self
.
config
=
config
or
default_config
[
'database'
]
self
.
_config
=
config
or
_CONFIG
if
self
.
_config
is
None
:
raise
DatabaseError
(
"database config is not found."
)
def
__enter__
(
self
):
def
__enter__
(
self
):
port
=
3306
port
=
3306
...
...
This diff is collapsed.
Click to expand it.
utils
/injectable.py
→
framework
/injectable.py
View file @
228349ea
import
abc
import
os
,
sys
import
inspect
from
importlib
import
import_module
import
functools
from
inspect
import
signature
,
Parameter
from
functools
import
partial
,
wraps
from
typing
import
List
,
get_origin
,
get_args
from
typing
import
List
,
get_origin
,
get_args
from
types
import
GenericAlias
from
types
import
GenericAlias
from
framework.base
import
get_project_path
__COMPONENT_CLASS
=
[]
__COMPONENT_CLASS
=
[]
__NAME_COMPONENT
=
{}
__NAME_COMPONENT
=
{}
...
@@ -19,7 +21,7 @@ class InjectableError(Exception):
...
@@ -19,7 +21,7 @@ class InjectableError(Exception):
def
component
(
cls
=
None
,
bean_name
=
None
):
def
component
(
cls
=
None
,
bean_name
=
None
):
if
cls
is
None
:
if
cls
is
None
:
return
functools
.
partial
(
component
,
bean_name
=
bean_name
)
return
partial
(
component
,
bean_name
=
bean_name
)
__COMPONENT_CLASS
.
append
(
cls
)
__COMPONENT_CLASS
.
append
(
cls
)
if
bean_name
:
if
bean_name
:
...
@@ -29,19 +31,23 @@ def component(cls=None, bean_name=None):
...
@@ -29,19 +31,23 @@ def component(cls=None, bean_name=None):
return
cls
return
cls
def
autowired
(
func
=
None
):
def
autowired
(
func
=
None
,
names
=
None
):
if
func
is
None
:
if
func
is
None
:
return
functools
.
partial
(
autowired
)
return
partial
(
autowired
,
names
=
names
)
@
functools
.
wraps
(
func
)
@
wraps
(
func
)
def
wrap
(
*
args
,
**
kwargs
):
def
wrap
(
*
args
,
**
kwargs
):
if
func
.
__name__
==
'__init__'
:
self_type
=
type
(
args
[
0
])
self_type
=
type
(
args
[
0
])
if
self_type
in
__COMPONENT_CLASS
and
self_type
not
in
__COMPONENT_INSTANCE
:
if
self_type
in
__COMPONENT_CLASS
and
self_type
not
in
__COMPONENT_INSTANCE
:
__COMPONENT_INSTANCE
[
self_type
]
=
args
[
0
]
__COMPONENT_INSTANCE
[
self_type
]
=
args
[
0
]
for
p_name
,
p_type
in
inspect
.
signature
(
func
)
.
parameters
.
items
():
for
p_name
,
p_type
in
signature
(
func
)
.
parameters
.
items
():
if
p_name
==
'self'
or
p_type
==
inspect
.
Parameter
.
empty
:
if
p_name
==
'self'
or
p_type
==
Parameter
.
empty
or
p_name
in
kwargs
:
continue
continue
if
get_origin
(
p_type
.
annotation
)
is
list
:
if
names
is
not
None
and
p_name
in
names
:
if
names
[
p_name
]
in
__NAME_COMPONENT
:
kwargs
[
p_name
]
=
get_instance
(
__NAME_COMPONENT
[
names
[
p_name
]])
elif
get_origin
(
p_type
.
annotation
)
is
list
:
inject_types
=
get_args
(
p_type
.
annotation
)
inject_types
=
get_args
(
p_type
.
annotation
)
if
len
(
inject_types
)
>
0
:
if
len
(
inject_types
)
>
0
:
instances
=
[
get_instance
(
x
)
for
x
in
__COMPONENT_CLASS
if
issubclass
(
x
,
inject_types
)]
instances
=
[
get_instance
(
x
)
for
x
in
__COMPONENT_CLASS
if
issubclass
(
x
,
inject_types
)]
...
@@ -64,37 +70,10 @@ def get_instance(t):
...
@@ -64,37 +70,10 @@ def get_instance(t):
return
__COMPONENT_INSTANCE
[
t
]
return
__COMPONENT_INSTANCE
[
t
]
class
BaseBean
(
metaclass
=
abc
.
ABCMeta
):
def
init_injectable
(
path
=
get_project_path
()):
@
abc
.
abstractmethod
for
f
in
os
.
listdir
(
path
):
def
do_something
(
self
):
if
os
.
path
.
isdir
(
f
)
and
os
.
path
.
exists
(
os
.
path
.
join
(
f
,
'__init__.py'
)):
pass
init_injectable
(
path
=
os
.
path
.
join
(
path
,
f
))
if
f
.
endswith
(
'.py'
)
and
f
!=
'__init__.py'
:
py
=
os
.
path
.
relpath
(
os
.
path
.
join
(
path
,
f
),
get_project_path
())[:
-
3
]
@
component
(
bean_name
=
"one"
)
import_module
(
'.'
.
join
(
py
.
split
(
os
.
path
.
sep
)))
class
OneImplBean
(
BaseBean
):
def
do_something
(
self
):
print
(
"one bean"
)
@
component
(
bean_name
=
"two"
)
class
TwoImplBean
(
BaseBean
):
def
do_something
(
self
):
print
(
"two bean"
)
class
ServiceBean
:
@
autowired
def
__init__
(
self
,
base
:
BaseBean
=
None
,
bases
:
List
[
BaseBean
]
=
None
):
base
.
do_something
()
for
b
in
bases
:
b
.
do_something
()
print
(
__COMPONENT_CLASS
,
__NAME_COMPONENT
)
if
__name__
==
'__main__'
:
ServiceBean
()
This diff is collapsed.
Click to expand it.
fund_pool/fund_optimize.py
View file @
228349ea
import
pandas
as
pd
import
pandas
as
pd
from
utils
import
filter_weekend
,
config
,
dict_remove
from
framework
import
filter_weekend
,
config
,
dict_remove
from
datas
import
navs
from
datas
import
navs
from
dateutil.relativedelta
import
relativedelta
from
dateutil.relativedelta
import
relativedelta
from
empyrical
import
sortino_ratio
from
empyrical
import
sortino_ratio
...
...
This diff is collapsed.
Click to expand it.
fund_pool/service.py
0 → 100644
View file @
228349ea
from
api
import
BaseBean
,
ServiceBean
from
framework
import
autowired
,
component
@
component
class
ServiceImpl
(
ServiceBean
):
@
autowired
def
__init__
(
self
,
base
:
BaseBean
=
None
):
self
.
_base
=
base
def
do_service
(
self
):
self
.
_base
.
do_something
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
main.py
View file @
228349ea
from
utils
import
logger
from
framework
import
logger
,
autowired
from
datas
import
datum
from
api
import
ServiceBean
@
autowired
def
test
(
service
:
ServiceBean
=
None
):
service
.
do_service
()
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
logger
.
info
(
dir
())
logger
.
info
(
dir
())
logger
.
info
(
datum
.
get_fund_datums
()
)
test
(
)
This diff is collapsed.
Click to expand it.
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