<s> """<STR_LIT>""" <EOL> revision = '<STR_LIT>' <EOL> down_revision = '<STR_LIT>' <EOL> from oslo_db . sqlalchemy import utils as db_utils <EOL> from subunit2sql . db import api as db_api <EOL> from subunit2sql . db import models <EOL> from subunit2sql import read_subunit <EOL> def upgrade ( ) : <EOL> query = db_utils . model_query ( <EOL> models . Test , db_api . get_session ( ) ) . filter ( <EOL> models . Test . success > <NUM_LIT:0> , models . Test . run_time == None ) . join ( <EOL> models . TestRun , <EOL> models . Test . id == models . TestRun . test_id ) . filter_by ( <EOL> status = '<STR_LIT:success>' ) . values ( models . Test . id , <EOL> models . TestRun . start_time , <EOL> models . TestRun . stop_time ) <EOL> results = { } <EOL> for test_run in query : <EOL> delta = read_subunit . get_duration ( test_run [ <NUM_LIT:1> ] , test_run [ <NUM_LIT:2> ] ) <EOL> if test_run [ <NUM_LIT:0> ] in results : <EOL> results [ test_run [ <NUM_LIT:0> ] ] . append ( delta ) <EOL> else : <EOL> results [ test_run [ <NUM_LIT:0> ] ] = [ delta ] <EOL> for test in results : <EOL> avg = float ( sum ( results [ test ] ) ) / float ( len ( results [ test ] ) ) <EOL> db_api . update_test ( { '<STR_LIT>' : avg } , test ) <EOL> def downgrade ( ) : <EOL> pass </s>
