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

Update/integration iqair devices #3993

Conversation

NicholasTurner23
Copy link
Contributor

@NicholasTurner23 NicholasTurner23 commented Dec 4, 2024

Description

Updates to include network in the bigquery query builder

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced device retrieval methods now focus on network parameters instead of tenant parameters.
    • New network field added to the raw measurements schema for improved data tracking.
  • Improvements

    • Updated data extraction methods to allow for flexible querying based on network.
    • Enhanced error handling for better logging and traceability during data operations.
  • Bug Fixes

    • Adjusted SQL query construction to improve filtering and data retrieval accuracy.

These changes aim to provide users with a more robust and flexible data extraction experience, enhancing the overall functionality of the application.

Copy link
Contributor

coderabbitai bot commented Dec 4, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request primarily involve modifications to various methods across multiple classes in the airqo_etl_utils module. The updates shift the focus from tenant-based parameters to network-based parameters for device retrieval and data extraction. Key methods such as get_devices, extract_aggregated_raw_data, and query_data have been adjusted to accommodate the new network parameter. Additionally, error handling has been improved, and a new field for network has been added to the JSON schema for raw measurements.

Changes

File Path Change Summary
src/workflows/airqo_etl_utils/airqo_api.py Updated get_devices method to use network instead of tenant. Enhanced error handling and modified logic for fetching devices. Updated get_devices_by_network.
src/workflows/airqo_etl_utils/airqo_utils.py Replaced tenant with network in extract_uncalibrated_data, extract_data_from_bigquery, and extract_aggregated_raw_data. Improved error handling in flatten_field_8.
src/workflows/airqo_etl_utils/bigquery_api.py Modified compose_query, query_data, and dynamic_averaging_query methods to include network parameter with default values. Adjusted SQL query construction.
src/workflows/airqo_etl_utils/daily_data_utils.py Removed tenant=Tenant.ALL from query_data calls in query_hourly_data and query_daily_data.
src/workflows/airqo_etl_utils/data_warehouse_utils.py Removed tenant=Tenant.ALL from query_data calls in extract_hourly_bam_data, extract_data_from_big_query, and extract_hourly_low_cost_data. Added default value for tenant in extract_sites_meta_data.
src/workflows/airqo_etl_utils/schema/raw_measurements.json Added new field network as a nullable string type in the JSON schema.
src/workflows/airqo_etl_utils/weather_data_utils.py Removed tenant=Tenant.ALL from extract_hourly_weather_data and extract_raw_data_from_bigquery method calls.
src/workflows/dags/airqo_measurements.py Updated extract_aggregated_raw_data to include network parameter. Modified extract_raw_data to set device_category and added remove_outliers parameter.

Possibly related PRs

Suggested reviewers

  • Baalmart
  • BenjaminSsempala
  • Psalmz777

🎉 In the realm of code, a shift we embrace,
From tenant to network, we quicken the pace.
With methods refined and errors now clear,
Our data flows smoothly, no need for fear.
So here's to the changes, let progress unfold,
In the world of AirQo, new stories are told! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
src/workflows/airqo_etl_utils/airqo_api.py (2)

Line range hint 171-181: Review Error Handling in get_devices Method

In the exception handling block of the get_devices method, an empty list is returned if an error occurs. This might mask underlying issues. Consider raising an exception or providing more contextual information to aid in debugging.


Line range hint 205-219: Add net_status Parameter Documentation in get_networks Method

The get_networks method now includes a net_status parameter. To enhance code clarity, include this parameter in the method's docstring along with its purpose and possible values.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4718807 and cd0063a.

