diff --git a/logs/README.md b/logs/README.md index f9975c6..6f9d000 100644 --- a/logs/README.md +++ b/logs/README.md @@ -12,4 +12,6 @@ Measurement: pressure Pumpdown curve: elapsed (seconds, float) and mbar. +To acquire: `python3 acquire.py` and give it a tag/comment to stdin. Then press the pumpdown button or turn the scope on. + Elapsed is 0 at the moment the script detected a pumpdown event. diff --git a/logs/acquire-pressure.py b/logs/acquire-pressure.py new file mode 100644 index 0000000..ebcaf2d --- /dev/null +++ b/logs/acquire-pressure.py @@ -0,0 +1,59 @@ +import requests +import time +from datetime import datetime +import glob + +tags = set() +for p in glob.glob("pressure-*.csv"): + p = p.rstrip('.csv') + parts = p.split('-', maxsplit=4) + tags.add(parts[4]) +print('Existing tags:', ', '.join(list(tags))) +tag = input("Tag? ") + +def metrics(): + r = requests.get('http://succbone.lab.fa-fo.de/metrics').text + res = {} + for line in r.split('\n'): + if '#' in line: + line = line[:line.index('#')] + line = line.strip() + if not line: + continue + a, b = line.split(' ') + a = a.strip() + b = b.strip() + res[a] = float(b) + return res + + +f = None +prev = None +logging = None +buffer = [] +while True: + time.sleep(0.1) + m = metrics() + v = m['sem_pressure_mbar'] + if logging is None: + if v < 800 and (prev is None or prev >= 800): + logging = time.time() + print('Starting log...') + f = open(f'pressure-{datetime.now().isoformat()}-{tag}.csv', 'w') + f.write('elapsed\tmbar\n') + for t, v in buffer: + f.write(f'{t-logging}\t{v}\n') + else: + buffer.append((time.time(), v)) + else: + if v > 800: + print('Vented') + break + + prev = v + if logging is not None: + elapsed = time.time() - logging + print(elapsed, m['sem_pressure_mbar']) + f.write(f'{elapsed}\t{v}\n') + else: + print('waiting', m['sem_pressure_mbar'])