<jupyter_start><jupyter_text>Fault Classes | Fault | Binary | Decimal || --- | --- | --- || A | 00 | 0 || B | 01 | 1 || C | 10 | 2 |  Fault Code = (variable << 2) + fault_class | Fault | Binary | Decimal || --- | --- | --- || A1 | 100 | 4 || B1 | 101 | 5 || C1 | 110 | 6 |  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 || A1B1 | 4-5 || A1C1 | 4-6 || B1C1 | 5-6 |  Flow Chart  Run<jupyter_code>command = "D:/code/C++/RT-Cadmium-FDD-New-Code/top_model/mainwd.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}

for key in generators.keys():
    generators[key] = len(re.findall("faultGen" + key, output))
fault_codes
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
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}
discarded_percentage = {'A': a_discarded * 100 / total_generated, 'B': b_discarded * 100 / total_generated, 'C': c_discarded * 100 / total_generated}
discarded
fault_codes
a_increment = generators['A'] - fault_codes['-4-5-'] - fault_codes['-4-6-'] - 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-'] - c_discarded
c_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><ipython-input-44-a55430dbb174>:8: MatplotlibDeprecationWarning: normalize=None does not normalize if the sum is less than 1 but this behavior is deprecated since 3.3 until two minor releases later. After the deprecation period the default value will be normalize=True. To prevent normalization pass normalize=False 
  wedges, texts = plt.pie(values, textprops=dict(color="w"), wedgeprops=dict(width=0.5))<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><ipython-input-46-0f993063da11>:8: MatplotlibDeprecationWarning: normalize=None does not normalize if the sum is less than 1 but this behavior is deprecated since 3.3 until two minor releases later. After the deprecation period the default value will be normalize=True. To prevent normalization pass normalize=False 
  wedges, texts = plt.pie(values, textprops=dict(color="w"), wedgeprops=dict(width=0.5))<jupyter_text>Toggle Time vs Frequency of Generators<jupyter_code>toggle_times = {'A': 620, 'B': 180, 'C': 490}<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.bar(keys, values)
#plt.title('Single-Run')
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>
{'fraction_non_alphanumeric': 0.16129484304932734, 'fraction_numerical': 0.021300448430493273, 'mean_word_length': 4.382352941176471, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '186644', 'license': 'MIT', 'n_tokens_mistral': 2722, 'n_tokens_neox': 2480, 'n_words': 548, 'path': 'Sensor_Fusion_New_Fault_Codes_WD/Sensor_Fusion_New_Fault_Codes_WD.ipynb', 'repo_name': 'Valentine-Efagene/Jupyter-Notebooks', 'size': '7136'}