📒 Files selected for processing (8)
  • src/workflows/airqo_etl_utils/airqo_api.py (1 hunks)
  • src/workflows/airqo_etl_utils/airqo_utils.py (4 hunks)
  • src/workflows/airqo_etl_utils/bigquery_api.py (6 hunks)
  • src/workflows/airqo_etl_utils/daily_data_utils.py (0 hunks)
  • src/workflows/airqo_etl_utils/data_warehouse_utils.py (0 hunks)
  • src/workflows/airqo_etl_utils/schema/raw_measurements.json (1 hunks)
  • src/workflows/airqo_etl_utils/weather_data_utils.py (0 hunks)
  • src/workflows/dags/airqo_measurements.py (1 hunks)
💤 Files with no reviewable changes (3)
  • src/workflows/airqo_etl_utils/weather_data_utils.py
  • src/workflows/airqo_etl_utils/data_warehouse_utils.py
  • src/workflows/airqo_etl_utils/daily_data_utils.py
🔇 Additional comments (9)
src/workflows/airqo_etl_utils/airqo_api.py (1)

Line range hint 138-203: Ensure Proper Handling of the network Parameter in get_devices Method

The get_devices method now accepts a network parameter to retrieve devices based on the network. Verify that all calls to this method pass the correct network value. Additionally, consider handling cases where network might be None to ensure backward compatibility and prevent potential errors.

src/workflows/airqo_etl_utils/schema/raw_measurements.json (1)

7-11: Addition of network Field to Schema

The network field has been successfully added to the schema with the appropriate type and mode. Ensure that this field is correctly populated during data ingestion and that downstream processes are updated to accommodate this new field.

src/workflows/dags/airqo_measurements.py (1)

45-46: Inclusion of network Parameter in extract_aggregated_raw_data

The network parameter has been added to the extract_aggregated_raw_data function call with the value "airqo". Confirm that the function definition in AirQoDataUtils accepts this parameter and that it is used appropriately within the function to filter data by network.

src/workflows/airqo_etl_utils/bigquery_api.py (2)

512-512: Update compose_query Method to Include network Parameter

The compose_query method signature now includes the network parameter with a default value "all". Verify that all calls to this method pass the correct network value and that the method handles cases when network is "all" appropriately in the query construction.


Line range hint 614-654: Ensure Proper Handling of Optional network Parameter in query_data Method

The query_data method now accepts an optional network parameter. Review the method's logic to ensure it correctly handles cases when network is None or specified. Additionally, confirm that the dynamic query generation accommodates the network filter appropriately.

src/workflows/airqo_etl_utils/airqo_utils.py (4)

62-62: Update Call to bigquery_api.query_data with network Parameter

In the extract_uncalibrated_data method, the call to bigquery_api.query_data now includes the network parameter set to str(Tenant.AIRQO). Ensure that this aligns with the updated method signature and that the correct network data is retrieved.


82-82: Inclusion of network Parameter in extract_data_from_bigquery

The network parameter is added to the bigquery_api.query_data call within extract_data_from_bigquery. Verify that this parameter is correctly propagated and that data is filtered based on the specified network.


Line range hint 120-134: Enhance Flexibility with network Parameter in extract_aggregated_raw_data

The extract_aggregated_raw_data method now accepts an optional network parameter. This enhances data extraction flexibility. Ensure that when network is None, the method behaves as expected, possibly retrieving data across all networks.


Line range hint 205-210: Improve Exception Handling in flatten_field_8 Method

The exception handling in flatten_field_8 has been refined to provide clearer logging messages. This aids in debugging but ensure that sensitive information is not logged. Consider adding more specific exception types if possible.

Comment on lines +544 to +547
where_clause = f" timestamp between '{start_date_time}' and '{end_date_time}' "

if network:
where_clause += f"AND network = '{network}' "
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Validate SQL Query Construction for network Filter

The inclusion of the network filter in the where_clause should be carefully constructed to prevent SQL injection vulnerabilities. Ensure that the network variable is sanitized or parameterized within the query to enhance security.

@Baalmart Baalmart merged commit f43cad7 into airqo-platform:staging Dec 4, 2024
46 checks passed
@Baalmart Baalmart mentioned this pull request Dec 4, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants