Páginas

2011/05/28

How to create a compatibility list with google spreadsheet?

http://dpspemu.blogspot.com/p/compatibility.html

HOW THIS WORKS?


This is a google spreadsheet with a form vinculated to a sheet

The other sheet gets the information of the form results and locates the max version per gameId showing only the results for the lastests version of the emulator per each game. After that it order the list with the date added descending so it will show first the lastest updates. Also it generates a chart with the Status column.

It should be updated automatically every 5 minutes.

HOW DID YOU DO THAT?


I have made the following function for google spreadsheets. Maybe it is too simple, but it is enough for creating a compatibility list successfully.

function groupByAndMaxSorted(list, uniqueColumn, maxColumn, sortColumn) {
  var list2 = [];
  for (var n = 0; n < list.length; n++) {
    var row = list[n];
    var prevRow = list2[row[uniqueColumn]];
    var prevMax = (prevRow !== undefined) ? prevRow[maxColumn] : undefined;
    var currentMax = row[maxColumn];
    if (prevMax === undefined || currentMax > prevMax) {
      list2[row[uniqueColumn]] = row;
    }
  }
  var list3 = [];
  for (var k in list2) {
    list3.push(list2[k]);
  }
  list3.sort(function(a, b) {
    return b[sortColumn] - a[sortColumn];
  });
  return list3;
}

No comments:

Post a Comment