Update validate-recipes.yml #230
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Commit date to master | |
on: push | |
jobs: | |
build_summary: | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the branch | |
- name: checkout | |
uses: actions/checkout@v2 # use either @v2-beta or @master. Eventually, there will be a @v2 tag. | |
- name: setup python | |
uses: actions/setup-python@v2 | |
- name: build summary | |
uses: jannekem/run-python-script-action@v1 | |
with: | |
script: | | |
import os | |
os.chdir("Recipes") | |
import glob | |
#import numpy as np | |
def unroll_forloop(results): | |
results = [r.split("#")[0] for r in results] | |
results2 = [] | |
endline =0 | |
for i in range(len(results)): | |
if len((results[i]).lower().split()) > 0: | |
if len((results[i]).lower()) > 0 and "for" == (results[i]).lower().split()[0]: | |
forCount = int(results[i].split()[1]) | |
startLine = i+1 | |
for repeats in range(forCount): | |
for nextLine in range(len(results)-i): | |
if len(results[startLine+nextLine].lower().split())> 0: | |
if "endfor" == (results[startLine+nextLine]).lower().split()[0]: | |
endline = startLine+nextLine+1 | |
break | |
else: | |
results2.append(results[startLine+nextLine]) | |
else: | |
if i < endline: | |
pass | |
else: | |
results2.append(results[i]) | |
return results2 | |
def read_script(scriptname,parent,tab,state,darks,flat,coronal,coronalExp,summary,md,warning,childextension=".rcp"): | |
if childextension != ".rcp": | |
coronal = [] | |
coronalExp = [] | |
#print(f"{scriptname},{parent},{tab},{state},{darks},{flat},{summary},{md},{warning}") | |
script = open(scriptname,"r") | |
results = script.readlines() | |
script.close() | |
results2 = unroll_forloop(results) | |
summary.write(f" {tab*6*'-'} > {scriptname.split('#')[0]}\n") | |
runTime = 0 | |
hardwareTime = 0 | |
color = None | |
emoji = None | |
if "_FW" not in scriptname and "setup" not in scriptname and "cbk" not in scriptname and "menu" not in scriptname and "_in" not in scriptname and "_out" not in scriptname: | |
if state['shut'] == "in": | |
color = "red" | |
if state['shut'] == "out" and state['calib'] =='out' and state['diffuser'] == "in": | |
color = "blue" | |
if state['shut'] == "out" and state['calib'] =='out' and state['diffuser'] == "out": | |
#print(state) | |
color = "green" | |
if state['shut'] == "out" and state['calib'] =='in' and state['diffuser'] == "in": | |
color = "black" | |
if color == "red": | |
#md.write("📙 ") | |
emoji = "📙 " | |
if color == "black": | |
# md.write("📕 ") | |
emoji = "📕 " | |
if color == "blue": | |
#md.write("📘 ") | |
emoji = "📘 " | |
if color == "green": | |
#md.write("📗 ") | |
emoji = "📗 " | |
md.write(f"<details><summary>") | |
if emoji is not None: | |
md.write(emoji) | |
md.write(f"{scriptname}</summary><blockquote><pre>") | |
tab = tab +1 | |
for child in results2: | |
filename =child.split('#')[0].strip() | |
child=child.strip().lower() | |
if len(child.strip()) > 0 and child.strip()[0] != "#" and not child.startswith("date") and not child.startswith("author") and not child.startswith("description"): | |
if childextension in child.split('#')[0]: | |
try: | |
(tTime,hTime) = read_script(filename,parent+","+child.split('#')[0],tab,state,darks,flats,coronal,coronalExp,summary,md,warning) | |
runTime += tTime | |
hardwareTime += hTime | |
# runTime = runTime+runTime2 | |
#md.write(f"read_script out {runTime}") | |
except FileNotFoundError: | |
warning.write(f"{parent} tried to call *{filename}* which does not exist\n") | |
else: | |
#print(f"{state} {darks} {flat} {parent} {child}") | |
color = None | |
command = child.split()[0] | |
if command not in ["data", "cal", "dark", "fw", "occ", "diffuser","calib", "occyrel", "occxrel", "o1", "calret", "calpol","cover", "shut", "exposure", "nd", "gain", "distortiongrid", "modwait","shut","exposure", "cover", "occ", "prefilterrange"]: | |
warning.write(f"{parent} {{ {child} }} command not found.\n") | |
if "gain" in child: | |
if child.split()[1] in ["low","high"]: | |
state['gain'] = "low" if "low" in child else "high" | |
else: | |
warning.write(f"{parent} {{ {child} }} has invalid gain\n") | |
if "shut" in child: | |
if child.split()[1] in ["in","out"]: | |
state['shut'] = "in" if "in" in child else "out" | |
else: | |
warning.write(f"{parent} {{ {child} }} has invalid position\n") | |
if "exposure" in child: | |
try: | |
exp = float(child.split()[1]) | |
if exp < 1 or exp > 84: | |
raise ValueError("Number out of range") | |
state['exposure'] = child.split()[1] | |
execpt: | |
warning.write(f"{parent} {{ {child} }} has invalid exposure time\n") | |
if "cover" in child: | |
if child.split()[1] in ["in","out"]: | |
if 'cover' not in state or state['cover'] != child.split()[1]: | |
hardwareTime = hardwareTime + 60 | |
state['cover'] = "in" if "in" in child else "out" | |
else: | |
warning.write(f"{parent} {{ {child} }} has invalid position\n") | |
if "occ" in child: | |
if child.split()[1] in ["in","out"]: | |
if 'occ' not in state or state['occ'] not in child: | |
hardwareTime = hardwareTime + 20 | |
state['occ'] = "in" if "in" in child else "out" | |
else: | |
warning.write(f"{parent} {{ {child} }} has invalid position\n") | |
if "prefilterrange " in child: | |
if child.split()[1] in ["637","670","706","761","789","802","991","1074","1079"]: | |
if 'filter' not in state or state['filter'] != child.split()[1]: | |
hardwareTime = hardwareTime + 25 | |
state['filter'] = int(child.split()[1]) | |
execpt: | |
warning.write(f"{parent} {{ {child} }} invalid prefilter\n") | |
if "calret" in child: | |
try: | |
float(child.split()[1]) | |
if 'calret' not in state or state['calret'] != child.split()[1]: | |
hardwareTime = hardwareTime + 5 | |
state['calret'] = child.split()[1] | |
execpt: | |
warning.write(f"{parent} {{ {child} }} should be degrees\n") | |
if "calpol" in child: | |
try: | |
float(child.split()[1]) | |
if 'calpol' not in state or state['calpol'] not in child: | |
hardwareTime = hardwareTime + 5 | |
state['calpol'] = child.split()[1] | |
execpt: | |
warning.write(f"{parent} {{ {child} }} should be degrees\n") | |
if "calib" in child: | |
if 'calib' not in state or state['calib'] not in child: | |
hardwareTime = hardwareTime + 20 | |
state['calib'] = "in" if "in" in child else "out" | |
if "diffuser" in child: | |
if child.split()[1] in ["in","out"]: | |
if 'diffuser' not in state or state['diffuser'] not in child: | |
hardwareTime = hardwareTime + 20 | |
state['diffuser'] = "in" if "in" in child else "out" | |
else: | |
warning.write(f"{parent} {{ {child} }} has invalid position\n") | |
if "data" in child: | |
#print(child) | |
data,cam,cont,wave,sums = child.split() | |
runTime += 300+int(state['exposure'])*4*int(sums) | |
if cam not in ["rcam","tcam"]: | |
warning.write(f"{parent} {{ {child} }} has invalid camera\n") | |
if cont not in ["both", "red,", "blue"]: | |
warning.write(f"{parent} {{ {child} }} has invalid continumm\n") | |
try: | |
float(wave) # Type-casting the string to `float`. | |
except ValueError: | |
warning.write(f"{parent} {{ {child} }} wavelength is not a number\n") | |
if state['shut'] == "in": | |
color = "red" | |
if state['exposure']+state['gain']+sums not in darks: | |
darks.append(state['exposure']+state['gain']+sums) | |
if state['shut'] == "out" and state['calib'] =='out' and state['diffuser'] == "in": | |
color = "blue" | |
if state['gain']+sums+cam+cont+wave not in flats: | |
flats.append(state['gain']+sums+cam+cont+wave) | |
if state['shut'] == "out" and state['calib'] =='out' and state['diffuser'] == "out": | |
#print(state) | |
color = "green" | |
coronal.append(state['gain']+sums+cam+cont+wave) | |
coronalExp.append(state['exposure']+state['gain']+sums) | |
# if state['exposure']+state['gain']+sums not in darks: | |
# warning.write(f"{parent} {{ {child} }}missing dark for {state['exposure']+state['gain']+sums}\n") | |
# if state['gain']+sums+cam+cont+wave not in flats: | |
# warning.write(f"{parent} {{ {child} }} missing flat for {state['gain']+sums+cam+cont+wave}\n") | |
if state['shut'] == "out" and state['calib'] =='in' and state['diffuser'] == "in": | |
color = "black" | |
summary.write(f"{tab*6*'-'}> {child.split('#')[0]}\n") | |
rcpName = child.split('#')[0] | |
if "_FW" not in rcpName and "setup" not in rcpName and "cbk" not in rcpName and "menu" not in rcpName: | |
#md.write(f"rcpname {rcpName}") | |
if color == "red": | |
md.write("📙 ") | |
if color == "black": | |
md.write("📕 ") | |
if color == "blue": | |
md.write("📘 ") | |
if color == "green": | |
md.write("📗 ") | |
md.write(f"{"\t".join((child.split('#')[0]).strip().split())}\n") | |
pass | |
script.close() | |
if "rcp" in childextension: | |
md.write(f"\nIntegration:{runTime/1000/60:.2f} minutes. Hardware:{hardwareTime/60:.2f} minutes. total:{runTime/1000/60 + hardwareTime/60:.2f} minutes ") | |
else: | |
for corona in coronalExp: | |
#c1 = corona.replace("tcam","rcam") | |
if corona not in darks: | |
warning.write(f"{parent} missing dark for {{ {corona} }}\n") | |
for corona in coronal: | |
if corona not in flats: | |
warning.write(f"{parent} missing flat for {{ {corona} }}\n") | |
md.write("</pre></blockquote></details>") | |
return runTime,hardwareTime | |
menus = glob.glob("*.menu") | |
state = {} | |
darks = [] | |
coronal = [] | |
coronalExp = [] | |
flats = [] | |
warning = open('warnings.txt',"w") | |
for menu in menus: | |
state = {'exposure':"80",'shut':"",'calib':"",'occ':"",'diffuser':"",'gain':"high"} | |
darks = [] | |
flats = [] | |
coronal = [] | |
coronalExp = [] | |
md = open(menu.split(".menu")[0]+".md","w") | |
summary = open(menu.split(".menu")[0]+".summary","w") | |
md.write( """📙 =dark | |
📕 =calib | |
📘 =flat | |
📗 =data """) | |
quick_menu = open(menu,"r") | |
qmenu = quick_menu.readlines() | |
quick_menu.close() | |
if "NOWARNING" not in "".join(qmenu): | |
read_script(menu,menu,0,state,darks,flats,coronal,coronalExp,summary,md,warning,".cbk") | |
md.close() | |
summary.close() | |
warning.close() | |
- name: setup git config | |
run: | | |
# setup the username and email. I tend to use 'GitHub Actions Bot' with no email by default | |
git config user.name "GitHub Actions Bot" | |
git config user.email "<>" | |
- name: commit | |
run: | | |
# Stage the file, commit and push | |
git add . | |
git commit -m "Menu files re-summarized" --allow-empty | |
git push origin main |