Skip to content

Micro phases #1278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions docker/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,23 @@ CREATE TRIGGER categories_moddatetime
EXECUTE PROCEDURE moddatetime (updated_at);


CREATE TABLE micro_phases (
id SERIAL PRIMARY KEY,
run_id uuid NOT NULL REFERENCES runs(id) ON DELETE CASCADE ON UPDATE CASCADE,
name text NOT NULL,
start_time bigint NOT NULL,
end_time bigint NOT NULL,
created_at timestamp with time zone DEFAULT now(),
updated_at timestamp with time zone
);

CREATE INDEX "micro_phases_run_id" ON "micro_phases" USING HASH ("run_id");
CREATE TRIGGER micro_phases_moddatetime
BEFORE UPDATE ON micro_phases
FOR EACH ROW
EXECUTE PROCEDURE moddatetime (updated_at);


CREATE TABLE phase_stats (
id SERIAL PRIMARY KEY,
run_id uuid NOT NULL REFERENCES runs(id) ON DELETE CASCADE ON UPDATE CASCADE,
Expand Down
19 changes: 7 additions & 12 deletions lib/notes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from re import fullmatch
import re

from lib.db import DB

Expand All @@ -22,26 +22,21 @@ def save_to_db(self, run_id):
""",
params=(run_id, note['detail_name'], note['note'], int(note['timestamp']))
)
def parse_and_add_notes(self, detail_name, data):
for match in re.findall(r'^(\d{16}) (.+)$', data, re.MULTILINE):
self.__notes.append({'note': match[1], 'detail_name': detail_name, 'timestamp': match[0]})

def parse_note(self, line):
if match := fullmatch(r'^(\d{16}) (.+)', line):
return int(match[1]), match[2]
return None

def add_note(self, note):
self.__notes.append(note)
def add_note(self, note, detail_name, timestamp):
self.__notes.append({'note': note , 'detail_name': detail_name, 'timestamp': timestamp})

if __name__ == '__main__':
import argparse
import time

parser = argparse.ArgumentParser()
parser.add_argument('run_id', help='Please supply a run_id to attribute the measurements to')

args = parser.parse_args() # script will exit if arguments not present

notes = Notes()
notes.add_note({'note': 'This is my note',
'timestamp': int(time.time_ns() / 1000),
'detail_name': 'Arnes_ Container'})
notes.parse_and_add_notes('my container', '1234567890123456 My note')
notes.save_to_db(args.run_id)
Loading
Loading