fix: date parsing, continent grouping, dynamic analytics, and sector scraping
All checks were successful
Deployment / deploy-docker (push) Successful in 5s
All checks were successful
Deployment / deploy-docker (push) Successful in 5s
This commit is contained in:
@@ -55,12 +55,15 @@ async def get_metadata():
|
||||
|
||||
@app.get("/api/summary")
|
||||
async def get_summary():
|
||||
# Group by continent/country if metadata exists
|
||||
# Coalesce null values to 'Unknown' and group properly
|
||||
query = """
|
||||
select m.continent, m.country, count(*) as trade_count, sum(t.price * t.quantity) as total_volume
|
||||
select
|
||||
coalesce(m.continent, 'Unknown') as continent,
|
||||
count(*) as trade_count,
|
||||
sum(t.price * t.quantity) as total_volume
|
||||
from trades t
|
||||
left join metadata m on t.isin = m.isin
|
||||
group by m.continent, m.country
|
||||
group by continent
|
||||
"""
|
||||
try:
|
||||
response = requests.get(f"http://{DB_HOST}:9000/exec", params={'query': query}, auth=DB_AUTH)
|
||||
@@ -73,8 +76,14 @@ async def get_summary():
|
||||
@app.get("/api/comparison")
|
||||
async def get_comparison(days: int = 7):
|
||||
# Aggregated volume per exchange per day
|
||||
# QuestDB date_trunc('day', timestamp) is good.
|
||||
# We ensure we get exchange, day, and metrics.
|
||||
query = f"""
|
||||
select exchange, date_trunc('day', timestamp) as day, sum(price * quantity) as daily_volume, count(*) as trade_count
|
||||
select
|
||||
exchange,
|
||||
date_trunc('day', timestamp) as day,
|
||||
sum(price * quantity) as daily_volume,
|
||||
count(*) as trade_count
|
||||
from trades
|
||||
where timestamp > dateadd('d', -{days}, now())
|
||||
group by exchange, day
|
||||
|
||||
Reference in New Issue
Block a user