def process_tracked_yield(minIONdict):
    """
    This function maintains a history of all yield values over the time of a run - it can be configured to store yields
    at given intervals. It is used by the main web page to provide a history of cumulative yield.
    """
    for minion in minIONdict:
        if 'detailsdata' in minIONdict[minion]:
            if 'livedata' in minIONdict[minion]:
                if 'yield_res' in minIONdict[minion]['livedata']:
                    if 'result' in minIONdict[minion]['livedata']['yield_res']:
                        try:
                            asictemp = float(minIONdict[minion][
                                'detailsdata']['engine_states'][
                                'minion_asic_temperature'])
                        except:
                            asictemp = 0
                        try:
                            heatsinktemp = float(minIONdict[minion][
                                'detailsdata']['engine_states'][
                                'minion_heatsink_temperature'])
                        except:
                            heatsinktemp = 0
                        if minIONdict[minion]['livedata']['bias_voltage_gain'][
                            'result'] != 'null':
                            biasvoltage = int(minIONdict[minion]['livedata'
                                ]['bias_voltage_gain']['result'])
                        else:
                            biasvoltage = 0
                        if minIONdict[minion]['livedata']['biasvoltageget'][
                            'result'] != 'null':
                            voltage_val = int(minIONdict[minion]['livedata'
                                ]['biasvoltageget']['result']['bias_voltage'])
                        else:
                            voltage_val = 0
                        voltage_value = voltage_val * biasvoltage
                        try:
                            if minIONdict[minion]['livedata']['yield_res'][
                                'result'] != 'null':
                                yieldval = int(minIONdict[minion][
                                    'livedata']['yield_res']['result'])
                            else:
                                yieldval = minIONdict[minion]['detailsdata'][
                                    'statistics']['read_event_count']
                        except:
                            yieldval = 0
                        try:
                            meanratio = minIONdict[minion]['detailsdata'][
                                'meanratio']
                            openpore = minIONdict[minion]['detailsdata'][
                                'openpore']
                            instrand = minIONdict[minion]['detailsdata'][
                                'instrand']
                        except:
                            meanratio = 0
                            openpore = 0
                            instrand = 0
                        if 'yield_history' not in minIONdict[minion]:
                            minIONdict[minion]['yield_history'] = []
                        if 'temp_history' not in minIONdict[minion]:
                            minIONdict[minion]['temp_history'] = dict()
                        if 'pore_history' not in minIONdict[minion]:
                            minIONdict[minion]['pore_history'] = dict()
                        if 'meanratio_history' not in minIONdict[minion][
                            'pore_history']:
                            minIONdict[minion]['pore_history'][
                                'meanratio_history'] = []
                            minIONdict[minion]['pore_history'][
                                'openpore_history'] = []
                            minIONdict[minion]['pore_history'][
                                'instrand_history'] = []
                        if 'strand' not in minIONdict[minion]['pore_history']:
                            minIONdict[minion]['pore_history']['strand'] = []
                            minIONdict[minion]['pore_history']['percent'] = []
                            minIONdict[minion]['pore_history']['single'] = []
                        if 'asictemp' not in minIONdict[minion]['temp_history'
                            ]:
                            minIONdict[minion]['temp_history']['asictemp'] = []
                            minIONdict[minion]['temp_history']['heatsinktemp'
                                ] = []
                            minIONdict[minion]['temp_history']['voltage'] = []
                        strand = 0
                        single_pore = 0
                        if 'simplesummary' in minIONdict[minion]:
                            if 'strand' in minIONdict[minion]['simplesummary'
                                ].keys():
                                strand = float(minIONdict[minion][
                                    'simplesummary']['strand'])
                            if 'single_pore' in minIONdict[minion][
                                'simplesummary'].keys():
                                single_pore = float(minIONdict[minion][
                                    'simplesummary']['single_pore'])
                            elif 'good_single' in minIONdict[minion][
                                'simplesummary'].keys():
                                single_pore = float(minIONdict[minion][
                                    'simplesummary']['good_single'])
                        if strand + single_pore > 0:
                            percent = strand / (strand + single_pore) * 100
                        else:
                            percent = 0
                        if len(minIONdict[minion]['yield_history']) > 1:
                            if yieldval > minIONdict[minion]['yield_history'][
                                -1][1]:
                                minIONdict[minion]['yield_history'].append((
                                    minIONdict[minion]['detailsdata'][
                                    'timestamp'] * 1000, yieldval))
                            minIONdict[minion]['temp_history']['asictemp'
                                ].append((minIONdict[minion]['detailsdata']
                                ['timestamp'] * 1000, asictemp))
                            minIONdict[minion]['temp_history']['voltage'
                                ].append((minIONdict[minion]['detailsdata']
                                ['timestamp'] * 1000, voltage_value))
                            minIONdict[minion]['temp_history']['heatsinktemp'
                                ].append((minIONdict[minion]['detailsdata']
                                ['timestamp'] * 1000, heatsinktemp))
                            minIONdict[minion]['pore_history']['strand'
                                ].append((minIONdict[minion]['detailsdata']
                                ['timestamp'] * 1000, strand))
                            minIONdict[minion]['pore_history']['percent'
                                ].append((minIONdict[minion]['detailsdata']
                                ['timestamp'] * 1000, percent))
                            minIONdict[minion]['pore_history']['single'
                                ].append((minIONdict[minion]['detailsdata']
                                ['timestamp'] * 1000, single_pore))
                            minIONdict[minion]['pore_history'][
                                'meanratio_history'].append((minIONdict[
                                minion]['detailsdata']['timestamp'] * 1000,
                                meanratio))
                            minIONdict[minion]['pore_history'][
                                'openpore_history'].append((minIONdict[
                                minion]['detailsdata']['timestamp'] * 1000,
                                openpore))
                            minIONdict[minion]['pore_history'][
                                'instrand_history'].append((minIONdict[
                                minion]['detailsdata']['timestamp'] * 1000,
                                instrand))
                            if 'simplesummary' in minIONdict[minion]:
                                if 'details' not in minIONdict[minion][
                                    'pore_history'].keys():
                                    minIONdict[minion]['pore_history'][
                                        'details'] = dict()
                                for state in minIONdict[minion]['simplesummary'
                                    ].keys():
                                    if state not in minIONdict[minion][
                                        'pore_history']['details'].keys():
                                        minIONdict[minion]['pore_history'][
                                            'details'][state] = []
                                    minIONdict[minion]['pore_history'][
                                        'details'][state].append((
                                        minIONdict[minion]['detailsdata'][
                                        'timestamp'] * 1000, minIONdict[
                                        minion]['simplesummary'][state]))
                        else:
                            minIONdict[minion]['yield_history'].append((
                                minIONdict[minion]['detailsdata'][
                                'timestamp'] * 1000, yieldval))
                            minIONdict[minion]['temp_history']['asictemp'
                                ].append((minIONdict[minion]['detailsdata']
                                ['timestamp'] * 1000, asictemp))
                            minIONdict[minion]['temp_history']['heatsinktemp'
                                ].append((minIONdict[minion]['detailsdata']
                                ['timestamp'] * 1000, heatsinktemp))
                            minIONdict[minion]['temp_history']['voltage'
                                ].append((minIONdict[minion]['detailsdata']
                                ['timestamp'] * 1000, voltage_value))
                            minIONdict[minion]['pore_history']['strand'
                                ].append((minIONdict[minion]['detailsdata']
                                ['timestamp'] * 1000, strand))
                            minIONdict[minion]['pore_history']['percent'
                                ].append((minIONdict[minion]['detailsdata']
                                ['timestamp'] * 1000, percent))
                            minIONdict[minion]['pore_history']['single'
                                ].append((minIONdict[minion]['detailsdata']
                                ['timestamp'] * 1000, single_pore))
                            minIONdict[minion]['pore_history'][
                                'meanratio_history'].append((minIONdict[
                                minion]['detailsdata']['timestamp'] * 1000,
                                meanratio))
                            minIONdict[minion]['pore_history'][
                                'openpore_history'].append((minIONdict[
                                minion]['detailsdata']['timestamp'] * 1000,
                                openpore))
                            minIONdict[minion]['pore_history'][
                                'instrand_history'].append((minIONdict[
                                minion]['detailsdata']['timestamp'] * 1000,
                                instrand))
                            if 'simplesummary' in minIONdict[minion]:
                                if 'details' not in minIONdict[minion][
                                    'pore_history'].keys():
                                    minIONdict[minion]['pore_history'][
                                        'details'] = dict()
                                for state in minIONdict[minion]['simplesummary'
                                    ].keys():
                                    if state not in minIONdict[minion][
                                        'pore_history']['details'].keys():
                                        minIONdict[minion]['pore_history'][
                                            'details'][state] = []
                                    minIONdict[minion]['pore_history'][
                                        'details'][state].append((
                                        minIONdict[minion]['detailsdata'][
                                        'timestamp'] * 1000, minIONdict[
                                        minion]['simplesummary'][state]))
                else:
                    minIONdict[minion]['yield_history'] = []
                    minIONdict[minion]['temp_history']['asictemp'] = []
                    minIONdict[minion]['temp_history']['heatsinktemp'] = []
                    minIONdict[minion]['temp_history']['voltage'] = []
                    minIONdict[minion]['pore_history']['strand'] = []
                    minIONdict[minion]['pore_history']['percent'] = []
                    minIONdict[minion]['pore_history']['single'] = []
                    minIONdict[minion]['pore_history']['openpore_history'] = []
                    minIONdict[minion]['pore_history']['instrand_history'] = []
                    minIONdict[minion]['pore_history']['meanratio_history'] = [
                        ]
                    if 'details' in minIONdict[minion]['pore_history']:
                        minIONdict[minion]['pore_history'].pop('details')
