//First we get some info to add to the measurement table
var tcode = session.info.transaction;
var flavorId = session.info.flavorId;
//We call the function module to get the timestamp, this is because SAPGUI doesn't support the Date object
var rfc = session.createRFC("ZPERSONAS_ANALYTICS_GET_TIMEST");
rfc.requestResults(JSON.stringify(["ES_TIMESTAMP"]));
rfc.send();
var timestampStruc = JSON.parse(rfc.getResult("ES_TIMESTAMP"));
//We store the info in the session to be used in a later script
session.utils.put("tcode", ""+tcode);
session.utils.put("flavorId", flavorId);
session.utils.put("time.start", ""+timestampStruc.TIMESTAMP);
//First we get the timestamp for when we end the transaction
var rfc2 = session.createRFC("ZPERSONAS_ANALYTICS_GET_TIMEST");
rfc2.requestResults(JSON.stringify(["ES_TIMESTAMP"]));
rfc2.send();
var timestampStruc2 = JSON.parse(rfc2.getResult("ES_TIMESTAMP"));
var timestop = timestampStruc2.TIMESTAMP;
var timestart = parseFloat(session.utils.get("time.start"));
var tcode = session.utils.get("tcode");
var flavorId = session.utils.get("flavorId");
//Get the timedifference between the start and stop.
var timeelapsed = timestop - timestart;
// Name information, which is required
var firstDataName = 'currentApplication';
var secondDataName = 'currentScreen';
var thirdDataName = 'currentFlavor';
// Get required information
var firstDataValue = session.info.transaction;
var secondDataValue = session.info.screenNumber;
var thirdDataValue = session.info.flavorId;
// Combine appropriate name and information into data
var nameValueSeparator = ':';
var firstData = firstDataName.concat(nameValueSeparator, firstDataValue);
var secondData = secondDataName.concat(nameValueSeparator, secondDataValue);
var thirdData = thirdDataName.concat(nameValueSeparator, thirdDataValue);
// Combine all data into one string
var dataSeparator = ',';
var measurement = JSON.stringify({tcode : tcode, flavor : flavorId, timestart : timestart, timestop : timestop, timeelapsed : timeelapsed});
var measurementData = 'tcode:' +tcode +',flavor:' +flavorId +',timestart:' +timestart +',timestop:' +timestop +',timeelapsed:' +timeelapsed;
// Call RFC
var oRFC = session.createRFC("Z_PERSONAS_GUI_MEASURE");
oRFC.setParameter("IV_MSPNT_ID", 'TIMEINTRANSACTIONGUI'); // setting the measuring point parameter
oRFC.setParameter("IV_MS_DATA", measurementData);
oRFC.send();
session.findById("wnd[0]/tbar[0]/btn[11]").press();
//Get the table
var selectedTable = session.findById("wnd[0]/usr/cntlGRID_CONTAINER/shellcont/shell");
//Get the Column IDs
var columns = selectedTable.columns;
//Variable where table contents will be copied
var contents = [];
if (selectedTable.rowCount > 0) {
//Set the visible row to 0
selectedTable.firstVisibleRow = 0;
//Get the Max visible row number
var topRow = selectedTable.visibleRowCount - 1;
//Loop through all the rows
for (var rowIndex = 0; rowIndex < selectedTable.rowCount; rowIndex++) {
var row = {};
if (rowIndex > topRow) {
// Set the first visible row to the next set of rows. If the next set goes beyond the maximum rows,
// adjust it so that the set's last row is the table's last row.
if (topRow + selectedTable.visibleRowCount > selectedTable.rowCount) {
selectedTable.firstVisibleRow = selectedTable.rowCount - selectedTable.visibleRowCount;
} else {
selectedTable.firstVisibleRow = topRow + 1;
}
topRow += selectedTable.visibleRowCount;
}
// Populate the row information.
for (var i = 0; i < columns.length; i++) {
var colName = columns.elementAt(i).name;
row[colName] = selectedTable.getCellValue(rowIndex, colName);
}
// Break after the first blank row - the values usually contain all underscores like "____" for a 4 character column.
if (!row[columns.elementAt(3).name].replace(/_/g, "")) {
break;
}
contents.push(row);
}
}
for (var i = 0; i < contents.length; i++){
var sum = 0;
for (var c = 0; c < contents.length; c++){
sum = sum + parseFloat(contents[c].TIMEELAPSED);
}
var Average = sum / contents.length;
console.log(Average);
contents[i].AVERAGE = Average;
contents[i].DATETIME = contents[i].DATE +" " + contents[i].TIME;
}
var chartHTML = '<html> <head>';
chartHTML += '<script id="sap-ui-bootstrap"'
chartHTML += 'type="text/javascript"'
chartHTML +='src="/sap/public/bc/ui5_ui5/1/resources/sap-ui-cachebuster/sap-ui-core.js"'
chartHTML +='data-sap-ui-theme="sap_goldreflection"'
chartHTML +='data-sap-ui-libs="sap.ui.core,sap.ui.commons,sap.viz">'
chartHTML +='</script>';
chartHTML +='<script>';
// some business data
chartHTML += 'var oModel = new sap.ui.model.json.JSONModel({businessData:' + JSON.stringify(contents) + '});';
// A Dataset defines how the model data is mapped to the chart
chartHTML += ' var oDataset = new sap.viz.ui5.data.FlattenedDataset({\
dimensions : [ \
{\
axis : 1, \
name : "Date", \
value : "{DATETIME}"\
} \
],\
measures : [ \
{\
name : "Time", \
value : "{TIMEELAPSED}" \
},\
{\
name : "Average", \
value : "{AVERAGE}" \
}\
],\ data : {\
path : "/businessData"\
}\
});';
// create a Donut chart
/*chartHTML += ' var oBarChart = new sap.viz.ui5.Combination({\
width : "100%",\
height : "200px",\
plotArea : {\
dataLabel: {\
visible: true \
}\
},\
title : {\
visible : true,\
text : "Measurement Point graph"\
},\
valueAxis: { \
title: { \
visible: true\
} \
}, \
categoryAxis: { \
title: { \
visible: true \
} \
},\
dataset : oDataset\
});';
*/
chartHTML += ' var oVizFrameCol = new sap.viz.ui5.controls.VizFrame({ \
height : "400px", \
width : "100%", \
vizType : "combination", \
}); \
oVizFrameCol.setVizProperties({ \
title : { \
visible :"true", \
text : "Measurement Point chart" \
} \
}); \
oVizFrameCol.setDataset(oDataset); \
oVizFrameCol.setModel(oModel);\
var feedPrimaryValuesc = new sap.viz.ui5.controls.common.feeds.FeedItem({ \
"uid" : "valueAxis", \
"type" : "Measure", \
"values" : ["Time", "Average"] \
}); \
var feedAxisLabelsc = new sap.viz.ui5.controls.common.feeds.FeedItem({ \
"uid" : "axisLabels", \
"type" : "Dimension", \
"values" : ["Date"] \
}); \
oVizFrameCol.addFeed(feedPrimaryValuesc); \
oVizFrameCol.addFeed(feedAxisLabelsc); \
var oPopoverc = new sap.viz.ui5.controls.Popover({}); \
oPopoverc.connect(oVizFrameCol.getVizUid()); \
oVizFrameCol.setVizProperties({\
plotArea: { \
dataLabel: { \
visible: true \
} \
} \
}); \
oVizFrameCol.placeAt("content"); ';
// attach the model to the chart and display it
/*chartHTML += ' oBarChart.setModel(oModel);\
oBarChart.placeAt("content");';
*/
chartHTML += '</script>';
chartHTML += '</head>';
chartHTML += '<body class="sapUiBody" supportedthemes="sap_corbu" role="application">';
chartHTML += '<div id="content"></div>'
chartHTML += '</body></html>';
session.findById("wnd[0]/usr/htmlViewerPersonas_147381051051473").content = chartHTML;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 | |
2 |