11from itertools import groupby
22
33import streamlit as st
4- from test2text .services .db import DbClient
4+ from test2text .services .db import get_db_client
55
66
77def add_new_line (summary ):
88 return summary .replace ("\n " , "<br>" )
99
1010
1111def make_a_report ():
12- st .header ("Test2Text Report" )
12+ st .header ("Test2Text Report" )
1313
14- db = DbClient ( "./private/requirements.db" )
14+ db = get_db_client ( )
1515
16- st .subheader ("Table of Contents" )
16+ st .subheader ("Table of Contents" )
1717
18- data = db .conn .execute ("""
18+ data = db .conn .execute ("""
1919 SELECT
2020 Requirements.id as req_id,
2121 Requirements.external_id as req_external_id,
@@ -39,61 +39,80 @@ def make_a_report():
3939 Requirements.id, AnnotationsToRequirements.cached_distance, TestCases.id
4040 """ )
4141
42- current_annotations = {}
43- current_test_scripts = set ()
44-
45- def write_requirement (req_id , req_external_id , req_summary ,
46- current_annotations : set [tuple ], current_test_scripts : set ):
47- if req_id is None and req_external_id is None :
48- return False
49-
50- with st .expander (f"#{ req_id } Requirement { req_external_id } " ):
51- st .subheader (f"Requirement { req_external_id } " )
52- st .html (f"<p>{ add_new_line (req_summary )} </p>" )
53- st .subheader ("Annotations" )
42+ current_annotations = {}
43+ current_test_scripts = set ()
44+
45+ def write_requirement (
46+ req_id ,
47+ req_external_id ,
48+ req_summary ,
49+ current_annotations : set [tuple ],
50+ current_test_scripts : set ,
51+ ):
52+ if req_id is None and req_external_id is None :
53+ return False
54+
55+ with st .expander (f"#{ req_id } Requirement { req_external_id } " ):
56+ st .subheader (f"Requirement { req_external_id } " )
57+ st .html (f"<p>{ add_new_line (req_summary )} </p>" )
58+ st .subheader ("Annotations" )
59+ anno , summary , dist = st .columns (3 )
60+ with anno :
61+ st .write ("Annonation's id" )
62+ with summary :
63+ st .write ("Summary" )
64+ with dist :
65+ st .write ("Distance" )
66+ for anno_id , anno_summary , distance in current_annotations :
5467 anno , summary , dist = st .columns (3 )
5568 with anno :
56- st .write ("Annonation's id " )
69+ st .write (f" { anno_id } " )
5770 with summary :
58- st .write ( "Summary " )
71+ st .html ( f" { add_new_line ( anno_summary ) } " )
5972 with dist :
60- st .write ("Distance" )
61- for anno_id , anno_summary , distance in current_annotations :
62- anno , summary , dist = st .columns (3 )
63- with anno :
64- st .write (f"{ anno_id } " )
65- with summary :
66- st .html (
67- f"{ add_new_line (anno_summary )} "
68- )
69- with dist :
70- st .write (round (distance , 2 ))
71-
72- st .subheader ("Test Scripts" )
73- for test_script in current_test_scripts :
74- st .markdown (f"- { test_script } " )
75-
76- progress_bar = st .empty ()
77- rows = data .fetchall ()
78- if not rows :
79- st .error ("There is no data to inspect.\n Please upload annotations." )
80- return None
81- max_progress = len (rows )
82- index = 0
83- for (req_id , req_external_id , req_summary ), group in groupby (rows , lambda x : x [0 :3 ]):
84- current_annotations = set ()
85- current_test_scripts = set ()
86- index += 1
87- for _ , _ , _ , anno_id , anno_summary , distance , case_id , test_script , test_case in group :
88- current_annotations .add ((anno_id , anno_summary , distance ))
89- current_test_scripts .add (test_script )
90- write_requirement (req_id = req_id , req_external_id = req_external_id , req_summary = req_summary ,
91- current_annotations = current_annotations , current_test_scripts = current_test_scripts )
92-
93-
94- progress_bar .progress (round (index * 100 / max_progress ), text = "Processing..." )
95- progress_bar .empty ()
96- db .conn .close ()
73+ st .write (round (distance , 2 ))
74+
75+ st .subheader ("Test Scripts" )
76+ for test_script in current_test_scripts :
77+ st .markdown (f"- { test_script } " )
78+
79+ progress_bar = st .empty ()
80+ rows = data .fetchall ()
81+ if not rows :
82+ st .error ("There is no data to inspect.\n Please upload annotations." )
83+ return None
84+ max_progress = len (rows )
85+ index = 0
86+ for (req_id , req_external_id , req_summary ), group in groupby (
87+ rows , lambda x : x [0 :3 ]
88+ ):
89+ current_annotations = set ()
90+ current_test_scripts = set ()
91+ index += 1
92+ for (
93+ _ ,
94+ _ ,
95+ _ ,
96+ anno_id ,
97+ anno_summary ,
98+ distance ,
99+ case_id ,
100+ test_script ,
101+ test_case ,
102+ ) in group :
103+ current_annotations .add ((anno_id , anno_summary , distance ))
104+ current_test_scripts .add (test_script )
105+ write_requirement (
106+ req_id = req_id ,
107+ req_external_id = req_external_id ,
108+ req_summary = req_summary ,
109+ current_annotations = current_annotations ,
110+ current_test_scripts = current_test_scripts ,
111+ )
112+
113+ progress_bar .progress (round (index * 100 / max_progress ), text = "Processing..." )
114+ progress_bar .empty ()
115+ db .conn .close ()
97116
98117
99118if __name__ == "__main__" :
0 commit comments