function CreateOverview() {
var ss = SpreadsheetApp.openById("<document id>");
var oview = ss.getSheetByName("Overview");
var mechs = ss.getSheetByName("Mech Data");
oview.clear();
// Set up formats
oview.setFrozenRows(2);
oview.setFrozenColumns(1);
var header = oview.getRange(1,1,1,25);
header.setFontWeight("bold");
header.setFontLine("underline");
header.setHorizontalAlignment("center");
header.setVerticalAlignment("center");
var col1 = oview.getRange("A1:A999");
col1.setFontStyle("italic");
col1.setFontWeight("bold");
col1.setHorizontalAlignment("center");
col1.setVerticalAlignment("center");
// Set the two header rows (Column names and totals)
oview.appendRow(["Games (≥N)", // A
"Mechs", // B
"Matches", // C
"Wins", // D
"Losses", // E
"WL Ratio", // F
"Kills", // G
"Deaths", // H
"KD Ratio", // I
"Damage Done", // J
"XP Earned", // K
"Time Played", // L
"Dmg / Match", // M
"Avg Kills", // N
"Dmg / Kill", // O
"XP / Match", // P
"XP / Second", // Q
"Time / Mech", // R
"Time / Match", // S
"Win %", // T
"Time Played (seconds)" // U
]);
oview.appendRow(["Totals",
"=COUNTIF('Mech Data'!B2:B999,\">0\")", // Mechs
"=SUM('Mech Data'!B2:B999)", // Matches
"=SUM('Mech Data'!C2:C999)", // Wins
"=SUM('Mech Data'!D2:D999)", // Losses
"=ROUND(D2/E2,2)", // Win/Loss Ratio
"=SUM('Mech Data'!F2:F999)", // Kills
"=SUM('Mech Data'!G2:G999)", // Deaths
"=ROUND(G2/H2,2)", // Kill/Death Ratio
"=SUM('Mech Data'!I2:I999)", // Damage done
"=SUM('Mech Data'!J2:J999)", // XP earned
"=SUM('Mech Data'!K2:K999)", // Hours played
"=ROUND(J2/C2,2)", // Average Damage / Match
"=ROUND(G2/C2,2)", // Average Kills / Match
"=ROUND(J2/G2,2)", // Average Damage / Kill
"=ROUND(K2/C2,2)", // Average XP / Match
"=ROUND(K2/U2,2)", // Average XP / Second
"=L2/B2", // Average Time / Mech
"=L2/C2", // Average Time / Match
"=D2/C2", // Winning percentage
"=L2*24*60*60" // Time played (seconds)
]);
var oFormat = [["#,#","#,#","#,#","#,#","0.00","#,#","#,#","0.00","#,#","#,#","[hh]:mm:ss","0.00","0.00","0.00","0.00","0.00","[hh]:mm:ss","[hh]:mm:ss","0.00%","#"]];
var tRow = oview.getRange("B2:U2");
tRow.setNumberFormats(oFormat);
tRow.setHorizontalAlignment("center");
tRow.setVerticalAlignment("center");
// Get the maximum number of matches played for a mech
var max = 0;
var mCount = 0;
for (var i = 2; i < mechs.getMaxRows()+1; ++i) {
var val = mechs.getRange(i,2,1,1).getValue();
if (val == "") {
break;
}
mCount++;
if (val > max) {
max = val;
}
}
var numRows = max / 25;
var realRows = 0;
for (realRows = 0; realRows <= numRows; ++realRows) { }
var lPos = oview.getLastRow() + 1;
var rPos = oview.getLastRow();
var fRow = oview.getRange("B"+rPos+":BA"+rPos);
for (var r = realRows; r > 1; --r) {
// =sumif('Mech Data'!B1:B988,TEXT((A3-1),">000"),'Mech Data'!F1:F988)
var min = (r-1) * 25 - 1;
var max = r * 25;
lPos = oview.getLastRow() + 1;
oview.appendRow([(min+1)+" - "+max,
"=COUNTIFS('Mech Data'!B2:B999,\">"+min+"\",'Mech Data'!B2:B999,\"<"+max+"\")",
"=SUMIFS('Mech Data'!B2:B999,'Mech Data'!B2:B999,\">"+min+"\",'Mech Data'!B2:B999,\"<"+max+"\")",
"=SUMIFS('Mech Data'!C2:C999,'Mech Data'!B2:B999,\">"+min+"\",'Mech Data'!B2:B999,\"<"+max+"\")",
"=SUMIFS('Mech Data'!D2:D999,'Mech Data'!B2:B999,\">"+min+"\",'Mech Data'!B2:B999,\"<"+max+"\")",
"=ROUND(D"+lPos+"/E"+lPos+",2)",
"=SUMIFS('Mech Data'!F2:F999,'Mech Data'!B2:B999,\">"+min+"\",'Mech Data'!B2:B999,\"<"+max+"\")",
"=SUMIFS('Mech Data'!G2:G999,'Mech Data'!B2:B999,\">"+min+"\",'Mech Data'!B2:B999,\"<"+max+"\")",
"=ROUND(G"+lPos+"/H"+lPos+",2)",
"=SUMIFS('Mech Data'!I2:I999,'Mech Data'!B2:B999,\">"+min+"\",'Mech Data'!B2:B999,\"<"+max+"\")",
"=SUMIFS('Mech Data'!J2:J999,'Mech Data'!B2:B999,\">"+min+"\",'Mech Data'!B2:B999,\"<"+max+"\")",
"=SUMIFS('Mech Data'!K2:K999,'Mech Data'!B2:B999,\">"+min+"\",'Mech Data'!B2:B999,\"<"+max+"\")",
"=ROUND(J"+lPos+"/C"+lPos+",2)",
"=ROUND(G"+lPos+"/C"+lPos+",2)",
"=ROUND(J"+lPos+"/G"+lPos+",2)",
"=ROUND(K"+lPos+"/C"+lPos+",2)",
"=ROUND(K"+lPos+"/U"+lPos+",2)",
"=L"+lPos+"/B"+lPos,
"=L"+lPos+"/C"+lPos,
"=D"+lPos+"/C"+lPos,
"=L"+lPos+"*24*60*60"
]);
rPos = oview.getLastRow();
fRow = oview.getRange("B"+rPos+":U"+rPos);
fRow.setNumberFormats(oFormat);
fRow.setHorizontalAlignment("center");
fRow.setVerticalAlignment("center");
}
lPos = oview.getLastRow() + 1;
oview.appendRow(["<25",
"=COUNTIF('Mech Data'!B2:B999,\"<25\")",
"=SUMIF('Mech Data'!B2:B999,\"<25\",'Mech Data'!B2:C999)",
"=SUMIF('Mech Data'!B2:B999,\"<25\",'Mech Data'!C2:C999)",
"=SUMIF('Mech Data'!B2:B999,\"<25\",'Mech Data'!D2:D999)",
"=ROUND(D"+lPos+"/E"+lPos+",2)",
"=SUMIF('Mech Data'!B2:B999,\"<25\",'Mech Data'!F2:F999)",
"=SUMIF('Mech Data'!B2:B999,\"<25\",'Mech Data'!G2:G999)",
"=ROUND(G"+lPos+"/H"+lPos+",2)",
"=SUMIF('Mech Data'!B2:B999,\"<25\",'Mech Data'!I2:I999)",
"=SUMIF('Mech Data'!B2:B999,\"<25\",'Mech Data'!J2:J999)",
"=SUMIF('Mech Data'!B2:B999,\"<25\",'Mech Data'!K2:K999)",
"=ROUND(J"+lPos+"/C"+lPos+",2)",
"=ROUND(G"+lPos+"/C"+lPos+",2)",
"=ROUND(J"+lPos+"/G"+lPos+",2)",
"=ROUND(K"+lPos+"/C"+lPos+",2)",
"=ROUND(K"+lPos+"/U"+lPos+",2)",
"=L"+lPos+"/B"+lPos,
"=L"+lPos+"/C"+lPos,
"=D"+lPos+"/C"+lPos,
"=L"+lPos+"*24*60*60"
]);
fRow = oview.getRange("B"+lPos+":U"+lPos);
fRow.setNumberFormats(oFormat);
fRow.setHorizontalAlignment("center");
fRow.setVerticalAlignment("center");
for (var i = 1; i < 20; ++i) {
oview.autoResizeColumn(i);
}
oview.hideColumns(21); // Hide everything to the right of the data
}