src/py/aggregators/csvaggregator.py
def appendToDemoCSV(destinationPath:str,data:SessionData, modulesById:Dict[str, ModuleBase], batchNum:int, adtlParams:Dict = None)->AggregatorReturn:
    """Main Aggregator function that writes some information about the processed image into a growing CSV file"""

    #Open the file and read current data
    created = False
    try:
        with open(destinationPath, newline='') as csvfile:
            reader = csv.reader(csvfile, delimiter=',', quotechar='"')
            rows = [r for r in reader]
        #check if row exists and store its index
        rnum = [i for i,r in enumerate(rows) if r[0] == str(batchNum)]
    except:
        created = True
        rnum = []
        rows = [__getTitleRow()]


    #Get data to write into CSV - very simple here. But we can communicate via modulesById Parameter with any intiated module
    #in the current pipeline and ask it to provide information/generate data.
    img = data.getData('Processed Image')
    newRow = [batchNum, img.shape[1], img.shape[0], np.mean(img)]
    overwritten = False

    if len(rnum) > 0:#row exists we need to replace it
        rows[int(rnum[0])] = newRow
        overwritten = True
    else: #append the new batch
        rows += [newRow]

    #overwrite existing file with new data
    with open(destinationPath, 'w', newline='') as csvfile:
        wr = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
        # write rows, which include header
        for r in rows: wr.writerow(r)



    #Generate some information for the user (will be displayed in a toast in the export aggregate screen).
    if overwritten and not created:
        msg = 'Overwritten batch %d results in dataset: Currently %d entries. '%(batchNum, len(rows)-1)
    elif not created:
        msg = 'Added batch %d results to dataset. Currently %d entries. '%(batchNum, len(rows) - 1)
    else:
        msg = 'Created file and added results from batch %d.'%(batchNum)

    ret = AggregatorReturn(msg, __getInfo(rows))
Main Aggregator function that writes some information about the processed image into a growing CSV file
Main Aggregator function that writes some information about the processed image into a growing CSV file
Main Aggregator function that writes some information about the processed image into a growing CSV file
def appendToDemoCSV(destinationPath:str,data:SessionData, modulesById:Dict[str, ModuleBase], batchNum:int, adtlParams:Dict = None)->AggregatorReturn:
    created = False
    try:
        with open(destinationPath, newline='') as csvfile:
            reader = csv.reader(csvfile, delimiter=',', quotechar='"')
            rows = [r for r in reader]
        rnum = [i for i,r in enumerate(rows) if r[0] == str(batchNum)]
    except:
        created = True
        rnum = []
        rows = [__getTitleRow()]
    img = data.getData('Processed Image')
    newRow = [batchNum, img.shape[1], img.shape[0], np.mean(img)]
    overwritten = False
    if len(rnum) > 0:
        rows[int(rnum[0])] = newRow
        overwritten = True
    else: 
        rows += [newRow]
    with open(destinationPath, 'w', newline='') as csvfile:
        wr = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
        for r in rows: wr.writerow(r)
    if overwritten and not created:
        msg = 'Overwritten batch %d results in dataset: Currently %d entries. '%(batchNum, len(rows)-1)
    elif not created:
        msg = 'Added batch %d results to dataset. Currently %d entries. '%(batchNum, len(rows) - 1)
    else:
        msg = 'Created file and added results from batch %d.'%(batchNum)
    ret = AggregatorReturn(msg, __getInfo(rows))
def appendToDemoCSV ( destinationPath : str , data : SessionData , modulesById : Dict [ str , ModuleBase ] , batchNum : int , adtlParams : Dict = None ) -> AggregatorReturn : created = False try : with open ( destinationPath , newline = '' ) as csvfile : reader = csv . reader ( csvfile , delimiter = ',' , quotechar = '"' ) rows = [ r for r in reader ] rnum = [ i for i , r in enumerate ( rows ) if r [ 0 ] == str ( batchNum ) ] except : created = True rnum = [ ] rows = [ __getTitleRow ( ) ] img = data . getData ( 'Processed Image' ) newRow = [ batchNum , img . shape [ 1 ] , img . shape [ 0 ] , np . mean ( img ) ] overwritten = False if len ( rnum ) > 0 : rows [ int ( rnum [ 0 ] ) ] = newRow overwritten = True else : rows += [ newRow ] with open ( destinationPath , 'w' , newline = '' ) as csvfile : wr = csv . writer ( csvfile , delimiter = ',' , quotechar = '"' , quoting = csv . QUOTE_MINIMAL ) for r in rows : wr . writerow ( r ) if overwritten and not created : msg = 'Overwritten batch %d results in dataset: Currently %d entries. ' % ( batchNum , len ( rows ) - 1 ) elif not created : msg = 'Added batch %d results to dataset. Currently %d entries. ' % ( batchNum , len ( rows ) - 1 ) else : msg = 'Created file and added results from batch %d.' % ( batchNum ) ret = AggregatorReturn ( msg , __getInfo ( rows ) )
Main Aggregator function that writes some information about the processed image into a growing CSV file
Main Aggregator function that writes some information about the processed image into a growing CSV file
"""Main Aggregator function that writes some information about the processed image into a growing CSV file""" #Open the file and read current data #check if row exists and store its index #Get data to write into CSV - very simple here. But we can communicate via modulesById Parameter with any intiated module #in the current pipeline and ask it to provide information/generate data. #row exists we need to replace it #append the new batch #overwrite existing file with new data # write rows, which include header #Generate some information for the user (will be displayed in a toast in the export aggregate screen).
destinationPath
str
data
SessionData
modulesById
Dict[str, ModuleBase]
batchNum
int
adtlParams
Dict