refactor a bit

This commit is contained in:
Kelly McDonald 2020-12-03 08:44:15 -05:00
parent 92aa1b971d
commit 0e8913434a
1 changed files with 12 additions and 28 deletions

View File

@ -267,33 +267,16 @@ def join_uuids(uuids):
# in the same order # in the same order
return hashlib.md5(combined_uuids.encode('utf8')).hexdigest() # make a hash of the hashes return hashlib.md5(combined_uuids.encode('utf8')).hexdigest() # make a hash of the hashes
@cross_origin() # allow all cross origin requests so we can hit it with a dev box
def get_all_spec_state(): def get_all_spec_state():
# big_nasty_sql = """ df = get_all_spec_state_dataframe()
# return df.reset_index().to_json(orient='records')
# with first as (
# select file_model_id,version,max(version) over (partition by file_model_id) maxversion,f def get_all_spec_state_dataframe():
# .name, """
# workflow_spec_id,date_created,md5_hash Return a list of all workflow specs along with last updated date and a
# from file f join file_data fd on fd. thumbprint of all of the files that are used for that workflow_spec
# file_model_id = f.id """
# where workflow_spec_id is not null
# order by workflow_spec_id,file_model_id,version desc),
# second as (select name,workflow_spec_id,date_created,md5_hash from first
# where maxversion = version)
# select row_to_json(t) workflow_spec_state
# from (
# select workflow_spec_id,max(date_created) last_update,md5(max(
# (
# select array_to_json(array_agg(row_to_json(d)))
# from (select name,md5_hash from second where second.workflow_spec_id = second2.workflow_spec_id) d
#
# )::text)) as files_hash
# from second as second2
# group by 1
# ) t
# """
# json_results = []
# result = db.engine.execute(big_nasty_sql)
x = session.query(FileDataModel).join(FileModel) x = session.query(FileDataModel).join(FileModel)
# there might be a cleaner way of getting a data frome from some of the # there might be a cleaner way of getting a data frome from some of the
@ -315,8 +298,9 @@ def get_all_spec_state():
# workflow spec # workflow spec
df = df.groupby('workflow_spec_id').agg({'date_created':'max', df = df.groupby('workflow_spec_id').agg({'date_created':'max',
'md5_hash':join_uuids}).copy() 'md5_hash':join_uuids}).copy()
df = df[['date_created','md5_hash']].copy()
df['date_created'] = df['date_created'].astype('str')
df = df.reset_index()[['workflow_spec_id','date_created','md5_hash']].copy()
return df.to_json(orient='records') return df