<jupyter_start><jupyter_text>Fault Classes | Fault | Binary | Decimal || --- | --- | --- || A | 00 | 0 || B | 01 | 1 || C | 10 | 2 || D | 11 | 3 |  Fault Code = (variable << 2) + fault_class | Fault | Binary | Decimal || --- | --- | --- || A1 | 100 | 4 || B1 | 101 | 5 || C1 | 110 | 6 || D1 | 111 | 7 |  Sample (C1)<jupyter_code>fault = 2
variable = 1
code = (variable << 2) + fault
code<jupyter_output><empty_output><jupyter_text>Reverse<jupyter_code>fault = code & 3
fault
variable = code >> 2
variable<jupyter_output><empty_output><jupyter_text>Current Fault Codes | Fault | Decimal || --- | --- || A1 | 4 || B1 | 5 || C1 | 6 || D1 | 7 || A1B1 | 4-5 || A1C1 | 4-6 || A1D1 | 4-7 || B1C1 | 5-6 || C1D1 | 6-7 |  Flow Chart<jupyter_code>from graphviz import Digraph

dot = Digraph(node_attr={'shape': 'box'}, format='png', filename='sensorfusion')
dot.edge_attr.update(arrowhead='vee', arrowsize='1')

dot.node('0', 'Fault Generator')
dot.node('1', 'Other Faults')
dot.node('2', 'Supervisor (Polling)')
dot.node('3', 'All faults\n processed\n?' ,shape='diamond')
dot.node('4', 'Send trigger signal \n &\n increment frequency')
dot.node('5', 'Append fault')
dot.node('6', 'Does fault\n exist?', shape='diamond')
dot.node('7', 'Remove and delay fault\nwith lower\npriority')
dot.node('8', 'Time\nOut?', shape='diamond')
dot.node('9', 'end', shape='oval')
dot.node('10', 'start', shape='oval')
dot.node('11', 'Delayed Faults')

dot.edge('2', '1')
dot.edge('0', '2', '  Possibility\nof fault')
dot.edge('1', '5', '  Possibility\nof fault')
dot.edge('2', '3')
dot.edge('3', '6', 'Yes')
dot.edge('3', '5', 'No')
dot.edge('4', '8')
dot.edge('5', '6')
dot.edge('6', '4', 'Yes')
dot.edge('6', '7', 'No')
dot.edge('7', '3')
dot.edge('8', '2', 'No')
dot.edge('8', '9', 'Yes')
dot.edge('10', '0')
dot.edge('11', '1')
dot
#dot.save()
#dot.render(view=True)<jupyter_output><empty_output><jupyter_text>Run<jupyter_code>command = "D:/code/C++/RT-Cadmium-FDD-New-Code/top_model/main.exe"
completed_process = subprocess.run(command, shell=False, capture_output=True, text=True)
#print(completed_process.stdout)<jupyter_output><empty_output><jupyter_text>Read from file<jupyter_code>fileName = "SensorFusion.txt"
    
fault_codes = {}
    
with open(fileName, "r") as f:
    lines = f.readlines()
    
with open(fileName, "r") as f:
    output = f.read()
    
for line in lines:
    if (re.search("supervisor", line) != None):
        res = re.findall("\{\d+[, ]*\d*[, ]*\d*\}", line)

        if len(res) > 0:
            str_interest = res[0].replace('}', '').replace('{', '')
            faults = str_interest.split(', ')
            key = '-' + '-'.join(faults) + '-'
            fault_codes[key] = fault_codes.get(key, 0) + 1

generators = {'A': 0, 'B': 0, 'C': 0, 'D': 0}

for key in generators.keys():
    generators[key] = len(re.findall("faultGen" + key, output))
