Skip to content

Commit

Permalink
Merge pull request #24 from HTTPArchive/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
maceto authored Jul 23, 2024
2 parents 0f1a37c + faa083a commit 5445dda
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 50 deletions.
43 changes: 24 additions & 19 deletions functions/adoption/libs/queries.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
import os
import json
from google.cloud import firestore
from google.cloud.firestore_v1.base_query import FieldFilter
from .result import Result
from .utils import convert_to_array

DB = firestore.Client(project=os.environ.get('PROJECT'), database=os.environ.get('DATABASE'))
TABLE = 'adoption'

def list_data(params):
ref = DB.collection(u'adoption')

query = ref
technology_array = convert_to_array(params['technology'])
data = []

if 'start' in params:
query = query.where('date', '>=', params['start'])
if 'end' in params:
query = query.where('date', '<=', params['end'])
if 'geo' in params:
query = query.where('geo', '==', params['geo'])
if 'technology' in params:
params_array = convert_to_array(params['technology'])
query = query.where('technology', 'in', params_array)
if 'rank' in params:
query = query.where('rank', '==', params['rank'])
for technology in technology_array:
query = DB.collection(TABLE)

documents = query.stream()
if 'start' in params:
query = query.where(filter=FieldFilter('date', '>=', params['start']))

data = []
for doc in documents:
data.append(doc.to_dict())
if 'end' in params:
query = query.where(filter=FieldFilter('date', '<=', params['end']))

if 'geo' in params:
query = query.where(filter=FieldFilter('geo', '==', params['geo']))

if 'rank' in params:
query = query.where(filter=FieldFilter('rank', '==', params['rank']))

query = query.where(filter=FieldFilter('technology', '==', technology))

documents = query.stream()

for doc in documents:
data.append(doc.to_dict())

return Result(result=data)
return Result(result=data)
7 changes: 4 additions & 3 deletions functions/categories/libs/queries.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import os
import json
from google.cloud import firestore
from google.cloud.firestore_v1.base_query import FieldFilter
from .result import Result
from .utils import convert_to_array

DB = firestore.Client(project=os.environ.get('PROJECT'), database=os.environ.get('DATABASE'))
TABLE = 'categories'

def list_data(params):
ref = DB.collection(u'categories')
ref = DB.collection(TABLE)

query = ref

Expand All @@ -27,7 +28,7 @@ def list_data(params):
category_array = convert_to_array(params['category'])

for category in category_array:
results = query.where("category", "==", category).stream()
results = query.where(filter=FieldFilter("category", "==", category)).stream()
for doc in results:
data.append(doc.to_dict())

Expand Down
36 changes: 16 additions & 20 deletions functions/cwvtech/libs/queries.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,31 @@
import os
import json
from google.cloud import firestore
from google.cloud.firestore_v1.base_query import FieldFilter
from .result import Result
from .utils import convert_to_array

DB = firestore.Client(project=os.environ.get('PROJECT'), database=os.environ.get('DATABASE'))
TABLE = 'core_web_vitals'

def list_data(params):
ref = DB.collection(u'core_web_vitals')
technology_array = convert_to_array(params['technology'])
data = []

query = ref

if 'start' in params:
query = query.where('date', '>=', params['start'])
if 'end' in params:
query = query.where('date', '<=', params['end'])

if 'geo' in params:
query = query.where('geo', '==', params['geo'])
for technology in technology_array:
query = DB.collection(TABLE)

if 'technology' in params:
params_array = convert_to_array(params['technology'])
query = query.where('technology', 'in', params_array)
if 'start' in params:
query = query.where(filter=FieldFilter('date', '>=', params['start']))
if 'end' in params:
query = query.where(filter=FieldFilter('date', '<=', params['end']))

if 'rank' in params:
query = query.where('rank', '==', params['rank'])
query = query.where(filter=FieldFilter('geo', '==', params['geo']))
query = query.where(filter=FieldFilter('rank', '==', params['rank']))
query = query.where(filter=FieldFilter('technology', '==', technology))

documents = query.stream()
documents = query.stream()

data = []
for doc in documents:
data.append(doc.to_dict())
for doc in documents:
data.append(doc.to_dict())

return Result(result=data)
17 changes: 9 additions & 8 deletions functions/lighthouse/libs/queries.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
import os
import json
from google.cloud import firestore
from google.cloud.firestore_v1.base_query import FieldFilter
from .result import Result
from .utils import convert_to_array

DB = firestore.Client(project=os.environ.get('PROJECT'), database=os.environ.get('DATABASE'))
TABLE = 'lighthouse'

def list_data(params):

technology_array = convert_to_array(params['technology'])
data = []

for technology in technology_array:
query = DB.collection(u'lighthouse')
query = DB.collection(TABLE)

if 'start' in params:
query = query.where('date', '>=', params['start'])
query = query.where(filter=FieldFilter('date', '>=', params['start']))
if 'end' in params:
query = query.where('date', '<=', params['end'])
query = query.where(filter=FieldFilter('date', '<=', params['end']))

query = query.where('geo', '==', params['geo'])
query = query.where('rank', '==', params['rank'])
query = query.where('technology', '==', technology)
query = query.where(filter=FieldFilter('geo', '==', params['geo']))
query = query.where(filter=FieldFilter('rank', '==', params['rank']))
query = query.where(filter=FieldFilter('technology', '==', technology))

documents = query.stream()

for doc in documents:
data.append(doc.to_dict())

return Result(result=data)
return Result(result=data)

0 comments on commit 5445dda

Please sign in to comment.