<s> import logging <EOL> l = logging . getLogger ( __name__ ) <EOL> import mox <EOL> from datetime import date , datetime , time , timedelta <EOL> from easy_split . experiments . models import ( Experiment , DailyEngagementReport , <EOL> DailyConversionReport , <EOL> DailyConversionReportGoalData , <EOL> Participant , AnonymousVisitor , <EOL> GoalType , GoalRecord ) <EOL> from easy_split . experiments . reports import ( EngagementReportGenerator , <EOL> ConversionReportGenerator , <EOL> calculate_participant_conversion , <EOL> get_conversion_data , <EOL> calculate_goal_type_conversion , <EOL> find_experiment_group_participants ) <EOL> from easy_split . experiments . tests . utils import create_user_in_group , TestCase <EOL> class TestDailyReports ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . experiment = Experiment ( name = "<STR_LIT>" ) <EOL> self . experiment . save ( ) <EOL> self . experiment . state = Experiment . ENABLED_STATE <EOL> self . experiment . save ( ) <EOL> self . experiment . start_date = ( self . experiment . start_date - <EOL> timedelta ( days = <NUM_LIT:5> ) ) <EOL> self . experiment . save ( ) <EOL> anonymous_visitor = AnonymousVisitor ( ) <EOL> anonymous_visitor . save ( ) <EOL> anonymous_participant = Participant ( anonymous_visitor = anonymous_visitor , <EOL> experiment = self . experiment , <EOL> group = Participant . TEST_GROUP ) <EOL> anonymous_participant . save ( ) <EOL> anonymous_participant . enrollment_date = self . experiment . start_date <EOL> anonymous_participant . save ( ) <EOL> self . other_experiment = Experiment ( name = "<STR_LIT>" ) <EOL> self . other_experiment . save ( ) <EOL> self . other_experiment . state = Experiment . DISABLED_STATE <EOL> self . other_experiment . save ( ) <EOL> self . other_experiment . start_date = ( date . today ( ) - <EOL> timedelta ( days = <NUM_LIT:7> ) ) <EOL> self . other_experiment . end_date = ( date . today ( ) - <EOL> timedelta ( days = <NUM_LIT:3> ) ) <EOL> self . other_experiment . save ( ) <EOL> def testDailyEngagementReport ( self ) : <EOL> users_test = [ ] <EOL> users_control = [ ] <EOL> num_control1 = <NUM_LIT:0> <EOL> num_test1 = <NUM_LIT:0> <EOL> num_control2 = <NUM_LIT:0> <EOL> num_test2 = <NUM_LIT:0> <EOL> for i in range ( <NUM_LIT:5> ) : <EOL> users_control . append ( create_user_in_group ( self . experiment , i , <EOL> Participant . CONTROL_GROUP , <EOL> date . today ( ) - timedelta ( days = i ) ) ) <EOL> users_test . append ( create_user_in_group ( self . experiment , i , <EOL> Participant . TEST_GROUP , <EOL> date . today ( ) - timedelta ( days = i ) ) ) <EOL> report_date = date . today ( ) - timedelta ( days = <NUM_LIT:1> ) <EOL> expected_engagement_score_calls = { <EOL> ( users_test [ <NUM_LIT:1> ] , date . today ( ) - timedelta ( days = <NUM_LIT:1> ) , report_date ) : <NUM_LIT> , <EOL> ( users_test [ <NUM_LIT:2> ] , date . today ( ) - timedelta ( days = <NUM_LIT:2> ) , report_date ) : <NUM_LIT> , <EOL> ( users_test [ <NUM_LIT:3> ] , date . today ( ) - timedelta ( days = <NUM_LIT:3> ) , report_date ) : <NUM_LIT> , <EOL> ( users_test [ <NUM_LIT:4> ] , date . today ( ) - timedelta ( days = <NUM_LIT:4> ) , report_date ) : <NUM_LIT:0> , <EOL> ( users_control [ <NUM_LIT:1> ] , date . today ( ) - timedelta ( days = <NUM_LIT:1> ) , report_date ) : <NUM_LIT:0> , <EOL> ( users_control [ <NUM_LIT:2> ] , date . today ( ) - timedelta ( days = <NUM_LIT:2> ) , report_date ) : <NUM_LIT:0> , <EOL> ( users_control [ <NUM_LIT:3> ] , date . today ( ) - timedelta ( days = <NUM_LIT:3> ) , report_date ) : <NUM_LIT:0> , <EOL> ( users_control [ <NUM_LIT:4> ] , date . today ( ) - timedelta ( days = <NUM_LIT:4> ) , report_date ) : <NUM_LIT:0> } <EOL> test_case = self <EOL> class EngagementScoreCalculatorStub ( object ) : <EOL> def calculate_user_engagement_score ( self , user , <EOL> start_date , end_date ) : <EOL> test_case . assertNotEquals ( user , None ) <EOL> test_case . assertTrue ( expected_engagement_score_calls . <EOL> has_key ( ( user , start_date , end_date ) ) ) <EOL> return expected_engagement_score_calls [ ( user , <EOL> start_date , end_date ) ] <EOL> ( EngagementReportGenerator ( EngagementScoreCalculatorStub ( ) ) . <EOL> generate_daily_report_for_experiment ( self . experiment , report_date ) ) <EOL> experiment_report = DailyEngagementReport . objects . get ( <EOL> experiment = self . experiment , date = report_date ) <EOL> self . assertAlmostEqual ( ( <NUM_LIT> + <NUM_LIT> + <NUM_LIT> + <NUM_LIT:0> ) / <NUM_LIT> , <EOL> experiment_report . test_score ) <EOL> self . assertAlmostEqual ( <NUM_LIT:0.0> , experiment_report . control_score ) <EOL> self . assertEquals ( <NUM_LIT:4> , experiment_report . test_group_size ) <EOL> self . assertEquals ( <NUM_LIT:4> , experiment_report . control_group_size ) <EOL> self . assertAlmostEqual ( <NUM_LIT> , experiment_report . confidence ) <EOL> def testZeroParticipantExperiment ( self ) : <EOL> mocker = mox . Mox ( ) <EOL> engagement_calculator = mocker . CreateMockAnything ( ) <EOL> mocker . ReplayAll ( ) <EOL> report_date = date . today ( ) <EOL> EngagementReportGenerator ( engagement_score_calculator = engagement_calculator ) . generate_daily_report_for_experiment ( <EOL> self . other_experiment , report_date ) <EOL> experiment_report = DailyEngagementReport . objects . get ( <EOL> experiment = self . other_experiment , date = report_date ) <EOL> mocker . VerifyAll ( ) <EOL> self . assertEquals ( None , experiment_report . test_score ) <EOL> self . assertEquals ( None , experiment_report . control_score ) <EOL> self . assertEquals ( <NUM_LIT:0> , experiment_report . test_group_size ) <EOL> self . assertEquals ( <NUM_LIT:0> , experiment_report . control_group_size ) <EOL> def testGenerateAllDailyEngagementReports ( self ) : <EOL> class DummyEngagementCalculator ( object ) : <EOL> def calculate_user_engagement_score ( self , user , start_date , end_date ) : <EOL> return <NUM_LIT:7> <EOL> engagement_report_generator = EngagementReportGenerator ( engagement_score_calculator = DummyEngagementCalculator ( ) ) <EOL> engagement_report_generator . generate_daily_report_for_experiment ( <EOL> self . experiment , date . today ( ) - timedelta ( days = <NUM_LIT:2> ) ) <EOL> engagement_report_generator . generate_daily_report_for_experiment ( <EOL> self . experiment , date . today ( ) - timedelta ( days = <NUM_LIT:3> ) ) <EOL> engagement_report_generator . generate_all_daily_reports ( ) <EOL> DailyEngagementReport . objects . get ( experiment = self . experiment , <EOL> date = date . today ( ) - timedelta ( days = <NUM_LIT:1> ) ) <EOL> DailyEngagementReport . objects . get ( experiment = self . experiment , <EOL> date = date . today ( ) - timedelta ( days = <NUM_LIT:2> ) ) <EOL> DailyEngagementReport . objects . get ( experiment = self . experiment , <EOL> date = date . today ( ) - timedelta ( days = <NUM_LIT:3> ) ) <EOL> DailyEngagementReport . objects . get ( experiment = self . experiment , <EOL> date = date . today ( ) - timedelta ( days = <NUM_LIT:4> ) ) <EOL> DailyEngagementReport . objects . get ( experiment = self . experiment , <EOL> date = date . today ( ) - timedelta ( days = <NUM_LIT:5> ) ) <EOL> self . assertEquals ( <NUM_LIT:5> , DailyEngagementReport . objects . filter ( <EOL> experiment = self . experiment ) . count ( ) ) <EOL> DailyEngagementReport . objects . get ( experiment = self . other_experiment , <EOL> date = date . today ( ) - timedelta ( days = <NUM_LIT:3> ) ) <EOL> DailyEngagementReport . objects . get ( experiment = self . other_experiment , <EOL> date = date . today ( ) - timedelta ( days = <NUM_LIT:4> ) ) <EOL> DailyEngagementReport . objects . get ( experiment = self . other_experiment , <EOL> date = date . today ( ) - timedelta ( days = <NUM_LIT:5> ) ) <EOL> DailyEngagementReport . objects . get ( experiment = self . other_experiment , <EOL> date = date . today ( ) - timedelta ( days = <NUM_LIT:6> ) ) <EOL> DailyEngagementReport . objects . get ( experiment = self . other_experiment , <EOL> date = date . today ( ) - timedelta ( days = <NUM_LIT:7> ) ) <EOL> self . assertEquals ( <NUM_LIT:5> , DailyEngagementReport . objects . filter ( <EOL> experiment = self . other_experiment ) . count ( ) ) <EOL> def create_goal_record ( self , record_datetime , anonymous_visitor , goal_type ) : <EOL> record = GoalRecord . objects . create ( anonymous_visitor = anonymous_visitor , <EOL> goal_type = goal_type ) <EOL> record . created = record_datetime <EOL> record . save ( ) <EOL> def create_participant ( self , anonymous_visitor , experiment , enrollment_date , group ) : <EOL> participant = Participant . objects . create ( anonymous_visitor = anonymous_visitor , <EOL> experiment = experiment , <EOL> group = group ) <EOL> participant . enrollment_date = enrollment_date <EOL> participant . save ( ) <EOL> return participant <EOL> def testParticipantConversionCalculator ( self ) : <EOL> goal_types = [ GoalType . objects . create ( name = str ( i ) ) for i in range ( <NUM_LIT:3> ) ] <EOL> anonymous_visitor = AnonymousVisitor . objects . create ( ) <EOL> participant = self . create_participant ( <EOL> anonymous_visitor = anonymous_visitor , <EOL> experiment = self . experiment , <EOL> enrollment_date = self . experiment . start_date + timedelta ( days = <NUM_LIT:2> ) , <EOL> group = Participant . TEST_GROUP ) <EOL> days = [ datetime . combine ( self . experiment . start_date + timedelta ( days = i ) , time ( hour = <NUM_LIT:12> ) ) <EOL> for i in range ( <NUM_LIT:5> ) ] <EOL> nb_goal_records = GoalRecord . objects . all ( ) . count ( ) <EOL> self . create_goal_record ( days [ <NUM_LIT:0> ] , anonymous_visitor , goal_types [ <NUM_LIT:0> ] ) <EOL> self . create_goal_record ( days [ <NUM_LIT:0> ] , anonymous_visitor , goal_types [ <NUM_LIT:1> ] ) <EOL> self . create_goal_record ( days [ <NUM_LIT:1> ] , anonymous_visitor , goal_types [ <NUM_LIT:0> ] ) <EOL> self . create_goal_record ( days [ <NUM_LIT:1> ] , anonymous_visitor , goal_types [ <NUM_LIT:0> ] ) <EOL> self . create_goal_record ( days [ <NUM_LIT:2> ] , anonymous_visitor , goal_types [ <NUM_LIT:1> ] ) <EOL> self . create_goal_record ( days [ <NUM_LIT:3> ] , anonymous_visitor , goal_types [ <NUM_LIT:0> ] ) <EOL> self . create_goal_record ( days [ <NUM_LIT:4> ] , anonymous_visitor , goal_types [ <NUM_LIT:0> ] ) <EOL> self . create_goal_record ( days [ <NUM_LIT:4> ] , anonymous_visitor , goal_types [ <NUM_LIT:0> ] ) <EOL> self . assertEquals ( nb_goal_records + <NUM_LIT:8> , GoalRecord . objects . all ( ) . count ( ) ) <EOL> self . assertEquals ( calculate_participant_conversion ( participant , goal_types [ <NUM_LIT:0> ] , days [ <NUM_LIT:0> ] ) , <NUM_LIT:0> ) <EOL> self . assertEquals ( calculate_participant_conversion ( participant , goal_types [ <NUM_LIT:1> ] , days [ <NUM_LIT:0> ] ) , <NUM_LIT:0> ) <EOL> self . assertEquals ( calculate_participant_conversion ( participant , goal_types [ <NUM_LIT:2> ] , days [ <NUM_LIT:0> ] ) , <NUM_LIT:0> ) <EOL> self . assertEquals ( calculate_participant_conversion ( participant , None , days [ <NUM_LIT:0> ] ) , <NUM_LIT:0> ) <EOL> self . assertEquals ( calculate_participant_conversion ( participant , goal_types [ <NUM_LIT:0> ] , days [ <NUM_LIT:1> ] ) , <NUM_LIT:0> ) <EOL> self . assertEquals ( calculate_participant_conversion ( participant , goal_types [ <NUM_LIT:1> ] , days [ <NUM_LIT:1> ] ) , <NUM_LIT:0> ) <EOL> self . assertEquals ( calculate_participant_conversion ( participant , goal_types [ <NUM_LIT:2> ] , days [ <NUM_LIT:1> ] ) , <NUM_LIT:0> ) <EOL> self . assertEquals ( calculate_participant_conversion ( participant , None , days [ <NUM_LIT:1> ] ) , <NUM_LIT:0> ) <EOL> self . assertEquals ( calculate_participant_conversion ( participant , goal_types [ <NUM_LIT:0> ] , days [ <NUM_LIT:2> ] ) , <NUM_LIT:0> ) <EOL> self . assertEquals ( calculate_participant_conversion ( participant , goal_types [ <NUM_LIT:1> ] , days [ <NUM_LIT:2> ] ) , <NUM_LIT:1> ) <EOL> self . assertEquals ( calculate_participant_conversion ( participant , goal_types [ <NUM_LIT:2> ] , days [ <NUM_LIT:2> ] ) , <NUM_LIT:0> ) <EOL> self . assertEquals ( calculate_participant_conversion ( participant , None , days [ <NUM_LIT:2> ] ) , <NUM_LIT:1> ) <EOL> self . assertEquals ( calculate_participant_conversion ( participant , goal_types [ <NUM_LIT:0> ] , days [ <NUM_LIT:3> ] ) , <NUM_LIT:1> ) <EOL> self . assertEquals ( calculate_participant_conversion ( participant , goal_types [ <NUM_LIT:1> ] , days [ <NUM_LIT:3> ] ) , <NUM_LIT:1> ) <EOL> self . assertEquals ( calculate_participant_conversion ( participant , goal_types [ <NUM_LIT:2> ] , days [ <NUM_LIT:3> ] ) , <NUM_LIT:0> ) <EOL> self . assertEquals ( calculate_participant_conversion ( participant , None , days [ <NUM_LIT:3> ] ) , <NUM_LIT:1> ) <EOL> self . assertEquals ( calculate_participant_conversion ( participant , goal_types [ <NUM_LIT:0> ] , days [ <NUM_LIT:4> ] ) , <NUM_LIT:1> ) <EOL> self . assertEquals ( calculate_participant_conversion ( participant , goal_types [ <NUM_LIT:1> ] , days [ <NUM_LIT:4> ] ) , <NUM_LIT:1> ) <EOL> self . assertEquals ( calculate_participant_conversion ( participant , goal_types [ <NUM_LIT:2> ] , days [ <NUM_LIT:4> ] ) , <NUM_LIT:0> ) <EOL> self . assertEquals ( calculate_participant_conversion ( participant , None , days [ <NUM_LIT:4> ] ) , <NUM_LIT:1> ) <EOL> def testGoalTypeConversionCalculator ( self ) : <EOL> mocker = mox . Mox ( ) <EOL> participants = [ mocker . CreateMockAnything ( ) , <EOL> mocker . CreateMockAnything ( ) , <EOL> mocker . CreateMockAnything ( ) ] <EOL> goal_type = mocker . CreateMockAnything ( ) <EOL> report_date = mocker . CreateMockAnything ( ) <EOL> participant_conversion_calculator = mocker . CreateMockAnything ( ) <EOL> participant_conversion_calculator ( <EOL> participants [ <NUM_LIT:0> ] , goal_type , report_date ) . InAnyOrder ( ) . AndReturn ( <NUM_LIT:1> ) <EOL> participant_conversion_calculator ( <EOL> participants [ <NUM_LIT:1> ] , goal_type , report_date ) . InAnyOrder ( ) . AndReturn ( <NUM_LIT:0> ) <EOL> participant_conversion_calculator ( <EOL> participants [ <NUM_LIT:2> ] , goal_type , report_date ) . InAnyOrder ( ) . AndReturn ( <NUM_LIT:1> ) <EOL> mocker . ReplayAll ( ) <EOL> self . assertEquals ( <NUM_LIT:2> , calculate_goal_type_conversion ( <EOL> goal_type , participants , report_date , participant_conversion_calculator ) ) <EOL> mocker . VerifyAll ( ) <EOL> def testExperimentGroupParticipantFinder ( self ) : <EOL> days = [ datetime . combine ( date . today ( ) + timedelta ( days = i ) , time ( hour = <NUM_LIT:12> ) ) <EOL> for i in range ( - <NUM_LIT:7> , <NUM_LIT:0> ) ] <EOL> experiment = Experiment ( name = "<STR_LIT>" ) <EOL> experiment . save ( ) <EOL> experiment . state = Experiment . ENABLED_STATE <EOL> experiment . save ( ) <EOL> experiment . start_date = days [ <NUM_LIT:2> ] . date ( ) <EOL> experiment . save ( ) <EOL> other_experiment = Experiment ( name = "<STR_LIT>" ) <EOL> other_experiment . save ( ) <EOL> other_experiment . state = Experiment . DISABLED_STATE <EOL> other_experiment . save ( ) <EOL> other_experiment . start_date = days [ <NUM_LIT:0> ] . date ( ) <EOL> other_experiment . end_date = days [ <NUM_LIT:4> ] . date ( ) <EOL> other_experiment . save ( ) <EOL> anonymous_visitors = [ AnonymousVisitor . objects . create ( ) for i in range ( <NUM_LIT:10> ) ] <EOL> experiment_participant_groups = [ <EOL> [ <EOL> self . create_participant ( anonymous_visitor = anonymous_visitors [ <NUM_LIT:0> ] , <EOL> experiment = experiment , <EOL> enrollment_date = days [ <NUM_LIT:2> ] , <EOL> group = Participant . TEST_GROUP ) , <EOL> self . create_participant ( anonymous_visitor = anonymous_visitors [ <NUM_LIT:1> ] , <EOL> experiment = experiment , <EOL> enrollment_date = days [ <NUM_LIT:2> ] , <EOL> group = Participant . CONTROL_GROUP ) , <EOL> self . create_participant ( anonymous_visitor = anonymous_visitors [ <NUM_LIT:3> ] , <EOL> experiment = experiment , <EOL> enrollment_date = days [ <NUM_LIT:3> ] , <EOL> group = Participant . TEST_GROUP ) , <EOL> self . create_participant ( anonymous_visitor = anonymous_visitors [ <NUM_LIT:4> ] , <EOL> experiment = experiment , <EOL> enrollment_date = days [ <NUM_LIT:4> ] , <EOL> group = Participant . CONTROL_GROUP ) , <EOL> self . create_participant ( anonymous_visitor = anonymous_visitors [ <NUM_LIT:6> ] , <EOL> experiment = experiment , <EOL> enrollment_date = days [ <NUM_LIT:6> ] , <EOL> group = Participant . TEST_GROUP ) <EOL> ] , <EOL> [ <EOL> self . create_participant ( anonymous_visitor = anonymous_visitors [ <NUM_LIT:0> ] , <EOL> experiment = other_experiment , <EOL> enrollment_date = days [ <NUM_LIT:0> ] , <EOL> group = Participant . CONTROL_GROUP ) , <EOL> self . create_participant ( anonymous_visitor = anonymous_visitors [ <NUM_LIT:2> ] , <EOL> experiment = other_experiment , <EOL> enrollment_date = days [ <NUM_LIT:0> ] , <EOL> group = Participant . TEST_GROUP ) , <EOL> self . create_participant ( anonymous_visitor = anonymous_visitors [ <NUM_LIT:5> ] , <EOL> experiment = other_experiment , <EOL> enrollment_date = days [ <NUM_LIT:4> ] , <EOL> group = Participant . TEST_GROUP ) <EOL> ] <EOL> ] <EOL> ex1day2 = find_experiment_group_participants ( Participant . TEST_GROUP , experiment , days [ <NUM_LIT:2> ] ) <EOL> ex1day2visitors = [ p . anonymous_visitor for p in ex1day2 ] <EOL> self . assertTrue ( anonymous_visitors [ <NUM_LIT:0> ] in ex1day2visitors ) <EOL> self . assertEquals ( <NUM_LIT:1> , len ( ex1day2visitors ) ) <EOL> ex1day4test = find_experiment_group_participants ( Participant . TEST_GROUP , experiment , days [ <NUM_LIT:4> ] ) <EOL> ex1day4testvisitors = [ p . anonymous_visitor for p in ex1day4test ] <EOL> self . assertTrue ( anonymous_visitors [ <NUM_LIT:0> ] in ex1day4testvisitors ) <EOL> self . assertTrue ( anonymous_visitors [ <NUM_LIT:3> ] in ex1day4testvisitors ) <EOL> self . assertEquals ( <NUM_LIT:2> , len ( ex1day4testvisitors ) ) <EOL> ex1day4control = find_experiment_group_participants ( Participant . CONTROL_GROUP , experiment , days [ <NUM_LIT:4> ] ) <EOL> ex1day4controlvisitors = [ p . anonymous_visitor for p in ex1day4control ] <EOL> self . assertTrue ( anonymous_visitors [ <NUM_LIT:1> ] in ex1day4controlvisitors ) <EOL> self . assertTrue ( anonymous_visitors [ <NUM_LIT:4> ] in ex1day4controlvisitors ) <EOL> self . assertEquals ( <NUM_LIT:2> , len ( ex1day4controlvisitors ) ) <EOL> ex2day5test = find_experiment_group_participants ( Participant . TEST_GROUP , other_experiment , days [ <NUM_LIT:5> ] ) <EOL> ex2day5testvisitors = [ p . anonymous_visitor for p in ex2day5test ] <EOL> self . assertTrue ( anonymous_visitors [ <NUM_LIT:2> ] in ex2day5testvisitors ) <EOL> self . assertTrue ( anonymous_visitors [ <NUM_LIT:5> ] in ex2day5testvisitors ) <EOL> self . assertEquals ( <NUM_LIT:2> , len ( ex2day5testvisitors ) ) <EOL> def testGetConversionData ( self ) : <EOL> days = [ datetime . combine ( date . today ( ) + timedelta ( days = i ) , time ( hour = <NUM_LIT:12> ) ) <EOL> for i in range ( - <NUM_LIT:7> , <NUM_LIT:0> ) ] <EOL> yesterday = date . today ( ) - timedelta ( days = <NUM_LIT:1> ) <EOL> experiment = Experiment ( name = "<STR_LIT>" ) <EOL> experiment . save ( ) <EOL> experiment . state = Experiment . ENABLED_STATE <EOL> experiment . save ( ) <EOL> experiment . start_date = yesterday <EOL> experiment . save ( ) <EOL> goal_types = [ GoalType . objects . create ( name = "<STR_LIT:%s>" % i ) for i in range ( <NUM_LIT:4> ) ] <EOL> report = DailyConversionReport . objects . create ( experiment = experiment , <EOL> date = yesterday , <EOL> overall_test_conversion = <NUM_LIT> , <EOL> overall_control_conversion = <NUM_LIT:12> , <EOL> test_group_size = <NUM_LIT> , <EOL> control_group_size = <NUM_LIT> , <EOL> confidence = <NUM_LIT> ) <EOL> DailyConversionReportGoalData . objects . create ( report = report , <EOL> goal_type = goal_types [ <NUM_LIT:0> ] , <EOL> test_conversion = <NUM_LIT:11> , <EOL> control_conversion = <NUM_LIT:0> , <EOL> confidence = <NUM_LIT> ) <EOL> DailyConversionReportGoalData . objects . create ( report = report , <EOL> goal_type = goal_types [ <NUM_LIT:1> ] , <EOL> test_conversion = <NUM_LIT:0> , <EOL> control_conversion = <NUM_LIT> , <EOL> confidence = None ) <EOL> DailyConversionReportGoalData . objects . create ( report = report , <EOL> goal_type = goal_types [ <NUM_LIT:2> ] , <EOL> test_conversion = <NUM_LIT> , <EOL> control_conversion = <NUM_LIT> , <EOL> confidence = <NUM_LIT:100> ) <EOL> data = get_conversion_data ( experiment , yesterday ) <EOL> self . assertEquals ( data [ '<STR_LIT:date>' ] , yesterday ) <EOL> self . assertTrue ( "<STR_LIT>" in data ) <EOL> self . assertTrue ( "<STR_LIT>" in data ) <EOL> self . assertEquals ( <NUM_LIT:4> , len ( data [ "<STR_LIT>" ] . keys ( ) ) ) <EOL> for goal_type in goal_types [ <NUM_LIT:0> : <NUM_LIT:3> ] : <EOL> self . assertTrue ( goal_type . name in data [ "<STR_LIT>" ] ) <EOL> goal_type_data = data [ "<STR_LIT>" ] [ goal_type . name ] <EOL> self . assertTrue ( "<STR_LIT>" in goal_type_data ) <EOL> self . assertTrue ( "<STR_LIT>" in goal_type_data ) <EOL> self . assertTrue ( "<STR_LIT>" in goal_type_data ) <EOL> self . assertTrue ( "<STR_LIT>" in goal_type_data ) <EOL> self . assertTrue ( "<STR_LIT>" in goal_type_data ) <EOL> self . assertTrue ( "<STR_LIT>" in goal_type_data ) <EOL> self . assertEquals ( None , data [ "<STR_LIT>" ] [ goal_types [ <NUM_LIT:3> ] . name ] ) <EOL> self . assertEquals ( <NUM_LIT> , data [ "<STR_LIT>" ] ) <EOL> self . assertEquals ( <NUM_LIT> , data [ "<STR_LIT>" ] ) <EOL> totals = data [ "<STR_LIT>" ] <EOL> expected_test_rate = <NUM_LIT> / <NUM_LIT> * <NUM_LIT> <EOL> expected_control_rate = <NUM_LIT> / <NUM_LIT> * <NUM_LIT> <EOL> expected_improvement = ( expected_test_rate - expected_control_rate ) / expected_control_rate * <NUM_LIT> <EOL> self . assertAlmostEquals ( expected_test_rate , totals [ "<STR_LIT>" ] ) <EOL> self . assertAlmostEquals ( expected_control_rate , totals [ "<STR_LIT>" ] ) <EOL> self . assertAlmostEquals ( expected_improvement , totals [ "<STR_LIT>" ] ) <EOL> self . assertAlmostEquals ( <NUM_LIT> , totals [ "<STR_LIT>" ] ) <EOL> self . assertEquals ( <NUM_LIT> , totals [ "<STR_LIT>" ] ) <EOL> self . assertEquals ( <NUM_LIT:12> , totals [ "<STR_LIT>" ] ) <EOL> self . assertEquals ( <NUM_LIT:0> , data [ "<STR_LIT>" ] [ goal_types [ <NUM_LIT:0> ] . name ] [ "<STR_LIT>" ] ) <EOL> self . assertAlmostEquals ( <NUM_LIT> / <NUM_LIT> * <NUM_LIT> , data [ "<STR_LIT>" ] [ goal_types [ <NUM_LIT:0> ] . name ] [ "<STR_LIT>" ] ) <EOL> self . assertEquals ( None , data [ "<STR_LIT>" ] [ goal_types [ <NUM_LIT:0> ] . name ] [ "<STR_LIT>" ] ) <EOL> self . assertAlmostEquals ( <NUM_LIT> , data [ "<STR_LIT>" ] [ goal_types [ <NUM_LIT:0> ] . name ] [ "<STR_LIT>" ] ) <EOL> self . assertEquals ( <NUM_LIT:11> , data [ "<STR_LIT>" ] [ goal_types [ <NUM_LIT:0> ] . name ] [ "<STR_LIT>" ] ) <EOL> self . assertEquals ( <NUM_LIT:0> , data [ "<STR_LIT>" ] [ goal_types [ <NUM_LIT:0> ] . name ] [ "<STR_LIT>" ] ) <EOL> self . assertAlmostEquals ( <NUM_LIT> / <NUM_LIT> * <NUM_LIT> , data [ "<STR_LIT>" ] [ goal_types [ <NUM_LIT:1> ] . name ] [ "<STR_LIT>" ] ) <EOL> self . assertEquals ( None , data [ "<STR_LIT>" ] [ goal_types [ <NUM_LIT:1> ] . name ] [ "<STR_LIT>" ] ) <EOL> self . assertEquals ( None , data [ "<STR_LIT>" ] [ goal_types [ <NUM_LIT:1> ] . name ] [ "<STR_LIT>" ] ) <EOL> self . assertAlmostEquals ( ( <NUM_LIT> / <NUM_LIT> - <NUM_LIT> / <NUM_LIT> ) / ( <NUM_LIT> / <NUM_LIT> ) * <NUM_LIT> , <EOL> data [ "<STR_LIT>" ] [ goal_types [ <NUM_LIT:2> ] . name ] [ "<STR_LIT>" ] ) <EOL> def testConversionReportGenerator ( self ) : <EOL> days = [ datetime . combine ( date . today ( ) + timedelta ( days = i ) , time ( hour = <NUM_LIT:12> ) ) <EOL> for i in range ( - <NUM_LIT:7> , <NUM_LIT:0> ) ] <EOL> experiment = Experiment ( name = "<STR_LIT>" ) <EOL> experiment . save ( ) <EOL> experiment . state = Experiment . ENABLED_STATE <EOL> experiment . save ( ) <EOL> experiment . start_date = days [ <NUM_LIT:2> ] . date ( ) <EOL> experiment . save ( ) <EOL> other_experiment = Experiment ( name = "<STR_LIT>" ) <EOL> other_experiment . save ( ) <EOL> other_experiment . state = Experiment . DISABLED_STATE <EOL> other_experiment . save ( ) <EOL> other_experiment . start_date = days [ <NUM_LIT:0> ] . date ( ) <EOL> other_experiment . end_date = days [ <NUM_LIT:4> ] . date ( ) <EOL> other_experiment . save ( ) <EOL> goal_types = [ GoalType . objects . create ( name = "<STR_LIT:%s>" % i ) for i in range ( <NUM_LIT:3> ) ] <EOL> mocker = mox . Mox ( ) <EOL> finder = mocker . CreateMockAnything ( ) <EOL> calculator = mocker . CreateMockAnything ( ) <EOL> default_data = { <EOL> Participant . TEST_GROUP : { <EOL> "<STR_LIT:count>" : <NUM_LIT> , <EOL> "<STR_LIT>" : [ <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT:9> ] <EOL> } , <EOL> Participant . CONTROL_GROUP : { <EOL> "<STR_LIT:count>" : <NUM_LIT> , <EOL> "<STR_LIT>" : [ <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT:5> ] <EOL> } <EOL> } <EOL> day_2_data = { <EOL> Participant . TEST_GROUP : { <EOL> "<STR_LIT:count>" : <NUM_LIT:12> , <EOL> "<STR_LIT>" : [ <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> } , <EOL> Participant . CONTROL_GROUP : { <EOL> "<STR_LIT:count>" : <NUM_LIT:7> , <EOL> "<STR_LIT>" : [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:3> ] <EOL> } <EOL> } <EOL> day_3_data = { <EOL> Participant . TEST_GROUP : { <EOL> "<STR_LIT:count>" : <NUM_LIT:5> , <EOL> "<STR_LIT>" : [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:3> ] <EOL> } , <EOL> Participant . CONTROL_GROUP : { <EOL> "<STR_LIT:count>" : <NUM_LIT:12> , <EOL> "<STR_LIT>" : [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> } <EOL> } <EOL> day_4_data = { <EOL> Participant . TEST_GROUP : { <EOL> "<STR_LIT:count>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> } , <EOL> Participant . CONTROL_GROUP : { <EOL> "<STR_LIT:count>" : <NUM_LIT> , <EOL> "<STR_LIT>" : [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:7> ] <EOL> } <EOL> } <EOL> for day in days [ <NUM_LIT:2> : <NUM_LIT:7> ] : <EOL> data = default_data <EOL> if day == days [ <NUM_LIT:2> ] : <EOL> data = day_2_data <EOL> if day == days [ <NUM_LIT:3> ] : <EOL> data = day_3_data <EOL> if day == days [ <NUM_LIT:4> ] : <EOL> data = day_4_data <EOL> for group in ( Participant . TEST_GROUP , Participant . CONTROL_GROUP ) : <EOL> mock_participants = mocker . CreateMockAnything ( ) <EOL> finder ( group , experiment , day . date ( ) ) . InAnyOrder ( ) . AndReturn ( mock_participants ) <EOL> mock_participants . count ( ) . MultipleTimes ( ) . AndReturn ( data [ group ] [ "<STR_LIT:count>" ] ) <EOL> for goal_type in goal_types : <EOL> calculator ( goal_type , mock_participants , day . date ( ) ) . InAnyOrder ( ) . AndReturn ( data [ group ] [ "<STR_LIT>" ] [ int ( goal_type . name ) ] ) <EOL> calculator ( None , mock_participants , day . date ( ) ) . InAnyOrder ( ) . AndReturn ( sum ( data [ group ] [ "<STR_LIT>" ] ) ) <EOL> mocker . ReplayAll ( ) <EOL> for d in days [ <NUM_LIT:2> : <NUM_LIT:7> ] : <EOL> ConversionReportGenerator ( calculator , finder ) . generate_daily_report_for_experiment ( <EOL> experiment , d . date ( ) ) <EOL> results = DailyConversionReport . objects . filter ( <EOL> experiment = experiment ) . order_by ( '<STR_LIT>' ) <EOL> mocker . VerifyAll ( ) <EOL> self . assertEquals ( results . count ( ) , <NUM_LIT:5> ) <EOL> report_days = [ d . date ( ) for d in days [ <NUM_LIT:2> : <NUM_LIT:7> ] ] <EOL> for i in range ( <NUM_LIT:5> ) : <EOL> self . assertEquals ( results [ i ] . date , report_days [ <NUM_LIT:4> - i ] ) <EOL> self . assertEquals ( <NUM_LIT:12> , results [ <NUM_LIT:4> ] . test_group_size ) <EOL> self . assertEquals ( <NUM_LIT:7> , results [ <NUM_LIT:4> ] . control_group_size ) <EOL> self . assertEquals ( <NUM_LIT:5> , results [ <NUM_LIT:4> ] . overall_test_conversion ) <EOL> self . assertEquals ( <NUM_LIT:4> , results [ <NUM_LIT:4> ] . overall_control_conversion ) <EOL> day_2_goal_4_test_conversion = DailyConversionReportGoalData . objects . filter ( <EOL> report = results [ <NUM_LIT:4> ] , <EOL> goal_type = goal_types [ <NUM_LIT:0> ] ) [ <NUM_LIT:0> ] . test_conversion <EOL> self . assertEquals ( <NUM_LIT:0> , day_2_goal_4_test_conversion ) <EOL> day_2_goal_2_control_conversion = DailyConversionReportGoalData . objects . filter ( <EOL> report = results [ <NUM_LIT:4> ] , <EOL> goal_type = goal_types [ <NUM_LIT:2> ] ) [ <NUM_LIT:0> ] . control_conversion <EOL> self . assertEquals ( <NUM_LIT:3> , day_2_goal_2_control_conversion ) <EOL> self . assertEquals ( <NUM_LIT:5> , results [ <NUM_LIT:3> ] . test_group_size ) <EOL> self . assertEquals ( <NUM_LIT:0> , results [ <NUM_LIT:2> ] . test_group_size ) <EOL> self . assertEquals ( None , results [ <NUM_LIT:2> ] . confidence ) <EOL> day_4_goal_1_confidence = DailyConversionReportGoalData . objects . filter ( <EOL> report = results [ <NUM_LIT:2> ] , <EOL> goal_type = goal_types [ <NUM_LIT:0> ] ) [ <NUM_LIT:0> ] . confidence <EOL> self . assertEquals ( None , day_4_goal_1_confidence ) <EOL> day_5_goal_0_confidence = DailyConversionReportGoalData . objects . filter ( <EOL> report = results [ <NUM_LIT:1> ] , <EOL> goal_type = goal_types [ <NUM_LIT:0> ] ) [ <NUM_LIT:0> ] . confidence <EOL> self . assertAlmostEqual ( <NUM_LIT> , day_5_goal_0_confidence , places = <NUM_LIT:6> ) </s>