fault_codes<jupyter_output><empty_output><jupyter_text>ANALYSIS / VERIFICATION  Definitions **Pure Fault**: Faults from a single generator.  **Compound Faults**: Faults formed from the combination of pure faults.  Premise Fault $A1$: Should have no discarded entry, because it has the highest priority  Fault $B1$: Should have some discarded value, for the case $BD$, which is not available  Fault $C1$: Higher percentage of discarded cases than $C$, because of its lower priority  Fault $D1$: Highest percentage of discarded cases, because it has the lowest priority   Generator $output_{A1} = n({A1}) + n({A1} \cap {B1}) + n({A1} \cap {C1}) + n({A1} \cap {D1}) + discarded_{A1}$  Generator $output_{B1} = n({B1}) + n({A1} \cap {B1}) + n({B1} \cap {C1}) + discarded_{B1}$  Generator $output_{C1} = n({C1}) + n({A1} \cap {C1}) + n({B1} \cap {C1}) + n({C1} \cap {D1}) + discarded_{C1}$  Generator $output_{D1} = n({D1}) + n({A1} \cap {D1}) + n({C1} \cap {D1}) + discarded_{D1}$  Where $discarded_{A1} \equiv 0$, because A has the highest priority, and $discarded_{B1} = 0$ because B1 has a fault code combination with the others in the right order, using the priority system.<jupyter_code>def sumFromSupervisor(code):
    '''
    Returns the number of times faults associated with a particular pure fault (the parameter) were output by the supervisor

    @param code: int
    @return int
    '''
    sum = 0
    
    for key, value in fault_codes.items():
        if '-' + str(code) + '-' in key:
            sum += value;
            
    return sum;
a_discarded = generators['A'] - sumFromSupervisor(4)
a_discarded
b_discarded = generators['B'] - sumFromSupervisor(5)
b_discarded
c_discarded = generators['C'] - sumFromSupervisor(6)
c_discarded
d_discarded = generators['D'] - sumFromSupervisor(7)
d_discarded
total_discarded = a_discarded + b_discarded + c_discarded + d_discarded
total_discarded
total_generated = generators['A'] + generators['B'] + generators['C'] + generators['D']
total_generated
discarded = {'A': a_discarded, 'B': b_discarded, 'C': c_discarded, 'D': d_discarded}
discarded_percentage = {'A': a_discarded * 100 / total_generated, 'B': b_discarded * 100 / total_generated, 'C': c_discarded * 100 / total_generated, 'D': d_discarded * 100 / total_generated}
discarded_cases
fault_codes
a_increment = generators['A'] - fault_codes['-4-5-'] - fault_codes['-4-6-'] - fault_codes['-4-7-'] - a_discarded
a_increment
b_increment = generators['B'] - fault_codes['-4-5-'] - fault_codes['-5-6-'] - b_discarded
b_increment
c_increment = generators['C'] - fault_codes['-4-6-'] - fault_codes['-5-6-'] - fault_codes['-6-7-'] - c_discarded
c_increment
d_increment = generators['D'] - fault_codes['-4-7-'] - fault_codes['-6-7-'] - d_discarded
d_increment<jupyter_output><empty_output><jupyter_text>Discard Charts<jupyter_code>#plt.title('Discarded Bar')
plt.bar(discarded.keys(), discarded.values())
#plt.show()
plt.savefig('discarded bar.png', format='png')
keys, values = list(discarded.keys()), list(discarded.values())
legend_keys = copy.copy(keys)

for i in range(len(keys)):
     legend_keys[i] = str(legend_keys[i]) + " = " + str(values[i])

# Remove wedgeprops to make pie
wedges, texts = plt.pie(values, textprops=dict(color="w"), wedgeprops=dict(width=0.5))
plt.legend(wedges, legend_keys,
          title="Fault Codes",
          loc="center left",
          bbox_to_anchor=(1, 0, 0.5, 1))

#plt.title("Discarded Pie")
#plt.show()
plt.savefig('discard pie.png', format='png')<jupyter_output><empty_output><jupyter_text>Discard Percentage Charts<jupyter_code>#plt.title('Discard Percentage')
plt.bar(discarded_percentage.keys(), discarded_percentage.values())
#plt.show()
plt.savefig('sensorfusion.png', format='png')
keys, values = list(discarded_percentage.keys()), list(discarded_percentage.values())
legend_keys = copy.copy(keys)

for i in range(len(keys)):
     legend_keys[i] = str(legend_keys[i]) + " (%) = " + str(values[i])

