def generateDataset(aggregationInfo, inputFilename, outputFilename=None):
<EOL>inputFullPath = resource_filename("<STR_LIT>", inputFilename)<EOL>inputObj = FileRecordStream(inputFullPath)<EOL>aggregator = Aggregator(aggregationInfo=aggregationInfo,<EOL>inputFields=inputObj.getFields())<EOL>if aggregator.isNullAggregation():<EOL><INDENT>return inputFullPath<EOL><DEDENT>if outputFilename is None:<EOL><INDENT>outputFilename = '<STR_LIT>' %os.path.splitext(os.path.basename(inputFullPath))[<NUM_LIT:0>]<EOL>timePeriods = '<STR_LIT>''<STR_LIT>'<EOL>for k in timePeriods.split():<EOL><INDENT>if aggregationInfo.get(k, <NUM_LIT:0>) > <NUM_LIT:0>:<EOL><INDENT>outputFilename += '<STR_LIT>' % (k, aggregationInfo[k])<EOL><DEDENT><DEDENT>outputFilename += '<STR_LIT>'<EOL>outputFilename = os.path.join(os.path.dirname(inputFullPath), outputFilename)<EOL><DEDENT>lockFilePath = outputFilename + '<STR_LIT>'<EOL>if os.path.isfile(outputFilename) oros.path.isfile(lockFilePath):<EOL><INDENT>while os.path.isfile(lockFilePath):<EOL><INDENT>print('<STR_LIT>' %lockFilePath)<EOL>time.sleep(<NUM_LIT:1>)<EOL><DEDENT>return outputFilename<EOL><DEDENT>lockFD = open(lockFilePath, '<STR_LIT:w>')<EOL>outputObj = FileRecordStream(streamID=outputFilename, write=True,<EOL>fields=inputObj.getFields())<EOL>while True:<EOL><INDENT>inRecord = inputObj.getNextRecord()<EOL>(aggRecord, aggBookmark) = aggregator.next(inRecord, None)<EOL>if aggRecord is None and inRecord is None:<EOL><INDENT>break<EOL><DEDENT>if aggRecord is not None:<EOL><INDENT>outputObj.appendRecord(aggRecord)<EOL><DEDENT><DEDENT>return outputFilename<EOL>
Generate a dataset of aggregated values

    Parameters:
    ----------------------------------------------------------------------------
    aggregationInfo: a dictionary that contains the following entries
      - fields: a list of pairs. Each pair is a field name and an
        aggregation function (e.g. sum). The function will be used to aggregate
        multiple values during the aggregation period.

    aggregation period: 0 or more of unit=value fields; allowed units are:
          [years months] |
          [weeks days hours minutes seconds milliseconds microseconds]
          NOTE: years and months are mutually-exclusive with the other units.
                See getEndTime() and _aggregate() for more details.
          Example1: years=1, months=6,
          Example2: hours=1, minutes=30,
          If none of the period fields are specified or if all that are specified
          have values of 0, then aggregation will be suppressed, and the given
          inputFile parameter value will be returned.

    inputFilename: filename of the input dataset within examples/prediction/data

    outputFilename: name for the output file. If not given, a name will be
          generated based on the input filename and the aggregation params

    retval: Name of the generated output file. This will be the same as the input
        file name if no aggregation needed to be performed



    If the input file contained a time field, sequence id field or reset field
    that were not specified in aggregationInfo fields, those fields will be
    added automatically with the following rules:

    1. The order will be R, S, T, rest of the fields
    2. The aggregation function for all will be to pick the first: lambda x: x[0]

      Returns: the path of the aggregated data file if aggregation was performed
        (in the same directory as the given input file); if aggregation did not
        need to be performed, then the given inputFile argument value is returned.