Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add endpoint to retrieve project types #139

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

andersy005
Copy link
Member

@andersy005 andersy005 commented Jan 24, 2025

@katamartin, this is ready

❯ curl -X 'GET' \                                                                                                                                                                         ─╯
  'https://offsets-db-staging.fly.dev/projects/types?top_n=6' \
  -H 'accept: application/json' \
  -H 'X-API-KEY: XXXXXXXXXX'
{"top":["redd+","wind","improved forest management","hydropower","cookstoves","solar - centralized"],"others":["landfill methane","afforestation/reforestation","mine methane capture","biomass","ozone depleting substances recovery & destruction","hfc replacement in foam production","leak detection & repair in gas systems","manure methane digester","biodigesters","natural gas electricity generation","n2o destruction in nitric acid production","carbon capture & enhanced oil recovery","hfc refrigerant reclamation","clean water","waste heat recovery","n2o destruction in adipic acid production","methane recovery in wastewater","waste gas recovery","bundled energy efficiency","sustainable grassland management","geothermal","avoided forest conversion","sf6 replacement","re bundled","community boreholes","wetland restoration","energy efficiency","composting","rice emission reductions","hfc23 destruction","advanced refrigerants","plugging oil & gas wells","lighting","waste incineration","solar - distributed","solar lighting","brick manufacturing emission reductions","university campus emission reductions","avoided grassland conversion","solar water heaters","sustainable agriculture","propylene oxide production","fleet efficiency","oil recycling","pneumatic retrofit","waste recycling","fuel switching","improved irrigation management","truck stop electrification","solid waste separation","aluminum smelters emission reductions","refrigerant leak detection","mass transit","shipping","carbon capture in concrete","lower carbon cement & concrete","electric vehicles & charging","road construction emission reductions","waste diversion","weatherization","feed additives","bicycles","carbon-absorbing concrete","nitrogen management","carbon capture in plastic","fuel transport","grid expansion & mini-grids","biochar","bundled compost production and soil application"]}

@github-actions github-actions bot added the api label Jan 24, 2025
Copy link
Member

@katamartin katamartin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @andersy005 !

The payload generally looks good! If it'd be helpful to test the frontend integration before deploying to production, I think we might need to make the /projects changes at the same time to be able to test the way these pieces fit together.

result = session.exec(statement).all()
top = [project_type for project_type, _ in result[:top_n]]
others = [project_type for project_type, _ in result[top_n:]]
return ProjectTypes(top=top, others=others)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we going to support the general /projects?project_type=Other query on the /projects endpoint? I think that would be helpful because including all of the "others" entries would make for a huge request URL.

If that's the case, should we use consistent naming here?

Suggested change
return ProjectTypes(top=top, others=others)
return ProjectTypes(Top=top, Other=others)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one idea that comes to mind is doing something along these lines:

update the /projects endpoint by adding the top_project_types parameter as a query parameter, and handle the project_type=Other logic when it's used in combination with top_project_types.

GET /projects?project_type=Other&top_project_types=Type1,Type2,Type3

this would translate in using the NOT IN clause on on the backend to exclude the top project types if project_type=Other is detected.

SELECT ...
....
WHERE project_type NOT in top_project_types

one advantage of this approach is that we avoid having to query the database to get the list of Other types and instead take advantage of the fact that we already know which types are in Top

@katamartin, how does this sound?

offsets_db_api/routers/projects.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants