Skip to content

Commit 0a0a059

Browse files
committed
changes in technologies reports
1 parent 4028b4b commit 0a0a059

File tree

4 files changed

+66
-6
lines changed

4 files changed

+66
-6
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import os
2+
import json
3+
from google.cloud import firestore
4+
from .result import Result
5+
6+
DB = firestore.Client(project=os.environ.get('PROJECT'))
7+
8+
def list_data(params):
9+
ref = DB.collection(u'technologies')
10+
11+
query = ref
12+
print("params", params)
13+
if 'start' in params:
14+
query = query.where('date', '>=', params['start'])
15+
if 'end' in params:
16+
query = query.where('date', '<=', params['end'])
17+
if 'geo' in params:
18+
query = query.where('geo', '==', params['geo'])
19+
if 'technology' in params:
20+
params_array = json.loads(params['technology'])
21+
query = query.where('technology', 'in', params_array)
22+
if 'rank' in params:
23+
query = query.where('rank', '==', params['rank'])
24+
if 'category' in params:
25+
params_array = json.loads(params['category'])
26+
query = query.where('category', 'in', params_array)
27+
28+
documents = query.stream()
29+
30+
data = []
31+
for doc in documents:
32+
data.append(doc.to_dict())
33+
34+
return Result(result=data)

functions/technologies/libs/utils.py

Lines changed: 0 additions & 2 deletions
Large diffs are not rendered by default.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from .result import Result
2+
3+
class Validator():
4+
def __init__(self, params):
5+
self.params = params
6+
self.errors = []
7+
self.normalizer_params = self.normalize(params)
8+
9+
def validate(self):
10+
result = Result(status="ok", result="()")
11+
12+
# if 'geo' not in self.params:
13+
# self.add_error("geo", "missing geo parameters")
14+
15+
return Result(errors=self.errors, result=self.params)
16+
17+
def add_error(self, key, error):
18+
self.errors.append([key, error])
19+
20+
def normalize(self, params):
21+
return ""

functions/technologies/main.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import functions_framework
2-
2+
from .libs.validator import Validator
33
from .libs.utils import output
4-
from .libs.utils import ( TECHNOLOGIES )
5-
from .libs.result import Result
4+
from .libs.queries import list_data
65

76
@functions_framework.http
87
def dispatcher(request):
8+
args = request.args.to_dict()
9+
10+
validator = Validator(params=args)
11+
result = validator.validate()
12+
13+
if result.failure():
14+
print("error", result.errors)
15+
return output(result)
916

10-
response = Result(result=TECHNOLOGIES)
17+
response = list_data(result.result)
1118

1219
return output(response)

0 commit comments

Comments
 (0)