解决Google Apps脚本中的“限制超出的DriveApp”

时间:2018-03-19 14:23:48

标签: google-apps-script google-sheets

我遇到的问题是我在处理电子表格时遇到了一定的配额。我每天处理一堆电子表格,当我添加一个新的系统来发送我的谷歌脚本更多的电子表格进行处理时,我收到错误:

  

限制超出DriveApp

它结束的行总是orderedCsv.getBlob().getDataAsString();其中orderedCsv是当前的电子表格。

我的问题是  1.我可以打哪个配额?  2.如何查看当前的配额使用情况?

我认为它可能是属性读/写超过,因为我导入的原始数据可能是3000-9000行数据。

它给我的错误记录是:

Error Transcript Pastebin

function ps_csvsToSheet ( currSheet, sheetCsvs, csvDict, sheetN, sheetOrderIndex){
  // import csvs into the sheet with formatting 
  lib_formatSheet(currSheet);

  var row = 39;
  var orderedCsv; 
  // loop for importing CSVs into one sheet in the order we want~~~~~~
  for (var i = 0; i < ps_statOrdering.length; i++) {
    // loop through all the sheets stored in a dictionary we created before
    for (var j = 0; j < sheetCsvs.length; j++) {
      var sheetName = sheetCsvs[j].getName();
      // additional test to ensure Draw chart  and not DrawCall 
      if ( ps_statOrdering[i] == 'Draw') {  
        if ( sheetName.indexOf(ps_statOrdering[i]) !== -1 && sheetName.indexOf('DrawCalls') == -1) {
          orderedCsv = sheetCsvs[j];
          break;
        }
      } else if ( sheetName.indexOf(ps_statOrdering[i]) !== -1) {
        orderedCsv = sheetCsvs[j];
        break;
    }
  }

  try{
    // import the csvs for spreadsheet
    var strData = orderedCsv.getBlob().getDataAsString(); //**********[Line it ends on]***********
    var importedData = lib_importCSV(row+1, 1, strData, currSheet);
  }
  catch(error) {
    Logger.log("Catch Error : " + error);
    return
  }
  // make formatting [][] for the importedData. Here we are working off
  // of pre-knowledge of what is expected 
  var nRows = importedData['rows'];
  var nCols = importedData['cols'];
  var c;
  var weightArr = new Array(nRows);
  var numFormatArr = new Array(nRows);
  for (var r = 0; r < nRows; r++) {  
    weightArr[r] = new Array(nCols);
    numFormatArr[r] = new Array(nCols);
    if (r == 0) {
      c = nCols;
      while(c--) { 
        weightArr[r][c] = "bold"; 
        numFormatArr[r][c] = '';
      }
    } else {
      c = nCols;
      while(c--) { 
        weightArr[r][c] = "normal"; 
        numFormatArr[r][c] = '0.00';
      }
      weightArr[r][0] =  "bold";
      numFormatArr[r][0] = '';
      if( sheetOrderIndex !== -1) {
        numFormatArr[r][0] =  'MMM.dd';
      }
    }
  }
  importedData['range'].setFontWeights(weightArr)
                       .setNumberFormats(numFormatArr);

   //Create the header of the sheet
   lib_inputSheetHeader(currSheet, row, nCols, (sheetN + " " + ps_statOrdering[i] 
   + " Averages"), ps_profileColors[0]) ;
  // insert appropriate graph 
  var key = ps_statOrdering[i];
  if( sheetOrderIndex !== -1) {
    // this is a setting trend sheet, line chart
    lib_makeLineChart(importedData['range'], ps_statLocDict[key][0], ps_statLocDict[key][1],
                  (sheetN + " " + ps_statOrdering[i] ), currSheet, 
                  ps_statVRange[key][0], ps_statVRange[key][1], ps_statAxisDict[key]);
  } else { 
    // this is a map sheet, bar chart  
    // debugPrint(importedData['range'].getValues().toString());
    lib_makeBarChart(importedData['range'], ps_statLocDict[key][0], ps_statLocDict[key][1],
                 (sheetN + " " + ps_statOrdering[i] ), currSheet, 
                 ps_statVRange[key][0], ps_statVRange[key][1], ps_statAxisDict[key]);
  }     
  row += importedData['rows'] +2;
  } // for loop close, import csv ~~~~  
  sleep(1000);
  SpreadsheetApp.flush();
}

1 个答案:

答案 0 :(得分:0)

所以我所做的是我用熊猫将很多计算卸载到了python。这样,我可以导入已经预先格式化的数据表,并在google中对其进行一些操作以节省执行时间。

由于必须执行特定的数据操作,所以我用来完成此工作的代码有点大。这是在python中完成的代码的快速摘要:

import pandas as pd
import numpy as np                        #used in case of needing np.NAN in our data

class DataProcessing():

    def __init__(self):
        rawData = pd.DataFrame.from_csv( **<enter path to csv>** )

        #From here i would run operations on the dataframe named rawdata
        #until the data frame matched what i needed it to look like.
        #PyCharm is a python IDE that can help you visualize the data frame 
        #through break points.

        #After im done modifying my dataframe i sent it to my google drive.
        #If you download google drive to your PC you can send it to a folder
        #in your PC that will auto sync files to your google drive.
        rawData.to_csv(os.path.join(**<GoogleFolder Path>**, csvName))

一开始学习熊猫有点棘手,但这是帮助我正确修改数据的资源。

https://github.com/pandas-dev/pandas/blob/master/doc/cheatsheet/Pandas_Cheat_Sheet.pdf

帮助这有帮助!