Skip to content

Commit

Permalink
contest: backend: add trivial query
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
kuba-moo committed May 18, 2024
1 parent 65ac327 commit c6c37de
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
62 changes: 62 additions & 0 deletions contest/backend/query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0


from flask import Flask
from flask import request
import couchdb
import os


app = Flask("NIPA contest query")

user = os.getenv('DB_USER')
pwd = os.getenv('DB_PWD')
couch = couchdb.Server(f'http://{user}:{pwd}@127.0.0.1:5984')


@app.route('/')
def hello():
return '<h1>boo!</h1>'


@app.route('/results')
def results():
global couch

br_cnt = request.args.get('branches')
if not br_cnt:
return {}

return_rows = []
seen_br = set()
offset = 0
done = False
while not done:
rows = couch["results"].find({
"selector": {},
"sort": [
{
"branch": "desc"
}
],
"skip": offset,
"limit": 100
})
offset += 100

done |= not list(rows)

for row in rows:
if row['branch'] not in seen_br:
if len(seen_br) == br_cnt:
done = True
break
seen_br.add(row['branch'])
return_rows.append(row)

return return_rows


if __name__ == "__main__":
app.run(host='0.0.0.0')
2 changes: 1 addition & 1 deletion contest/results-fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def insert_wip(self, remote, run):
else:
data['_id'] = uuid.uuid4().hex
data["remote"] = remote["name"]
when = datetime.datetime.fromisoformat(branch_info[run['branch']]['date'])
when = datetime.datetime.fromisoformat(branch_info['date'])
data["start"] = str(when)
when += datetime.timedelta(hours=2, minutes=58)
data["end"] = str(when)
Expand Down

0 comments on commit c6c37de

Please sign in to comment.