diff --git a/qcms-manifest.json b/qcms-manifest.json index 32fdd22..59f7e26 100644 --- a/qcms-manifest.json +++ b/qcms-manifest.json @@ -34,7 +34,7 @@ "index": "index.html", "on": { "load": { - "pane": [ + "studio-menu": [ "www/html/menu.html" ], "studio-intro":["www/html/about.html"] diff --git a/www/html/_assets/css/studio.css b/www/html/_assets/css/studio.css index 3612d1b..284174b 100644 --- a/www/html/_assets/css/studio.css +++ b/www/html/_assets/css/studio.css @@ -7,13 +7,43 @@ .studio { display:grid; - grid-template-rows: 50px 200px auto 48px; gap:8px; + grid-template-rows: 50px 200px auto 48px; + gap:8px; +} +.studio-index { + display:grid; + grid-template-columns: auto 25%; + gap:4px; + +} +.menu-2 { + display:grid; width:48px; + grid-template-rows: repeat(6,50px); + gap:8px; - } +.menu-2 .item { + + display:grid; align-items: center; + +} +.studio-index .menu-2 { + display:none ; +} +.studio-index .menu-1 { + display:block; +} +.studio-index-collapsed { + display:grid; + grid-template-columns: auto 50px; + gap:8px; +} +.studio-index-collapsed .menu-1{ display:none} +.studio-index-collapsed .menu-2 {display:grid;} + .studio-dialog { width:650px; } @@ -56,6 +86,7 @@ background-color: #F3F3F3; padding:4px; display:grid; grid-template-columns: 50px auto 40%; gap:8px; align-items: center; + } .studio .control .border-left {border-left:1px solid #FFFFFF;} diff --git a/www/html/_assets/js/studio.js b/www/html/_assets/js/studio.js index 3406db4..f03b20a 100644 --- a/www/html/_assets/js/studio.js +++ b/www/html/_assets/js/studio.js @@ -199,7 +199,7 @@ studio.frame = function (_args){ var _label = _args.label var uri = [studio._context,'api/transport/apply'] uri = uri.join('/') - if (_args.AI && sessionStorage.AI){ + if (_args.AI && sessionStorage.AI !="0"){ uri = uri.replace(/transport/g,'agent') } @@ -220,7 +220,7 @@ studio.frame = function (_args){ }else{ _compute(_label,_r.data) var _id = '.code.'+_args.label.trim() - $(_id).val($(_id).val() + '\n'+_r['query']) + $(_id).val('-- '+$(_id).val().replace(/\n/g,'-- ') + '\n'+_r['query']) } sessionStorage[_label] = _query @@ -301,6 +301,9 @@ studio.frame = function (_args){ } }) }) + if (spreadsheet.chartColl.length > 0){ + _rows ['charts'] = spreadsheet.chartColl + } if (_rows ){ http.setHeader('Content-Type','application/json') http.setData (JSON.stringify({rows:_rows,'label':_label})) @@ -433,7 +436,8 @@ studio.frame = function (_args){ _query = studio.defaults[_args.provider] if (sessionStorage[_args.label]) { - _query = ('-- '+_query.replace(/\n/g,' ')+'\n') + sessionStorage[_args.label] + // _query = ('-- '+_query.replace(/\n/g,' ')+'\n') + sessionStorage[_args.label] + _query = sessionStorage[_args.label] } $(_textarea).val(_query) } @@ -457,6 +461,8 @@ studio.frame = function (_args){ _id = `.${_id} code` this.compute() + $('.jxmodal').remove() + } @@ -476,4 +482,14 @@ studio.frame = function (_args){ } -} \ No newline at end of file +} + + +studio.menu = {} +studio.menu.collapse = function (){ + $('.studio-index').removeClass('studio-index').addClass('studio-index-collapsed') +} +studio.menu.expand = function (){ + $('.studio-index-collapsed').removeClass('studio-index-collapsed').addClass('studio-index') +} + diff --git a/www/html/_assets/themes/default/layout.css b/www/html/_assets/themes/default/layout.css index c0d713e..d6bb234 100644 --- a/www/html/_assets/themes/default/layout.css +++ b/www/html/_assets/themes/default/layout.css @@ -13,7 +13,7 @@ display:grid; - + grid-column: 1 / span 2; /* display:grid; grid-template-columns: 100%; diff --git a/www/html/_assets/themes/default/pane.css b/www/html/_assets/themes/default/pane.css index 9322c03..e612728 100644 --- a/www/html/_assets/themes/default/pane.css +++ b/www/html/_assets/themes/default/pane.css @@ -3,7 +3,7 @@ height:auto; gap:8px; grid-row:2 / span 3 ; grid-column:2 ; - +display:none; } .main .pane iframe{ width:100%; border:0px; height:80%;} diff --git a/www/html/_plugins/agent.py b/www/html/_plugins/agent.py index 0cb7a6e..61c8f7e 100644 --- a/www/html/_plugins/agent.py +++ b/www/html/_plugins/agent.py @@ -66,6 +66,7 @@ Guidelines: - If the question can not be answered with the provided schema return empty string in the sql attribute - Parse the question word by word so as to be able to identify tables, fields and operations associated (Joins, filters ...) - Under no circumstances will you provide an explanation of tables or reasoning detail. +- Avoid using subqueries, and use field names as represented in the provided schema and their data types question: {question} @@ -115,6 +116,7 @@ def AIProxy (_label,_query,_path,_CATALOG) : # # we should run the command here, assuming a valid query # + _data = _qreader.apply(_query) except Exception as e: # @@ -139,11 +141,15 @@ def AIProxy (_label,_query,_path,_CATALOG) : _about = f"The queries will run on {_provider} database.\n{_about}" r = _agent.toSQL(_query,_catalog, _about) - _data = _qreader.apply(r['sql']) + try: + _data = _qreader.apply(r['sql']) + except Exception as e1: + _data = pd.DataFrame() + pass # # returning the data and the information needed # - _data = _data.to_dict(orient='split') + _data = _data.astype(str).to_dict(orient='split') del _data['index'] if r : return {'data':_data,'query':r['sql']} diff --git a/www/html/_plugins/io.py b/www/html/_plugins/io.py index d738e1e..d1646fe 100644 --- a/www/html/_plugins/io.py +++ b/www/html/_plugins/io.py @@ -77,15 +77,19 @@ def write(**_args) : # # convert this to a spreadsheet _excelFile = BytesIO() - with pd.ExcelWriter(_excelFile, engine='openpyxl') as writer: + with pd.ExcelWriter(_excelFile, engine='xlsxwriter') as writer: _index = 1 for _name in _rows : _sheet = _rows[_name] - _df = pd.DataFrame(_sheet['values'],columns=_sheet['columns']) - - _df.to_excel(writer,sheet_name=_name,index=False) + try: + _df = pd.DataFrame(_sheet['values'],columns=_sheet['columns']) + _df.to_excel(writer,sheet_name=_name,index=False) + except Exception as e: + print (_name) + print (_sheet) _index += 1 - + if 'chart' in _rows : + print (_rows['chart']) # Write each DataFrame to a different sheet _excelFile.seek(0) _stream= _excelFile.read() #send_file(_excelFile,as_attachment=True,download_name=f'{_label}-export.xlsx', mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') diff --git a/www/html/index.html b/www/html/index.html index a75c21b..4ff6a72 100644 --- a/www/html/index.html +++ b/www/html/index.html @@ -66,7 +66,11 @@ }) -