-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from 0xPlaygrounds/refactor/contrib
`contrib`: `plotly` and `dash` subpackages
- Loading branch information
Showing
26 changed files
with
782 additions
and
609 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
## Running the examples | ||
Install subgrounds with your favorite Python dependency manager. E.g.: `pip install subgrounds`. | ||
|
||
Run the examples, e.g.: `python bar_chart.py` | ||
# Examples | ||
> See [our docs](https://docs.playgrounds.network/examples/) for more examples! |
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,20 @@ | ||
from subgrounds import Subgrounds | ||
|
||
sg = Subgrounds() | ||
|
||
# Load | ||
aave_v2 = sg.load_subgraph( | ||
"https://api.thegraph.com/subgraphs/name/messari/aave-v2-ethereum" | ||
) | ||
|
||
# Construct the query | ||
latest = aave_v2.Query.markets( | ||
orderBy=aave_v2.Market.totalValueLockedUSD, | ||
orderDirection="desc", | ||
first=5, | ||
) | ||
|
||
# Return query to a dataframe | ||
df = sg.query_df([latest.name, latest.totalValueLockedUSD]) | ||
|
||
print(df) |
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,36 @@ | ||
from subgrounds import Subgrounds | ||
|
||
sg = Subgrounds() | ||
|
||
curve = sg.load_subgraph( | ||
"https://api.thegraph.com/subgraphs/name/messari/curve-finance-ethereum" | ||
) | ||
|
||
# Partial FieldPath selecting the top 4 most traded pools on Curve | ||
most_traded_pools = curve.Query.liquidityPools( | ||
orderBy=curve.LiquidityPool.cumulativeVolumeUSD, | ||
orderDirection="desc", | ||
first=4, | ||
) | ||
|
||
# Partial FieldPath selecting the top 2 pools by daily total revenue of | ||
# the top 4 most traded tokens. | ||
# Mote that reuse of `most_traded_pools` in the partial FieldPath | ||
most_traded_snapshots = most_traded_pools.dailySnapshots( | ||
orderBy=curve.LiquidityPoolDailySnapshot.dailyTotalRevenue, | ||
orderDirection="desc", | ||
first=3, | ||
) | ||
|
||
# Querying: | ||
# - the name of the top 4 most traded pools, their 2 most liquid | ||
# pools' token symbols and their 2 most liquid pool's TVL in USD | ||
df = sg.query_df( | ||
[ | ||
most_traded_pools.name, | ||
most_traded_snapshots.dailyVolumeUSD, | ||
most_traded_snapshots.dailyTotalRevenueUSD, | ||
] | ||
) | ||
|
||
print(df) |
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,8 @@ | ||
# Dash Examples | ||
|
||
## Instructions | ||
|
||
```bash | ||
pip install "subgrounds[dash]" | ||
python bar_chart.py | ||
``` |
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
6 changes: 3 additions & 3 deletions
6
examples/live_indicator.py → examples/dash_apps/live_indicator.py
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
9 changes: 3 additions & 6 deletions
9
examples/olympus_voting.py → examples/dash_apps/olympus_voting.py
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
4 changes: 2 additions & 2 deletions
4
examples/uniswapv2_firehose.py → examples/dash_apps/uniswapv2_firehose.py
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,17 @@ | ||
# Subgrounds Contrib | ||
> Extra parts of subgrounds that may not fit in the main package | ||
## What is this? | ||
Contrib is a niche concept in some libraries that represent extra / contributed content to a library that may not fit in the main package. This might be due to the maintainer not willing to maintain said content, the content being deemed too experimental, or perhaps it's unknown whether it's a "good idea" or not. | ||
|
||
> Relevant [Stackoverflow](https://softwareengineering.stackexchange.com/questions/252053/whats-in-the-contrib-folder) post | ||
For us, `subgrounds.contrib` will represent extra features and ideas with `subgrounds` that generally builds upon the core part of `subgrounds`. It allows us to add extensions or features to other libraries (such as `plotly`) without *relying* on the library as a dependency. We might add new concepts to this subpackage in the future, so look out! | ||
|
||
## What's currently here? | ||
|
||
### Plotly | ||
Originally located in `subgrounds.plotly_wrappers`, `subgrounds.contrib.plotly` contains helpful wrappers on `plotly` objects that allow you to use `FieldPaths` directly without creating a `pandas` `DataFrame`. | ||
|
||
### Dash | ||
Originally located in `subgrounds.dash_wrappers`, `subgrounds.contrib.dash` contains helpful wrappers on `dash` objects that allow you to use other wrapped visualization objects (currently `subgrounds.contrib.plotly`) in `dash` apps without creating `pandas` `DataFrame`s. |
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,15 @@ | ||
"""Subgrounds Dash Components | ||
Extending dash components to be able to understand subgrounds logic. This includes other | ||
extended components of other libraries such as `plotly`. | ||
""" | ||
|
||
from .abcs import Refreshable | ||
from .components import AutoUpdate, DataTable, Graph | ||
|
||
__all__ = [ | ||
"Refreshable", | ||
"Graph", | ||
"DataTable", | ||
"AutoUpdate", | ||
] |
Oops, something went wrong.