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 fix/clean up #4062

Merged
merged 5 commits into from
Dec 13, 2024

Conversation

NicholasTurner23
Copy link
Contributor

@NicholasTurner23 NicholasTurner23 commented Dec 13, 2024

Description

[Provide a brief description of the changes made in this PR]
This PR cleans the daily measurements tasks

Related Issues

  • JIRA cards:
    • OPS-325

Summary by CodeRabbit

  • New Features

    • Enhanced data cleaning process to drop the pm2_5_raw_value column if it contains only zeros or missing values.
    • Updated data reloading and querying functionality in the BigQueryApi class for improved flexibility and error handling.
    • Streamlined data averaging process in the DailyDataUtils class for better efficiency and clarity.
  • Bug Fixes

    • Improved error handling for missing timestamp data in the BigQueryApi class.
  • Documentation

    • Added detailed docstrings to methods in the BigQueryApi and DailyDataUtils classes to enhance usability and clarity.

Copy link
Contributor

coderabbitai bot commented Dec 13, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request involve modifications to several methods across different classes, primarily focusing on data handling and processing. Key alterations include updates to the simple_data_cleaning method in the EventsModel class to broaden the criteria for dropping the pm2_5_raw_value column. The BigQueryApi class sees a shift from using the parameter tenant to network, enhancing error handling and documentation. Additionally, the average_data method in DailyDataUtils is optimized for efficiency, with improved data grouping and documentation.

Changes

File Path Change Summary
src/analytics/api/models/events.py Modified simple_data_cleaning method to drop pm2_5_raw_value if all values are zero or NaN; minor formatting changes.
src/workflows/airqo_etl_utils/bigquery_api.py Updated reload_data method to replace tenant with network, added error handling for missing "timestamp" column, and updated compose_query and query_data methods accordingly.
src/workflows/airqo_etl_utils/daily_data_utils.py Refined average_data method for efficiency by grouping by network and device ID; updated cleanup_and_reload to change tenant to network when calling reload_data.

Possibly related PRs

Suggested reviewers

  • Baalmart
  • BenjaminSsempala

🌟 In the realm of data, changes do unfold,
With cleaner methods and stories retold.
From tenants to networks, the terms we refine,
As we gather insights, our work will align.
So here's to the tweaks, both big and small,
In the world of analytics, we’ll conquer it all! 🌟


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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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: 2

🧹 Outside diff range and nitpick comments (1)
src/workflows/airqo_etl_utils/daily_data_utils.py (1)

33-51: Optimize data averaging by eliminating the loop

You can improve the efficiency of the average_data method by removing the loop and performing grouping and resampling directly on the DataFrame. This will enhance performance, especially with large datasets.

Here's how you might refactor the code:

data["timestamp"] = pd.to_datetime(data["timestamp"])
averaged_data = (
    data.set_index("timestamp")
        .groupby(["network", "device_id", "site_id", "device_number"])
        .resample("1D")
        .mean(numeric_only=True)
        .reset_index()
)

This approach simplifies the code by eliminating the need to concatenate individual DataFrames and reduces memory usage.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f0fb6ac and 688e416.

📒 Files selected for processing (3)
  • src/analytics/api/models/events.py (1 hunks)
  • src/workflows/airqo_etl_utils/bigquery_api.py (1 hunks)
  • src/workflows/airqo_etl_utils/daily_data_utils.py (2 hunks)
🔇 Additional comments (2)
src/workflows/airqo_etl_utils/bigquery_api.py (1)

607-652: Confirm consistent handling of the 'network' parameter

The reload_data method now includes the network parameter with a default value of "all". Please verify that:

  • All calls to reload_data provide appropriate network values.
  • The compose_query method correctly handles "all" as a valid value for the network parameter.
  • This change aligns with the overall design and does not introduce unintended side effects.
src/analytics/api/models/events.py (1)

592-592: Verify the impact of dropping 'pm2_5_raw_value' when all values are zero or NaN

The updated condition in simple_data_cleaning now drops the 'pm2_5_raw_value' column when all its values are zero or NaN. Please ensure that this change does not adversely affect any downstream processes or analyses that rely on this column, even if it contains only zeros or missing values.

Comment on lines +11 to +28
"""
Averages data in a pandas DataFrame on a daily basis for each device,
grouped by network and device ID. The function resamples data
to compute daily averages for numerical columns.

Args:
data (pd.DataFrame): A pandas DataFrame containing the following columns:
- "timestamp": Timestamps of the data.
- "network": The network the data belongs to.
- "device_id": Unique identifier for the device.
- "site_id": Unique identifier for the site associated with the device.
- "device_number": Device number.

Returns:
pd.DataFrame: A DataFrame containing daily averages for each device,
including metadata columns such as "tenant", "device_id", "site_id",
and "device_number".
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Update docstring to replace 'tenant' with 'network' for consistency

In the Returns section of the docstring for average_data, it mentions metadata columns such as "tenant", "device_id", "site_id", and "device_number". However, the code uses "network" instead of "tenant". Please update the docstring to reflect "network" to maintain consistency and avoid confusion.

Comment on lines +643 to +644
dataframe.copy()
) # Not sure why this dataframe is being copied. # Memory wastage?
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Clarify the purpose of copying the DataFrame or remove the unnecessary copy

The comment # Not sure why this dataframe is being copied. # Memory wastage? suggests uncertainty about the necessity of copying the DataFrame. If the copy is not required, consider removing data = dataframe.copy() to conserve memory. If it is necessary, please provide an explanation to clarify its purpose for future reference.

@Baalmart Baalmart merged commit 40bbbd5 into airqo-platform:staging Dec 13, 2024
45 of 46 checks passed
@Baalmart Baalmart mentioned this pull request Dec 13, 2024
1 task
This was referenced Dec 13, 2024
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.

2 participants