Skip to content

Commit

Permalink
added mode sql code for fetching github commits and updated the model
Browse files Browse the repository at this point in the history
  • Loading branch information
klai95 committed Mar 31, 2023
1 parent 4f2fdc7 commit 0bd02ef
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
12 changes: 6 additions & 6 deletions data-workflows/activity/github_activity_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ def format_to_timestamp(self, timestamp: datetime) -> Union[int, None]:
def format_to_type_identifier(self, identifier: str) -> str:
return self.type_identifier_formatter.format(identifier)

def get_query_timestamp_projection(self) -> str:
def get_query_projection(self) -> str:
if self is GitHubActivityType.LATEST:
return '1'
elif self is GitHubActivityType.TOTAL:
return '2'
return '1, max(commit_author_date) as latest_commit'
elif self is GitHubActivityType.MONTH:
return 'date_trunc('"month"', to_date(commit_author_date)) as month, count(*) as num_commit'
else:
return f"DATE_TRUNC('{self.name}', timestamp)"
return '1, count(*) as num_commits'


class GitHubActivity(Model):
class Meta:
host = os.getenv('LOCAL_DYNAMO_HOST')
prefix = os.getenv('STACK_NAME')
region = os.getenv('AWS_REGION')
table_name = f'{prefix}-github-activity'
region = region

plugin_name = UnicodeAttribute(hash_key=True)
type_identifier = UnicodeAttribute(range_key=True)
Expand Down
19 changes: 19 additions & 0 deletions data-workflows/activity/snowflake_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,25 @@ def get_plugins_install_count_since_timestamp(plugins_by_earliest_ts: dict[str,
return _mapped_query_results(query, 'PYPI', {}, _cursor_to_plugin_activity_mapper)


def get_plugins_commit_count_since_timestamp(plugins_by_earliest_ts: dict[str, datetime],
github_activity_type: GitHubActivityType) -> dict[str, List]:
# TODO: fill in (...) for the logic to get the commit count since a specific starting point for each plugin
query = f"""
SELECT
LOWER(file_project) AS plugin,
{github_activity_type.get_query_projection()}
FROM
imaging.github.commits
WHERE
repo_type = 'plugin'
AND (...)
GROUP BY 1, 2
ORDER BY 1, 2
"""
LOGGER.info(f'Fetching data for granularity={github_activity_type.name}')
return _mapped_query_results(query, 'GITHUB', {}, _cursor_to_plugin_activity_mapper)


def get_plugins_with_commits_in_window(start_millis: int, end_millis: int) -> dict[str, datetime]:
query = f"""
SELECT
Expand Down

0 comments on commit 0bd02ef

Please sign in to comment.