# Remove wedgeprops to make pie
wedges, texts = plt.pie(values, textprops=dict(color="w"), wedgeprops=dict(width=0.5))
plt.legend(wedges, legend_keys,
          title="Fault Codes",
          loc="center left",
          bbox_to_anchor=(1, 0, 0.5, 1))

#plt.title("Discard Percentage")
plt.show()
plt.savefig('discard percntage pie.png')<jupyter_output><empty_output><jupyter_text>Toggle Time vs Frequency of Generators<jupyter_code>toggle_times = {'A': 620, 'B': 180, 'C': 490, 'D': 270}<jupyter_output><empty_output><jupyter_text>Premise $faults\,generated \propto \frac{1}{toggle\,time}$$\therefore B > D > C > A$  Generator Output Charts (Possibilities of Faults)<jupyter_code>generators['A']
#plt.title('Generator Output (Possibilities of Faults)')
plt.bar(generators.keys(), generators.values())
#plt.show()
plt.savefig('generator output bar.png')
keys, values = list(generators.keys()), list(generators.values())
legend_keys = copy.copy(keys)

for i in range(len(keys)):
     legend_keys[i] = "n (" + str(legend_keys[i]) + ") = " + str(values[i])

# Remove wedgeprops to make pie
wedges, texts = plt.pie(values, textprops=dict(color="w"), wedgeprops=dict(width=0.5))
plt.legend(wedges, legend_keys,
          title="Fault Codes",
          loc="center left",
          bbox_to_anchor=(1, 0, 0.5, 1))

#plt.title("Generator Output Charts (Possibilities of Fault)")
#plt.show()
plt.savefig('generator output pie.png')<jupyter_output><empty_output><jupyter_text>Single-Run Fault Charts<jupyter_code>chart_data = copy.copy(fault_codes)
values = list(chart_data.values())
keys = list(chart_data.keys())

#plt.title('Single-Run')
plt.bar(keys, values)
#plt.show()
plt.savefig('single-run bar.png')
# Remove wedgeprops to make pie
wedges, texts = plt.pie(values, 
                        textprops=dict(color="w"), 
                        wedgeprops=dict(width=0.5))

legend_keys = copy.copy(keys)

for i in range(len(keys)):
     legend_keys[i] = str(legend_keys[i]) + " " + str(values[i]) + " " + "times"
        
plt.legend(wedges, legend_keys,
          title="Fault Codes",
          loc="center left",
          bbox_to_anchor=(1, 0, 0.5, 1))

#plt.title("Single-Run")
#plt.show()
plt.savefig('single-run pie.png')<jupyter_output><empty_output><jupyter_text>Cumulative Faults Chart<jupyter_code>fileName = "D:/code/C++/RT-Cadmium-FDD-New-Code/knowledge_base/_fault_codes_dir/_fault_codes_list.txt"

with open(fileName, "r") as f:
    lines = f.readlines()
    
total = {}
    
for line in lines:
    res = re.findall("\d+[-]*\d*", line)

    if len(res) > 0:
        total[res[0]] = str(res[1])
values = list(total.values())
keys = list(total.keys())

#plt.title('Cummulative')
plt.bar(keys, values)
#plt.show()
plt.savefig('single-run bar.png')
values = list(total.values())
keys = list(total.keys())
legend_keys = copy.copy(keys)

for i in range(len(keys)):
     legend_keys[i] = str(legend_keys[i]) + " " + str(values[i]) + " " + 'times'

# Remove wedgeprops to make pie
wedges, texts = plt.pie(values, textprops=dict(color="w"), wedgeprops=dict(width=0.5))
plt.legend(wedges, legend_keys,
          title="Fault Codes",
          loc="center left",
          bbox_to_anchor=(1, 0, 0.5, 1))

#plt.title("Cumulative")
#plt.show()
plt.savefig('cumulative pie.png')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18591075492233106, 'fraction_numerical': 0.024834273275947363, 'mean_word_length': 4.502449646162221, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 56, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '11861', 'license': 'MIT', 'n_tokens_mistral': 3999, 'n_tokens_neox': 3710, 'n_words': 816, 'path': 'Sensor_Fusion_New_Fault_Codes -Copy2.ipynb', 'repo_name': 'Valentine-Efagene/Jupyter-Notebooks', 'size': '10107'}