Skip to content

Commit df2d53d

Browse files
authored
Merge pull request #30 from HTTPArchive/development
Adding latest month logic
2 parents faf607b + 508844c commit df2d53d

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

functions/adoption/libs/queries.py

+11
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,22 @@
77
DB = firestore.Client(project=os.environ.get('PROJECT'), database=os.environ.get('DATABASE'))
88
TABLE = 'adoption'
99

10+
def get_latest_date():
11+
"""Retrieve the latest date in the collection."""
12+
query = DB.collection(TABLE).order_by('date', direction=firestore.Query.DESCENDING).limit(1)
13+
docs = query.stream()
14+
for doc in docs:
15+
return doc.to_dict().get('date')
16+
return None
17+
1018
def list_data(params):
1119

1220
technology_array = convert_to_array(params['technology'])
1321
data = []
1422

23+
if 'end' in params and params['end'] == 'latest':
24+
params['start'] = get_latest_date()
25+
1526
for technology in technology_array:
1627
query = DB.collection(TABLE)
1728

functions/cwvtech/libs/queries.py

+11
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,21 @@
77
DB = firestore.Client(project=os.environ.get('PROJECT'), database=os.environ.get('DATABASE'))
88
TABLE = 'core_web_vitals'
99

10+
def get_latest_date():
11+
"""Retrieve the latest date in the collection."""
12+
query = DB.collection(TABLE).order_by('date', direction=firestore.Query.DESCENDING).limit(1)
13+
docs = query.stream()
14+
for doc in docs:
15+
return doc.to_dict().get('date')
16+
return None
17+
1018
def list_data(params):
1119
technology_array = convert_to_array(params['technology'])
1220
data = []
1321

22+
if 'end' in params and params['end'] == 'latest':
23+
params['start'] = get_latest_date()
24+
1425
for technology in technology_array:
1526
query = DB.collection(TABLE)
1627

functions/lighthouse/libs/queries.py

+11
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,22 @@
77
DB = firestore.Client(project=os.environ.get('PROJECT'), database=os.environ.get('DATABASE'))
88
TABLE = 'lighthouse'
99

10+
def get_latest_date():
11+
"""Retrieve the latest date in the collection."""
12+
query = DB.collection(TABLE).order_by('date', direction=firestore.Query.DESCENDING).limit(1)
13+
docs = query.stream()
14+
for doc in docs:
15+
return doc.to_dict().get('date')
16+
return None
17+
1018
def list_data(params):
1119

1220
technology_array = convert_to_array(params['technology'])
1321
data = []
1422

23+
if 'end' in params and params['end'] == 'latest':
24+
params['start'] = get_latest_date()
25+
1526
for technology in technology_array:
1627
query = DB.collection(TABLE)
1728

functions/page-weight/libs/queries.py

+11
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,22 @@
77
DB = firestore.Client(project=os.environ.get('PROJECT'), database=os.environ.get('DATABASE'))
88
TABLE = 'page_weight'
99

10+
def get_latest_date():
11+
"""Retrieve the latest date in the collection."""
12+
query = DB.collection(TABLE).order_by('date', direction=firestore.Query.DESCENDING).limit(1)
13+
docs = query.stream()
14+
for doc in docs:
15+
return doc.to_dict().get('date')
16+
return None
17+
1018
def list_data(params):
1119

1220
technology_array = convert_to_array(params['technology'])
1321
data = []
1422

23+
if 'end' in params and params['end'] == 'latest':
24+
params['start'] = get_latest_date()
25+
1526
for technology in technology_array:
1627
query = DB.collection(TABLE)
1728

0 commit comments

Comments
 (0)