Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7c4c50c
Latest version copied to anamailyan fork
anamailyan Mar 17, 2019
bbc1397
Change db user
anamailyan Mar 17, 2019
c39a5d8
More details to project
anamailyan Mar 17, 2019
fe154ec
Adding fields from HPFS data and some ifs to test nulls
anamailyan Mar 18, 2019
1cd9037
Merging with upstream
anamailyan Mar 19, 2019
9a528bb
Adding schema changes
anamailyan Mar 19, 2019
e232d1f
Reverting to clean version without ifs
anamailyan Mar 19, 2019
b63f67d
Typo fix
anamailyan Mar 19, 2019
d7dc041
open and close db connection/cursor
anamailyan Mar 20, 2019
9341bd2
Adding HPFS fields to schema
anamailyan Mar 21, 2019
1cc4318
Typo fix
anamailyan Mar 21, 2019
00de047
Adding couple missing fields to Metadata
anamailyan Mar 21, 2019
fdfffe6
reverting to front page only on dev branch
anamailyan Mar 21, 2019
253198b
reverting to front page changes only on dev
anamailyan Mar 21, 2019
13095a8
reverting to front page changes only on dev
anamailyan Mar 21, 2019
0c79410
reverting to front page changes only on dev
anamailyan Mar 21, 2019
9952cbf
reverting to front page changes only on dev
anamailyan Mar 21, 2019
95db21d
Fix typo
anamailyan Mar 22, 2019
bf15322
Making count queries union
anamailyan Mar 23, 2019
f9b47c6
adding version to schema
anamailyan Mar 23, 2019
4704a87
function name change
anamailyan Mar 23, 2019
94ed77c
Adding command to set env var for password
anamailyan Mar 23, 2019
a81be3f
adding init and exit for db conn open and close
anamailyan Mar 25, 2019
0eef992
Using connection pool, c extension, pulling version from db and using…
anamailyan Mar 27, 2019
a2bd028
Fixing typo
anamailyan Mar 27, 2019
ffa8ce1
fixing white space
anamailyan Mar 27, 2019
9c96015
Removing spaces
anamailyan Mar 27, 2019
829e51d
moving pool creation and closing out of fetch
anamailyan Mar 27, 2019
f884da3
32 pools is too much, setting 10
anamailyan Mar 27, 2019
e8f18cd
placing pool creation in fetch_results and fixing version
anamailyan Mar 28, 2019
e3e2826
comments added
anamailyan Mar 29, 2019
d50b49c
Moving queries to dbqueries.py
anamailyan Apr 2, 2019
ece3f26
Remove all but front page queries
anamailyan Apr 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ then run
1. ``CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';``
2. ``GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' WITH GRANT OPTION;``
3. ``flush privileges;``

More information https://dev.mysql.com/doc/refman/5.5/en/adding-users.html
4. Set environment variable BIOM_MASS that holds user's password
``export BIOM_MASS="password"``

load_local_database.py script needs mysql.connect module.

Expand Down
62 changes: 58 additions & 4 deletions database.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,56 @@

# Calls to obtain values from the data structures (to be populated by the local database next)

import mysql.connector
from mysql.connector import pooling
import os
import dbqueries
import const

# add increment for aggregations
def add_key_increment(dictionary, key):
if not key in dictionary:
dictionary[key]=0
dictionary[key]+=1

class Data(object):

def __init__(self):
self.conn_pool = mysql.connector.connect(use_pure=False, pool_name="portal",
pool_size=10,
pool_reset_session=True,
database='portal_ui',
user='biom_mass',
password=os.environ['BIOM_MASS'])

def __exit__(self):
self.conn_pool.close()

# get connection from pool
def get_pool(self):
conn = mysql.connector.connect(pool_name="portal")
cursor = conn.cursor(buffered=True,dictionary=True)
return conn, cursor

# release connection back to pool
def release_pool(self,conn,cursor):
cursor.close()
conn.close()

# runs query and returns results
def fetch_results(self,query):
conn,cursor=self.get_pool()
cursor.execute(query)
data=[row for row in cursor]
self.release_pool(conn,cursor)
return data

# get current version from db
def get_current_version(self):
version_data=self.fetch_results(dbqueries.version_query)
del version_data[0]['updated']
del version_data[0]['id']
return version_data[0]


def load_data(self):
self.data = const.DB()

Expand Down Expand Up @@ -78,9 +120,21 @@ def get_project_aggregations(self, projects):

return project_aggregates


# get all counts for front page summary from db
def get_current_counts(self):
self.load_data()
return self.data.CURRENT_COUNTS
import schema

counts_data = self.fetch_results(dbqueries.all_counts_query)

return schema.Count(
projects=counts_data[0]['total'],
participants=counts_data[1]['total'],
samples=counts_data[2]['total'],
dataFormats=counts_data[3]['total'],
rawFiles=counts_data[4]['total'],
processedFiles=counts_data[5]['total'])


def get_file_aggregations(self, files):
import schema
Expand Down
9 changes: 9 additions & 0 deletions dbqueries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file holds all queries run in database.py
all_counts_query='''select count(id) as total from project
union all select count(id) as total from participant
union all select count(id) as total from sample
union all select count(distinct data_format) as total from file_sample
union all select count(id) as total from file_sample where type="rawFiles"
union all select count(id) as total from file_sample where type="processedFiles"'''

version_query="select * from version order by updated desc limit 1"
4 changes: 2 additions & 2 deletions load_local_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def parse_arguments(args):
required=False)
parser.add_argument(
"--key-file",
default="biom-mass-fdcadb440fdf.json",
default="/home/hutlab_public/compute_engine_service_account_key/biom-mass-8dc9ab934396.json",
help="google project service account private key file path\n]",
required=False)
parser.add_argument(
Expand Down Expand Up @@ -256,7 +256,7 @@ def main():
new_version = str(0.1)

now = datetime.datetime.now()
release_date ="Date Release "+new_version+" "+ now.strftime("%b %d, %Y")
release_date ="Data Release "+new_version+" - "+ now.strftime("%b %d, %Y")
commit ="commit_"+now.strftime("%m%d%Y")
query_insert_version ='''INSERT INTO `version` (
commit,
Expand Down
2 changes: 1 addition & 1 deletion schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,5 +427,5 @@ def resolve_samples(self, info, namespace, workspace):
json_result = query_firecloud.call_api(url)
obj_result = utilities.json2obj(json.dumps(json_result))
return obj_result



6 changes: 5 additions & 1 deletion server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
import os

import flask
import flask_cors
import flask_graphql
import graphene

import schema
import const
from database import data

NAME = "firecloud_graphql"
HOST = "0.0.0.0"
Expand All @@ -41,6 +43,8 @@ def process_query(request, schema):
def main():
# create the graphql flask app
app = flask.Flask(NAME)
# allow initial OPTIONS requests
flask_cors.CORS(app)

# add the root graphql queries
@app.route('/graphql', methods=["POST"])
Expand All @@ -55,7 +59,7 @@ def get_schema(name):
# add static endpoint for version/status
@app.route('/status', methods=["GET"])
def get_version():
return flask.jsonify(const.VERSION)
return flask.jsonify(data.get_current_version())

# add end point for graphql gui
app.add_url_rule('/test', view_func=flask_graphql.GraphQLView.as_view(
Expand Down