Commit b542b7e8 authored by Camron Blackburn's avatar Camron Blackburn

html db

parent 7dec6734
\ No newline at end of file
import os
DB_PATH = "materials"
def gen_index(filepath, pathlist):
makes a index page for the entire database
just a list of links to the material files
later update with a table summarizing the values of everything
filepath: path to html file created
pathlist: list of strings that are the material pages to link to,
assume name from path format
dir = os.path.split(filepath)[0]
html_file = open(filepath, mode='w')
content = '''
<!DOCTYPE html>
table, th, td {
border: 1px solid black;
<h1>Filter Media Database</h1>
This is a tracking page to follow the filter efficiency and physical properties of various types of face mask or ventilator filter materials - a central page to compare NOISH-approved N95 masks to new materials developed by the larger CBA COVID repsonse team (<a href="">electrospining</a>, <a href="">rotary jet</a> ) to DIY materials that could be easily sourced or readily available.
With the CDC now recommending everyone uses any type of makeshift mask before going out in public, and as more people become caretakers for sick family members, we should get a quantitative measurement of which type of household items are best for transmission protection, breathability, and longenvity.
Similar questions have been asked and answered before - <a href="">Effficiency of homemade masks</a>, <a href="">filtering performance of 20 protective fabrics</a>, etc. - this projects exists to verify and expand these findings, specialize them to known <a href="">SARS-CoV-2 aerosol Characteristics</a>, and provide an inital comparison for novel materials.
filtration efficiency testing is inspired by ASTM standards <a href="">F2299</a> and <a href="">F2101</a>, but it's NOT intended to replace or be as rigorous as NOISH testing - more details <a href="">here</a>. the hope is two fold: (1) to provide convenient testing for materials developed in house before sending them to more rigorous and qualified testing labs, and (2) to provide comparative insight backed by quantitative measurement to the growing DIY mask movement.
<i>click the mask name for <b>more images & details</b></i>
table = sum_table(pathlist, dir)
content += table
content = content + "\n </body>\n</html>"
print("generated index file: ", filepath)
def gen_media_page(dirpath):
generates a main page for each material studied
data must be stored in a txt file in the same directory
image folders will be scanned and images attached below text information
dirpath: directory to media summary
name = os.path.split(dirpath)[1]
html_path = os.path.join(dirpath, name+".html")
txt_path = os.path.join(dirpath, name+".txt")
if not os.path.isfile(txt_path):
print("text data file does not exist for %s! No html file will be added." % name)
html_file = open(html_path, mode="w")
txt_file = open(txt_path, mode="r")
content = '''
<!DOCTYPE html>
<ul style="list-style-type:none;">
''' % name
for line in txt_file:
cat= line.split(":")[0]
value = ":".join(line.split(":")[1:])
if cat == "notes":
stat = '<li><b>%s</b><ul style="list-tyle-type:none;">' % cat
bullets = value.split(",")
for b in bullets:
stat += "<li>%s</li>" % b
stat += "</ul></li>\n"
elif "link" in cat:
description, link = value.split(",")
stat = '<li><b>%s</b>: <a href="%s">%s</a></li>\n' % (cat, link, description)
stat = "<li><b>%s</b>: %s</li>\n" % (cat, value)
content = content + stat
for root, dirs, files in os.walk(dirpath):
for f in files:
base, ext = os.path.splitext(f)
if ext in [".jpg", ".png", ".jpeg", ".tif"]:
img_path = os.path.join(root, f)
img_path = img_path[len(dirpath):]
image = '<br><img src=".%s" height="400"><br>%s<br>\n' % (img_path, base)
content += image
content += "</html>"
print("generated material page: ", html_path)
def sum_table(pathlist, dir):
''' creates summary table of all the materials
name + link to page,
filter efficiency,
pressure drop,
avg fiber diameter,
rep image
returns table in html string
content = '''
<th>filter efficiency (%)</th>
<th>pressure drop (psi)</th>
<th>avg fiber diameter (um)</th>
<th>thickness (mm)</th>
<th>weight (g/cm^2)</th>
for path in pathlist:
name = os.path.splitext(os.path.split(path)[1])[0]
link_path = path[len(dir):]
link = '<td><a href=".%s">%s</a></td>\n' % (link_path, name)
effic = '<td></td>'
pressure = '<td></td>'
fiber = '<td></td>'
thick = '<td></td>'
weight = '<td></td>'
img = '<td></td>'
txt_path = os.path.join(dir, name, name+".txt")
if not os.path.isfile(txt_path):
row = "<tr>\n" + link + effic + pressure + fiber + thick + weight + img + "</tr>\n"
content += row
data_file = open(txt_path, "r")
for line in data_file:
column = line.split(":")[0]
value = ":".join(line.split(":")[1:])
if "efficiency" in column:
effic = '<td>%s</td>\n' % value
elif "pressure" in column:
pressure = '<td>%s</td>\n' % value
elif "fiber" in column:
fiber = '<td>%s</td>\n' % value
elif "thickness" in column:
thick = '<td>%s</td>\n' % value
elif "weight" in column:
weight = '<td>%s</td>\n' % value
SEM_path = os.path.join(dir, name, "SEM")
if os.path.exists(SEM_path):
SEM_imgs = os.listdir(SEM_path)
rep_im = [img for img in SEM_imgs if "rep" in img][0]
im_path = os.path.join(SEM_path, rep_im)[len(dir):]
img = '<td><img src=".%s" height="200"></td>\n' % im_path
row = "<tr>\n" + link + effic + pressure + fiber + thick + weight + img + "</tr>\n"
content += row
content += "</tbody>"
return content
cwd = os.getcwd()
DB_PATH = os.path.join(cwd, DB_PATH)
if not os.path.exists(DB_PATH):
html_media_pages = []
for root, dirs, files in os.walk(DB_PATH):
for name in dirs:
if root.split("\\") > DB_PATH.split("\\"):
if not os.path.isfile(os.path.join(cwd, name, name+".html")) or REWRITE:
gen_media_page(os.path.join(root, name))
html_media_pages.append(os.path.join(root, name, name+".html"))
# make index file if it doesn't exist
index = os.path.join(DB_PATH, "index.html")
if not os.path.isfile(index) or REWRITE:
gen_index(index, html_media_pages)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment