def RLCSimulationOneType(folderName, inputType, unit, approachName, houseNumber, randomFlag):
    '''
    This method used to constructed yaml files, and it will make sure each file only has one kind of requests.
        
    '''
    
    # read CSV input files
    Result = ReadCSV(folderName, inputType)
    requests = list(Result[0])
    
    ideal_type_load = modify_ideal_load(Result[1][-1], unit)
    
    # write load profile files
    RLCSimulate.getLoadProfileFiles(folderName, unit)
        
    # get house layout and zip_loads
    houseLayout = yamlCalcMethods.getHouseLayout(houseNumber, requests)
    S_ZipList = yamlCalcMethods.getSZipList(len(houseLayout))
    lengthMvList = yamlCalcMethods.getLengthMvList(len(houseLayout))
    
    # get the load, which not perform RLC approach
    original_loads = RLCSimulate.getOriginalObservedLoad(Result, unit, approachName)
    
    # get the relationship between request name, and its last minute number
    requestNameMinMap = yamlCalcMethods.getRequestNameMinMap(requests) # get the requestNameMinMap
    
    # write yaml file, and return RLC result
    random_observed_loads = writeYamlFileAndReturnRandomProbabilitiesOneRequest(Result, houseNumber, requests, unit, folderName, approachName, houseLayout, requestNameMinMap, S_ZipList, lengthMvList)
    
    # write the csv file which save original and RLC loads
    write_output(ideal_type_load, original_loads, random_observed_loads, folderName, inputType, randomFlag)
    
    print 'FINISH Random Output'
def getRequestStartTimeList(request, generateHouseNum, unit):
    """
    This method used to get the start time list of a request, then return a list with these times.
    typical, the time here is a string with format as: '09:45:00'.
        [request, request, ...], int, int => [time, time, ...]
    """

    yamlCalcMethods.getPureProbabilities(request)  # update the new probabilities which used to random

    startList = [0] * len(request.pure_probabilities)  # this list will save the numbers which represent to start time

    RLCSimulate.getRandomStartList(request, startList, generateHouseNum)

    startTimeList = yamlCalcMethods.getStartTime(startList, request, unit)  # get the start time with the time style

    return startTimeList
def getApplianceMapOneRequest(repeatNumber, requests, unit):
    '''
    This method used to return a map which only contains one request, and its start time list.
        
    '''
    
    returnMap = {}
    
    for request in requests:
        
        if request.quantity != 0:
            if request.quantity - repeatNumber >= 0:
                generateHouseNum = repeatNumber
                requestStartTimeList = RLCSimulate.getRequestStartTimeList(request, generateHouseNum, unit)
                request.minus_quantity(generateHouseNum)
            else:
                generateHouseNum = request.quantity
                requestStartTimeList = RLCSimulate.getRequestStartTimeList(request, generateHouseNum, unit)
                request.minus_quantity(generateHouseNum)
        
            returnMap[request.request_type.request_name] = requestStartTimeList
            tempResult = [returnMap, generateHouseNum]
        
            return tempResult
def writeYamlFileAndReturnRandomProbabilitiesOneRequest(Result, houseNumber, requests, unit, folderName, approachName, houseLayout, requestNameMinMap, S_ZipList, lengthMvList):
    '''
    This method used to constructed yaml file and return load information, and each yaml file only had one kind of request.
        
    '''
    
    fileCount = 0
    totalRequestNumber = yamlLargeHouseNumber.getTotalRequestNumber(requests)
    restRequestNumber = int(totalRequestNumber)
    createdRequestNum = 0
    
    while restRequestNumber != 0:
        
        if restRequestNumber < houseNumber:
            repeatNumber = restRequestNumber
        else:
            repeatNumber = houseNumber
            
        fileName = ''.join(('CSVdata/', folderName, '/resident/' 'resident_', folderName, '_', str(fileCount), '.yaml'))
        
        tempResult = getApplianceMapOneRequest(repeatNumber, requests, unit) # get the start time and request name dict
        
        applianceMap = tempResult[0]
        usedNumber = int(tempResult[1])
        
        
        writeFile = open(fileName, 'w')
        
        yamlWriteMethods.writeConstParameters(writeFile)
        
        yamlWriteMethods.writeHouseLayout(writeFile, houseLayout)
        
        yamlWriteMethods.writeVariableList(writeFile, houseLayout, S_ZipList, lengthMvList)
        
        yamlWriteMethods.writeConstSimulation(writeFile) 
        
        yamlWriteMethods.writeConstNetwork(writeFile) 
    
        yamlWriteMethods.writeConstHeartbeat(writeFile) 
    
        yamlWriteMethods.writeTimeSerialLoop(writeFile, applianceMap, folderName) # write load / time_series content
    
        yamlWriteMethods.writeConstBus(writeFile)
    
        yamlWriteMethods.writeConstGenericgen(writeFile)
    
        yamlWriteMethods.writeConstLoop(writeFile)
    
        applianceCount = 0
        
        yamlWriteMethods.writeAllAppliance(houseLayout, writeFile, applianceMap, applianceCount, requestNameMinMap)
    
        writeFile.close()
        
        
        print 'FileCount is:',
        print fileCount
        for key in applianceMap.keys():
            print key,
            print len(applianceMap[key])
        
        deleteRequests = RLCSimulate.setNewRequests(requests) # delete the request which quantity is zero
        
        fileCount = fileCount + 1
        restRequestNumber = restRequestNumber - usedNumber
        createdRequestNum = createdRequestNum + usedNumber
    
    print 'created request number is: ',
    print createdRequestNum
    
    deleteRequests = RLCSimulate.setTempProbabilitiesToProbabilities(deleteRequests)
    
    ## get the RLC random result
    random_observed_load = RLCSimulate.calculateExpectedLoad(requests, unit) # get observed load
    
    ## get output relative parameters
    random_observed_loads = [random_observed_load] 
    
    return random_observed_loads