Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var competitionId = 534; // http://api.etf2l.org/competition/list
- var tier = 1 // 0 = prem, 1 = high etc
- var app = SpreadsheetApp.getActiveSpreadsheet();
- var shLogs = app.getSheetByName('Logs');
- function onOpen() {
- app.getUi()
- .createMenu('logs.tf Importer')
- .addItem('Import Logs', 'importLogs')
- .addToUi();
- }
- function importLogs() {
- }
- function getMaxOfArray(numArray) {
- return Math.max.apply(null, numArray);
- }
- function createLogSpreadsheet() {
- var jsonResultPages = ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/results.json', '/page/total_pages', 'noHeaders')[0][0];
- var jsonMatchPages = ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/matches.json', '/page/total_pages', 'noHeaders')[0][0];
- var clan1Id = [];
- var clan1Name= [];
- var clan2Id =[];
- var clan2Name = [];
- var skillLevel = [];
- var week = [];
- var map = [];
- for (var i = 1; i<=jsonResultPages; ++i) {
- clan1Id = clan1Id.concat(ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/results/' + i + '.json', '/results/clan1/id', 'noHeaders'));
- clan1Name = clan1Name.concat(ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/results/' + i + '.json', '/results/clan1/name', 'noHeaders'));
- clan2Id = clan2Id.concat(ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/results/' + i + '.json', '/results/clan2/id', 'noHeaders'));
- clan2Name = clan2Name.concat(ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/results/' + i + '.json', '/results/clan2/name', 'noHeaders'));
- skillLevel = skillLevel.concat(ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/results/' + i + '.json', '/results/division/tier', 'noHeaders'));
- week = week.concat(ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/results/' + i + '.json', '/results/week', 'noHeaders'));
- map = map.concat(ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/results/' + i + '.json', '/results/maps', 'noHeaders'));
- }
- for (var i = 1; i<=jsonMatchPages; ++i) {
- clan1Id = clan1Id.concat(ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/matches/' + i + '.json', '/matches/clan1/id', 'noHeaders'));
- clan1Name = clan1Name.concat(ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/matches/' + i + '.json', '/matches/clan1/name', 'noHeaders'));
- clan2Id = clan2Id.concat(ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/matches/' + i + '.json', '/matches/clan2/id', 'noHeaders'));
- clan2Name = clan2Name.concat(ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/matches/' + i + '.json', '/matches/clan2/name', 'noHeaders'));
- skillLevel = skillLevel.concat(ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/matches/' + i + '.json', '/matches/division/tier', 'noHeaders'));
- week = week.concat(ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/matches/' + i + '.json', '/matches/week', 'noHeaders'));
- map = map.concat(ImportJSON('http://api.etf2l.org/competition/' + competitionId + '/matches/' + i + '.json', '/matches/maps', 'noHeaders'));
- }
- var numMatches = clan1Id.length;
- var matches = [];
- for (var i = 0; i < numMatches; ++i) {
- var match = {};
- match["homeID"] = clan1Id[i];
- match["homeName"] = clan1Name[i];
- match["awayID"] = clan2Id[i];
- match["awayName"] = clan2Name[i];
- match["skillLevel"] = skillLevel[i];
- match["week"] = week[i];
- match["map"] = map[i];
- matches.push(match);
- }
- var weekNumber = getMaxOfArray(week);
- var tierMatches = matches.filter(function(match) {return match.skillLevel == tier;});
- var weekMatches = [];
- shLogs.getRange(1,2).setValue('Home Link');
- shLogs.getRange(1,3).setValue('Home Name');
- shLogs.getRange(1,4).setValue('Away Link');
- shLogs.getRange(1,5).setValue('Away Name');
- shLogs.getRange(1,6).setValue('Map(s)');
- for (var w = 0; w < weekNumber; w++) {
- weekMatches[w] = tierMatches.filter(function(match) {return match.week == (+w + +1);});
- }
- var row = 1;
- for (var w = 0; w < 5; w++) {
- shLogs.getRange(row,1).setValue('Week ' + (+w + +1)); //set week title
- row += 1;
- for (i = 0; i < weekMatches[w].length; i++, row++) {
- shLogs.getRange(row,2).setValue("http://etf2l.org/teams/" + weekMatches[w][i].homeID);
- shLogs.getRange(row,3).setValue(weekMatches[w][i].homeName);
- shLogs.getRange(row,4).setValue("http://etf2l.org/teams/" + weekMatches[w][i].awayID);
- shLogs.getRange(row,5).setValue(weekMatches[w][i].awayName);
- shLogs.getRange(row,6).setValue(weekMatches[w][i].map);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement