Skip to content

Commit

Permalink
query_stars_by_repo is reverted for the task
Browse files Browse the repository at this point in the history
  • Loading branch information
kkamkou committed Sep 1, 2017
1 parent 55318d6 commit 72cfeb3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion gitmostwanted/tasks/repo_most_starred.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from time import sleep


def results_of(j: Job): # @todo #0:15m copy-paste code in multiple tasks
def results_of(j: Job):
while not j.complete:
app.logger.debug('The job is not complete, waiting...')
sleep(10)
Expand Down
15 changes: 5 additions & 10 deletions gitmostwanted/tasks/repo_stars.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,15 @@ def stars_mature(num_days):
# @todo #192:1h move BQ queries to a separate place
def query_stars_by_repo(repo_id: int, date_from: datetime, date_to: datetime):
query = """
#standardSQL
SELECT
COUNT(1) AS stars,
EXTRACT(YEAR FROM created_at) AS y,
EXTRACT(DAYOFYEAR FROM created_at) AS doy,
EXTRACT(MONTH FROM created_at) AS mon
COUNT(1) AS stars, YEAR(created_at) AS y, DAYOFYEAR(created_at) AS doy,
MONTH(created_at) as mon
FROM
`githubarchive.month.*`
TABLE_DATE_RANGE([githubarchive:day.], TIMESTAMP('{date_from}'), TIMESTAMP('{date_to}'))
WHERE
(_TABLE_SUFFIX BETWEEN '{date_from}' AND '{date_to}')
AND repo.id = {id}
AND type IN ('WatchEvent', 'ForkEvent')
repo.id = {id} AND type IN ('WatchEvent', 'ForkEvent')
GROUP BY y, mon, doy
"""
return query.format(
id=repo_id, date_from=date_from.strftime('%Y%m'), date_to=date_to.strftime('%Y%m')
id=repo_id, date_from=date_from.strftime('%Y-%m-%d'), date_to=date_to.strftime('%Y-%m-%d')
)
24 changes: 22 additions & 2 deletions scripts/repository_mean_reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
from gitmostwanted.lib.bigquery.job import Job
from gitmostwanted.models.repo import Repo, RepoMean, RepoStars
from gitmostwanted.services import bigquery
from gitmostwanted.tasks.repo_stars import query_stars_by_repo
from gitmostwanted.tasks.repo_status import last_known_mean, repo_mean
from time import sleep


def results_of(j: Job): # @todo #0:15m copy-paste code in multiple tasks
def results_of(j: Job):
while not j.complete:
app.logger.debug('The job is not complete, waiting...')
sleep(10)
Expand Down Expand Up @@ -60,3 +59,24 @@ def results_of(j: Job): # @todo #0:15m copy-paste code in multiple tasks
db.session.commit()

app.logger.info('Repository %d has %d days', result.id, cnt)


def query_stars_by_repo(repo_id: int, date_from: datetime, date_to: datetime):
query = """
#standardSQL
SELECT
COUNT(1) AS stars,
EXTRACT(YEAR FROM created_at) AS y,
EXTRACT(DAYOFYEAR FROM created_at) AS doy,
EXTRACT(MONTH FROM created_at) AS mon
FROM
`githubarchive.month.*`
WHERE
(_TABLE_SUFFIX BETWEEN '{date_from}' AND '{date_to}')
AND repo.id = {id}
AND type IN ('WatchEvent', 'ForkEvent')
GROUP BY y, mon, doy
"""
return query.format(
id=repo_id, date_from=date_from.strftime('%Y%m'), date_to=date_to.strftime('%Y%m')
)

2 comments on commit 72cfeb3

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 72cfeb3 Sep 1, 2017

Choose a reason for hiding this comment

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

Puzzle 0-15c49b8d discovered in gitmostwanted/tasks/repo_stars.py and submitted as #200.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 72cfeb3 Sep 1, 2017

Choose a reason for hiding this comment

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

Puzzle 192-ebcb75c9 discovered in gitmostwanted/tasks/repo_stars.py and submitted as #201.

Please sign in to comment.