Untitled

 avatar
unknown
plain_text
a year ago
2.0 kB
4
Indexable
Currently I am accessing like this on client side
 f"Tests Queue Statistics:\nNumber of tests ahead in QUEUE:{resp.json()['status_statistics'][0]} \nNumber of tests SCHEDULED:{resp.json()['status_statistics'][1]} \nNumber of tests STARTING:{resp.json()['status_statistics'][2]} \nNumber of tests IN_PROGRESS:{resp.json()['status_statistics'][3]} \nURL to Grafana Dashboard: https://g-e479d6ef8a.grafana-workspace.us-west-2.amazonaws.com/d/GXuswQq4z/performance-test-results?orgId=1&from=now-5m&to=now&var-internal_workflow_id={resp.json()['test-id']}"

But It's a bad practice to call variables using fix list index, this lead to bad readability. So, as I am creating a dictionary on server side I want to create another dict under [status_statistics] so I can access and do somwthing like this on client side resp.json()['status_statistics']['starting']

My server side code
def get_existing_tests_status_summary(self):
        query = f"SELECT " \
                f"SUM(CASE WHEN {WORKFLOW_COLUMNS['status'][0]} = 'QUEUE' THEN 1 ELSE 0 END) AS queue_result, " \
                f"SUM(CASE WHEN {WORKFLOW_COLUMNS['status'][0]} = 'SCHEDULED' THEN 1 ELSE 0 END) AS scheduled_result, " \
                f"SUM(CASE WHEN {WORKFLOW_COLUMNS['status'][0]} = 'STARTING' THEN 1 ELSE 0 END) AS starting_result, " \
                f"SUM(CASE WHEN {WORKFLOW_COLUMNS['status'][0]} = 'IN_PROGRESS' THEN 1 ELSE 0 END) AS in_progress_result " \
                f"FROM {WORKFLOW_TABLE_NAME};"

        results = self.db.execute_dql_query(query)["results"][0]
        return results

which is being called here
def get_status_statistics(self):
        status_statistics = self.__result_db_handler.get_existing_tests_status_summary()
        return status_statistics

and here
status_summary = workflow_initiator.get_status_statistics()

Where can I make this change and how to make this change such that I can access it on server side by resp.json()['status_statistics']['starting']
Editor is loading...
Leave a Comment