// // StatisVC.m // jiaPei // // Created by apple on 15/11/20. // Copyright (c) 2015年 JCZ. All rights reserved. // #import "StatisVC.h" #import "PieView.h" #import "Grade.h" @interface StatisVC () { NSInteger cntUndo; NSInteger cntFault; NSInteger cntCorrect; NSInteger cntAll; PieView* pieV; UILabel* lbl00,*lbl01,*lbl10,*lbl11,*lbl20,*lbl21; NSArray* colors; } @end @implementation StatisVC - (void)viewDidLoad { [super viewDidLoad]; [self myInit]; [self getStatis]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - -(void)myInit { [self configNavigationBar]; [self setTitle:@"练习统计"]; [self.view setBackgroundColor:backGroundColor]; colors = @[contentTextColor,[UIColor orangeColor],defGreen]; UIView *vi; CGFloat bd = 0; CGFloat pieH = 320* .5; vi = [[UIView alloc] initWithFrame:SGRectMake(0, 0, 320, pieH + bd*2)]; [vi setBackgroundColor:backGroundColor]; [self.view addSubview:vi]; pieV = [[PieView alloc] init]; [pieV setBounds:SGRectMake(0, 0, pieH, pieH)]; [pieV setCenter:vi.center]; [pieV setDatasource:self]; [self.view addSubview:pieV]; UILabel* label; CGFloat currentTop; CGFloat lblH; currentTop = pieH + bd*2; bd = 5; lblH = 25; label = [[UILabel alloc] initWithFrame:SGRectMake(bd, currentTop, 320 - bd*2, lblH)]; [label setText:@"练习统计"]; [label setTextAlignment:NSTextAlignmentCenter]; [self.view addSubview:label]; [label setBackgroundColor:[UIColor whiteColor]]; currentTop += lblH ; vi = [[UIView alloc] initWithFrame:SGRectMake(bd, currentTop+1, 320-bd*2, lblH*3)]; [vi setBackgroundColor:[UIColor whiteColor]]; [self.view addSubview:vi]; CGFloat lblw; lblw = (320-bd*4)/3; NSArray* titles = @[@"未做题",@"1126",@"91%", @"答错题",@"64",@"5%", @"答对题",@"39",@"3%"]; for (int i = 0; i< 9; i++) { label = [[UILabel alloc] initWithFrame:SGRectMake(bd + lblw*(i%3), lblH*(i/3), lblw, lblH)]; [label setText:titles[i]]; [vi addSubview:label]; int x = i%3; int y = i/3; [label setTextColor:colors[y]]; if ( 1 == x ) { [label setTextAlignment:NSTextAlignmentCenter]; } if ( 2 == x) { [label setTextAlignment:NSTextAlignmentRight]; } switch (i) { case 1: lbl00 = label; break; case 2: lbl01 = label; break; case 4: lbl10 = label; break; case 5: lbl11 = label; break; case 7: lbl20 = label; break; case 8: lbl21 = label; break; default: break; } } } -(void)getStatis { // sqlite3 *database; // sqlite3_open([dataBasePath2 UTF8String], &database); // // sqlite3_stmt *statement; //获取数据库的表的名字 // const char *getTableInfo = "select * from sqlite_master where type='table' order by name"; // sqlite3_prepare_v2(database, getTableInfo, -1, &statement, nil); // while (sqlite3_step(statement) == SQLITE_ROW) { // char *nameData = (char *)sqlite3_column_text(statement, 1); // NSString *tableName = [[NSString alloc] initWithUTF8String:nameData]; // NSLog(@"name:%@",tableName); // } // NSString *columnName = @""; // //获取某表中字段的名字 // const char *getColumn = "PRAGMA table_info(question)"; // sqlite3_prepare_v2(database, getColumn, -1, &statement, nil); // while (sqlite3_step(statement) == SQLITE_ROW) { // char *nameData = (char *)sqlite3_column_text(statement, 1); // columnName = [[NSString alloc] initWithUTF8String:nameData]; // NSLog(@"columnName:%@",columnName); // } // // sqlite3_finalize(statement); NSString *sql1 = [NSString stringWithFormat:@"subject = %@",myDelegate.subject]; if ([defUser.car_type isEqualToString:@"1"] || [defUser.car_type isEqualToString:@"2"] || [defUser.car_type isEqualToString:@"3"] || [defUser.car_type isEqualToString:@"4"] || [defUser.car_type isEqualToString:@"5"] || [defUser.car_type isEqualToString:@"6"]) { sql1 = @"nil"; } cntFault = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Wrong].count : ([defUser.car_type isEqualToString:@"2"]? [DB_Que_Helper queryGZPZ_EXAM_CYRYMarkQuestionWithMarkType:@"1"] : [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Wrong].count); cntAll = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Sequential].count : ([defUser.car_type isEqualToString:@"2"]? [DB_Que_Helper countForQuery:sql1] : [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Sequential].count); int done = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? (int)[DB_Que_Helper queryMarkQuestionWithMarkType:@"4"] : ([defUser.car_type isEqualToString:@"2"]? (int)[DB_Que_Helper queryGZPZ_EXAM_CYRYMarkQuestionWithMarkType:@"4"] : (int)[DB_Que_Helper queryMarkQuestionWithMarkType:@"4"]); cntUndo = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_UnDo].count : ([defUser.car_type isEqualToString:@"2"]? cntAll - done : [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_UnDo].count); cntCorrect = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? (cntAll - cntFault - cntUndo) : ([defUser.car_type isEqualToString:@"2"]? done - cntFault : cntAll - cntFault - cntUndo); //NSLog(@"cntFault----->%d,cntCorrect----->%d,cntUndo------>%d,cntAll------>%d",(int)cntFault,(int)cntCorrect,(int)cntUndo,(int)cntAll); [pieV reloadData]; [lbl00 setText:[NSString stringWithFormat:@"%d",(int)cntUndo]]; [lbl01 setText:[NSString stringWithFormat:@"%.2f%%",!((cntUndo*100.0/cntAll) < 0)? cntUndo*100.0/cntAll : 0.00]]; [lbl10 setText:[NSString stringWithFormat:@"%d",(int)cntFault]]; [lbl11 setText:[NSString stringWithFormat:@"%.2f%%",cntFault*100.0/cntAll]]; [lbl20 setText:[NSString stringWithFormat:@"%d",(int)cntCorrect]]; [lbl21 setText:[NSString stringWithFormat:@"%.2f%%",cntCorrect*100.0/cntAll]]; } #pragma mark - - (int)numberOfSlicesInPieChartView:(PieView *)pieChartView { return 3; } /** 返回某个index的饼片的比例。0-100 */ - (double)pieChartView:(PieView *)pieChartView valueForSliceAtIndex:(NSUInteger)index { NSInteger cnt; switch (index) { case 0: cnt = cntUndo ; break; case 1: cnt = cntFault; break; case 2: cnt = cntCorrect; break; default: cnt = 1; break; } return cnt*100.0 / cntAll; } /**返回某个index饼片的颜色 */ - (UIColor *)pieChartView:(PieView *)pieChartView colorForSliceAtIndex:(NSUInteger)index { return colors[index]; } @end