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

Store number of captures per earnings record #56

Open
ZavenArra opened this issue Feb 3, 2022 · 5 comments
Open

Store number of captures per earnings record #56

ZavenArra opened this issue Feb 3, 2022 · 5 comments

Comments

@ZavenArra
Copy link
Contributor

ZavenArra commented Feb 3, 2022

Create new field in the earnings schema called 'captures_count' and extend the DAG to store the total number of captures consolidated into each earnings record.

@dadiorchen
Copy link
Contributor

@ZavenArra how do we count the captures number for every earnings record?

@dadiorchen
Copy link
Contributor

My plan on this:
Use this SQL to update all data in earings:

with counted as (
  select earnings_id, count(*) as captures_count
  from trees
  where 
    earnings_id is not null
  group by earnings_id
) 
update earnings.earnings
  set captures_count = counted.captures_count
from counted
where counted.earnings_id = earnings.earnings.id;

I can add this as a function into the lib, so we can use it in the dag, which one is a good one for this goal?
https://github.com/Greenstand/treetracker-airflow-dags/blob/main/contracts-earnings-fcc-term-3.py ?

@ZavenArra
Copy link
Contributor Author

We don't need to update ALL the records, just the ones that we are adding. The captures count should be computed when we create an earnings record, and from there it will never change.

@dadiorchen
Copy link
Contributor

Which dag is the one you used to insert the earnings record? contracts-earnings-fcc-term-3.py ? there are three similar.

@dadiorchen
Copy link
Contributor

I have made the change, seems to work:

image

@dadiorchen dadiorchen removed their assignment Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

No branches or pull requests

2 participants